SOAP over JMS

In this recipe, we will implement reliable SOAP communication over JMS and not over HTTP. The only difference is that your request and response will be published on a queue. This way the request can't be lost (when it has JMS persistence with XA/QoS). The response will also be published on the queue and the client can consume this response.

Getting ready

For this recipe, we will use an OSB project with a proxy service that is based on a WSDL with a synchronous request/response operation. The SOAP message will be sent over JMS instead of HTTP. JDeveloper will be used to generate a test client:

Getting ready

You can import the OSB project into Eclipse OEPE from chapter-10getting-readysending-soap-over-jms.

How to do it...

First we will need to change the proxy service to use the JMS instead of the HTTP transport. In Eclipse OEPE, perform the following steps:

  1. Open the SoapOverJMS proxy service.
  2. Click on the Transport tab.
  3. Choose jms in the Protocol field.
  4. The Endpoint URI must use a XA Connection Factory. The URI must look like this jms://[OSBServer]:[Port]/weblogic.jms.XAConnectionFactory/SourceQueue
  5. Navigate to the JMS Transport tab.
  6. Enable Is Response Required.
  7. Select JMSMessageID in the Response Pattern field.
  8. Select Text in the Response Message Type field.
  9. Click on the Message Flow tab.
  10. Add a Transport Header action after the Replace action:
    How to do it...
  11. On the Properties of the Transport Header, choose Inbound Response from the Direction drop-down listbox.
  12. Click on Add Header.
  13. Select the Other option and enter _wls_mimehdrContent_Type into the field.
  14. Select the Set Header option to and click on Expression.
  15. Enter text/xml; charset=utf-8 into the Expression field and click on OK.
  16. Deploy the project to the OSB Server.

    Now let's test the service by implementing a simple Java client in JDeveloper. First we need to retrieve the WSDL of the OSB proxy service from the OSB server. In the Service Bus console, perform the following steps for saving the WSDL into a file:

  17. In the Project Explorer, select the sending-soap-over-jms project.
  18. Click on the proxy folder on the right.
  19. Navigate to the SoapOverJMS proxy service and click on the Export WSDL icon (the third icon in the Actions cell).
  20. Click on Save.
  21. Save the SoapOverJMS_wsdl.jar to a temporary folder.

    In JDeveloper, perform the following steps:

  22. Create a new application by selecting File | New.
  23. Enter Generic into the search field, select Generic Application, and click on OK.
  24. Enter SoapOverJms into the Application Name field and click on Next.
  25. Enter SoapOverJMSClient into the Project Name field and click on Finish.
  26. Right-click on the SoapOverJMSClient in the project navigator and select New.
  27. Enter ant in the search field, select Empty Buildfile (Ant), and click on OK.
  28. Leave build.xml as the file name and click on OK.
  29. Open the build.xml and enter the following Ant script:
    <project default="clientOSB">
    
      <path id="weblogic">
        <pathelement path="C:/oracle/MiddlewareJdev11gR1PS4/wlserver_10.3/server/lib/weblogic.jar" />
      </path>
    
     <taskdef name="clientgen" classname="weblogic.wsee.tools.anttasks.ClientGenTask"
              classpathref="weblogic"/>
    
     <target name="clientOSB">
      <clientgen wsdl="file:Helloworld.wsdl"
                 destdir="src" 
                 packagename="osb.book.soap.jms"
                 type="JAXRPC"/>
      <javac srcdir="src" 
             destdir="classes"
             includes="osb.book.soap.jms/**/*.java"/>
     </target>
    </project>
  30. Change the path to the weblogic.jar so it matches with your environment.
  31. Open the SoapOverJMS_wsdl.jar file that we just created and extract the Helloworld.wsdl and Helloworld.xsd into the project folder.
  32. Right-click on the build.xml and select Run Ant Target | clientOSB.
  33. JDeveloper creates the Web Service proxy client code. Confirm that this was successful by checking the Ant Log tab for the BUILD SUCCESSFUL message.
  34. Right-click on the SoapOverJMSClient project and select Project Properties.
  35. In the tree on the left, navigate to Libraries and Classpath and click on Add Library.
  36. In the pop-up window select the WebLogic 10.3 Remote-Client library and click on OK.
  37. Close the Project Properties window by clicking on OK.
  38. Right-click on the SoapOverJMSClient project and select New.
  39. Enter java class into the search field, select Java Class, and click on OK.
  40. Enter TestService into the Name field, enable the Main Method checkbox, and click on OK.
  41. Add the following import statements to the TestService Java class:
    import java.net.URISyntaxException;
    import java.rmi.RemoteException;
    
    import javax.xml.rpc.ServiceException;
    import javax.xml.rpc.Stub;
    
    import osb.book.soap.jms.HelloWorldService;
    import osb.book.soap.jms.HelloWorldServiceSoapHttpPortBindingQSService;
    import osb.book.soap.jms.HelloWorldServiceSoapHttpPortBindingQSService_Impl;
    
    import weblogic.wsee.connection.transport.jms.JmsTransportInfo;

    Replace the main method by the following code:

    public static void main(String[] args) throws ServiceException,
                                                  URISyntaxException,
                                                  RemoteException {
      
        HelloWorldServiceSoapHttpPortBindingQSService service = 
            new HelloWorldServiceSoapHttpPortBindingQSService_Impl();
        HelloWorldService port = 
            service.getHelloWorldServiceSoapHttpPortBindingQSPort();
    
        Stub stub = (Stub)port;  
        String uri = "jms://[OSBServer]:[Port]?URI=SourceQueue";    
        JmsTransportInfo ti =  new JmsTransportInfo(uri);    
        stub._setProperty("weblogic.wsee.connection.transportinfo", ti);    
             
        try {
            String result = null;
            System.out.println("start");
            result = port.sayHello();
            System.out.println("Got JMS result: " + result);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
  42. Replace [OSBServer] and [Port] with the settings of the OSB server installation.

    Now let's test the Java class.

  43. Right-click on the TestService.java class and select Run:
    How to do it...
  44. The log window will show the result of the call as shown in the following screenshot:
    How to do it...

How it works...

SOAP over JMS works in the same manner as HTTP, but JMS will be more reliable. The JAX-RPC client in JDeveloper generates a request and puts it in a WebLogic queue. The proxy service consumes the request from the queue and executes the normal message flow. The proxy service publishes the response that is also on the queue and uses the value of the JMSMessagId property of the request as the JMSCorrelationId. The client listens on the queue for the response message with this JMSCorrelationId.

SOAP over JMS has the following disadvantages:

  • The WSDL is only accessible in the Oracle Service Bus console
  • On the client, you need to change the endpoint
  • Only the JAX-RPC framework supports JMS. JAX-WS only supports HTTP
  • On the server, we need to change the transport of the proxy service to JMS and enable correlation
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset