Uploaded image for project: 'JBoss Web Services'
  1. JBoss Web Services
  2. JBWS-1324

JMS Endpoint - Message delivery starts before endpoint is ready.

XMLWordPrintable

    • Workaround Exists
    • Hide

      Add the following code to your endpoint implementation to sleep while waiting for the service endpoint to be ready to process the message: -

      @Override
      protected SOAPMessage processSOAPMessage(String fromName, InputStream reqMessage) throws SOAPException, IOException,
      RemoteException
      {

      ServiceEndpointManagerFactory factory = ServiceEndpointManagerFactory.getInstance();
      ServiceEndpointManager epManager = factory.getServiceEndpointManager();
      ObjectName sepID = getServiceEndpointForDestination(epManager, fromName);
      ServiceEndpoint sep = epManager.getServiceEndpointByID(sepID);

      long startTime = System.currentTimeMillis();
      State state = sep.getState();

      log.info("State=" + state);
      while (state != State.STARTED && (System.currentTimeMillis() - startTime < 60000))
      {
      try

      { Thread.sleep(1000); state = sep.getState(); log.info("State=" + state); }

      catch (InterruptedException e)

      { throw new EJBException(e); }

      }

      return super.processSOAPMessage(fromName, reqMessage);
      }

      private ObjectName getServiceEndpointForDestination(ServiceEndpointManager epManager, String fromName)
      {
      ObjectName sepID = null;
      for (ObjectName aux : epManager.getServiceEndpoints())
      {
      String jmsProp = aux.getKeyProperty("jms");
      if (jmsProp != null && jmsProp.equals(fromName))

      { sepID = aux; break; }

      }
      return sepID;
      }

      Show
      Add the following code to your endpoint implementation to sleep while waiting for the service endpoint to be ready to process the message: - @Override protected SOAPMessage processSOAPMessage(String fromName, InputStream reqMessage) throws SOAPException, IOException, RemoteException { ServiceEndpointManagerFactory factory = ServiceEndpointManagerFactory.getInstance(); ServiceEndpointManager epManager = factory.getServiceEndpointManager(); ObjectName sepID = getServiceEndpointForDestination(epManager, fromName); ServiceEndpoint sep = epManager.getServiceEndpointByID(sepID); long startTime = System.currentTimeMillis(); State state = sep.getState(); log.info("State=" + state); while (state != State.STARTED && (System.currentTimeMillis() - startTime < 60000)) { try { Thread.sleep(1000); state = sep.getState(); log.info("State=" + state); } catch (InterruptedException e) { throw new EJBException(e); } } return super.processSOAPMessage(fromName, reqMessage); } private ObjectName getServiceEndpointForDestination(ServiceEndpointManager epManager, String fromName) { ObjectName sepID = null; for (ObjectName aux : epManager.getServiceEndpoints()) { String jmsProp = aux.getKeyProperty("jms"); if (jmsProp != null && jmsProp.equals(fromName)) { sepID = aux; break; } } return sepID; }

      For most endpoints we need the EJB to be initialised before we initialise the web service, this way we know the session bean will be ready to process requests before the first request from a client is received.

      For message driven beans we need the web service to be initialised before the first message is processed by the MDB, however the same logic is used as is used for session beans so it is possible that the first message will be received while the web service is still being initialised.

      12:53:51,277 ERROR [SOAPFaultHelperJAXRPC] SOAP request exception
      javax.xml.rpc.soap.SOAPFaultException: Endpoint cannot handle requests in state: CREATED
      at org.jboss.ws.core.server.ServiceEndpoint.processRequest(ServiceEndpoint.java:176)
      at org.jboss.ws.integration.jboss42.jms.JMSMessageDispatcher.dipatchMessage(JMSMessageDispatcher.java:94)
      at org.jboss.ws.integration.jboss42.jms.JMSTransportSupport.processSOAPMessage(JMSTransportSupport.java:139)
      at org.jboss.ws.integration.jboss42.jms.JMSTransportSupport.onMessage(JMSTransportSupport.java:101)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.jboss.invocation.Invocation.performCall(Invocation.java:359)
      at org.jboss.ejb.MessageDrivenContainer$ContainerInterceptor.invoke(MessageDrivenContainer.java:495)

              rhn-support-asoldano Alessio Soldano
              darran.lofthouse@redhat.com Darran Lofthouse
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: