3 Replies Latest reply on Oct 19, 2007 9:29 AM by jtestori

    web service and asynchronous processing

    vitor_b

      Hello

      I really need your help, so please read my question and post your reply if you know the answer, so ...

      Webservices generally have one or more business methods exposed for clients.
      for example:

      public ResponseObject businessMethod(RequestObject request)



      A client sends a request, this request is transformed to an object, this object is passed as a parameter to our business method. The method do some work, then returns ResponseObject, application server sends the response to the client. The client waits for the answer. So this is synchronous communication.
      WebServices use SOAP. Application server knows where has to send the reply.


      But lets suppose that in some cases i would like to do some business logic later, not just when a request is received. I have been thinking of it and
      i would like you to help me.

      So I could expose another method, like:

      public ConfirmationObject asyncBusinessMethod(RequestObject request)


      This method would put RequestObject in JMS queue and then send reply. This reply
      means that request is accepted, and will be processing later. Client can continue its work.
      The Queue will hold all async requests.


      Requests will be taken from the queue later, one after the other.
      There will be for example a session bean (not MDB becouse i don't want it to take objects when they are available, just later), this bean will take a request from queue and then call first described method: businessMethod(...) . This method will create a reply, but now there is a big problem.
      Where it should be send? We have no info about client which has sent this message to our application.
      How to handle this? Generally client will have a end point, waiting for async response.
      It will use SOAP. How to send the async response using SOAP to client?
      Or should I do it in completely different way? The goal is asynchronous handling of requests.

      If there was only one client i could create and send SOAP message like that:

      ResponseObject response = ...
      //add the response object to SOAP message
      //then
      SOAPConnection connection = ...
      java.net.URL endpoint = new URL ("http://www.one.known.client");
      SOAPMessage response = connection.call(response, endpoint);
      //endpoint - client end point waiting for async reply, hardcoded or in app config


      Could that be done from a session bean?

      If there were many clients we wouldn't know to which client we should send the reply.
      Once again how to handle that?

      Please help me, I'm a beginner and this is not easy for me at all.
      Thank you in advance.

      vitor_b


        • 1. Re: web service and asynchronous processing
          heiko.braun

          Take a look at our ws-addressing implementation:
          http://jbws.dyndns.org/mediawiki/index.php/JAX-WS_User_Guide#WS-Addressing

          EndpointReferences (EPR) are used for use cases like this.
          Basically the client passes an EPR with the request, which then can be used to send the reply later on.

          • 2. Re: web service and asynchronous processing
            vitor_b

            Hello

            Thank you for your reply, but unfortunately there are some things i don't understand. Could you clarify these for me please?

            We have Message Addressing Properties:

            <wsa:To>xs:anyURI</wsa:To> ?
            <wsa:From>wsa:EndpointReferenceType</wsa:From> ?
            <wsa:ReplyTo>wsa:EndpointReferenceType</wsa:ReplyTo> ?
            <wsa:FaultTo>wsa:EndpointReferenceType</wsa:FaultTo> ?
            <wsa:Action>xs:anyURI</wsa:Action>
            <wsa:MessageID>xs:anyURI</wsa:MessageID> ?
            <wsa:RelatesTo RelationshipType="xs:anyURI"?>xs:anyURI</wsa:RelatesTo> *
            <wsa:ReferenceParameters>xs:any*</wsa:ReferenceParameters> ?


            where EndpointReferenceType means:

            <wsa:EndpointReference>
             <wsa:Address>xs:anyURI</wsa:Address>
             <wsa:ReferenceParameters>xs:any*</wsa:ReferenceParameters> ?
             <wsa:Metadata>xs:any*</wsa:Metadata>?
            </wsa:EndpointReference>


            That is ok, but there is on the page
            http://jbws.dyndns.org/mediawiki/index.php/JAX-WS_User_Guide#WS-Addressing
            something like this:

            <handler-chains xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee javaee_web_services_1_2.xsd">
            
             <handler-chain>
             <protocol-bindings>##SOAP11_HTTP</protocol-bindings>
             <handler>
             <handler-name>Application Server Handler</handler-name>
             <handler-class>org.jboss.test.ws.jaxws.samples.wsaddressing.ServerHandler</handler-class>
             </handler>
             </handler-chain>
            
            </handler-chains>


            At this point i have some questions:

            1. in which file should i put handler-chains element?

            2. What does element handler-class contain? What is this class? Does this class is able to read SOAPMessage? I think i should i think write this class myself, but what is the contract for writing this class? What interface should it implement? SOAPHandler? Do i have to implement logic which will take info from soap message header?

            3. I think these properties are handled automatically, this means webservice will send reply to adderss taken from element: wsa:ReplyTo, and i don't need to do anything in order to get this done. Am i right?

            4. If 3 is true, that means that message addressing properties don't support property i need. Client should have entry point which will accept soap message sent by server after message from queue is processed. But this entry point will not be any identified by message addressing properties received in request

            .................request......................................RequestObject
            Client -------------------------> WebService ---------------
            Client <------------------------- WebService ..................|
            ............ConfirmationObject........................................v
            ............................................................................Queue
            ...................................................................................|
            ...................SOAPMessage.........................................|
            Client (EP) <------------------- SessionBean <-----------
            Client (EP) --------------------> SessionBean

            . (dot) - only used as a spaces, to format this message

            EP - this should be a client entry point, where all results after processing objects from queue will be sent. There won't be address of this EP in the request.

            Any help will be appreciated.
            cheers

            vitor_b





            • 3. Re: web service and asynchronous processing
              jtestori

              dear vitor_b,
              did you manage to do asynchronous calls as you described here? i would be very interested in how it works.

              or can anyone else help me? i don't want a stateful shopping card, but a webservice that calls back to the client after processing the request, because in my case this can be some days later.