Time for action – Incorporating the Wise SOAP Client

Let us modify our sample to use the Wise SOAPClient now. Follow these steps:

  1. In JBoss Developer Studio, open the esbcontent/META-INF/jboss-esb.xml file in Source mode.
  2. Replace the following code:
    <action name="soapui-client-action"
            class="org.jboss.soa.esb.actions.soap.SOAPClient">
      <property name="wsdl" value="http://localhost:8080/Chapter8/ebws/Chapter8Sample/Chapter8Service?wsdl"/>
      <property name="SOAPAction" value="Chapter8ServiceOp"/>
    </action>

    With the followingcode:

    <action class="org.jboss.soa.esb.actions.soap.wise.SOAPClient"
            name="soap-wise-client-action">
      <property name="wsdl"
                value="http://localhost:8080/BookService?wsdl"/>
      <property name="SOAPAction" value="getBooks"/>
      <property name="EndPointName" value="BookServicePort"/>
    </action>
  3. Click the Save button, and the modified application should now be deployed in the server.
  4. Select the src folder, expand it till the SendEsbMessage.java file is displayed in the tree. Now click Run | Run As | Java Application.

    The server Console will display the output as below:

    INFO  [STDOUT] (pool-41-thread-1) Request map is: {getAuthors=null}
    INFO  [STDOUT] (pool-41-thread-1) parsing WSDL...
    INFO  [STDOUT] (pool-41-thread-1) generating code...
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedBookService.java
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedBookServiceService.java
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedGetAuthors.java
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedGetAuthorsResponse.java
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedGetBooks.java
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedGetBooksResponse.java
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedObjectFactory.java
    INFO  [STDOUT] (pool-41-thread-1) orgjbosssoaesbsamplesquickstartwebservice_consumer_wisegeneratedpackage-info.java
    

    The test Console will display the output as shown:

    {result=[Great Expectations, Hound Of The Baskervilles, The Da Vinci Code, The Immortals Of Meluha]}
    

What just happened?

We used the Wise SOAPClient to invoke a web service. Note that we are using WSDL from a different service than the soapUI example and that the processing of the WSDL results in the automatic generation of the appropriate Java client proxy classes. This stub generation will only happen once with all subsequent requests using the cached WSDL and the pre-compiled Java classes. This "on the fly" compilation is the reason that the tools.jar file was added at the beginning of the chapter to your JRE library list.

Have a go hero – Wise properties

Take a look at the wise-core.properties file in the esbcontent directory of the Chapter8 project, you will find a wise.tmpDir property which specifies the location of the temporary files generated by Wise. By default this will be /tmp on Mac and Linux and <ESB server drive>:/tmp on Windows.

Now take a look at the Wise generated files. Modify the SOAPAction and see if you can invoke the getAuthors method.

Request and response processing

The request parameters for the Wise SOAPClient are configured as a map in the payload of the incoming ESB message. The contents of this map can take one of two forms:

  • A map of parameters where the key of each entry is the name of the SOAP parameter as declared within the WSDL
  • A general map of parameters that can be transformed into the map required by the specific operation through a Smooks transformation. The Smooks transformation will be responsible for translating the incoming Map into the correct model required by the invocation of the SOAP operation.

The response will be stored in a map which will contain all the parameters that are returned as part of the SOAP invocation, the key for each entry being the name of the SOAP parameter as it is declared in the WSDL. This will include the result of the operation as well as the values associated with any in/out or out parameters defined in the WSDL for the operation. This map will be stored in the ESB message payload as a result of this action.

As with the request parameters, it is also possible to transform the response into a different Java model using a Smooks transformation. The map containing the transformed objects will, in that case, be stored in the ESB message payload instead of the original result of the SOAP invocation.

Transformations on the request and response objects are declared within the configuration by specifying the SmooksRequestMapper and SmooksResponseMapper action properties respectively. These properties will each reference a Smooks configuration which will be used to transform one Java model into another. Here is a sample from the quickstarts:

<action name="soap-wise-client-action"
        class="org.jboss.soa.esb.actions.soap.wise.SOAPClient">
  <property name="wsdl" value="http://127.0.0.1:8080/Quickstart_webservice_consumer_wise2/PingWS?wsdl" />
  <property name="SOAPAction" value="pingComplexObject"/>
  <property name="EndPointName" value="PingWSPort"/>
  <property name="SmooksRequestMapper"value="smooks-request-config.xml"/>
  <property name="SmooksResponseMapper"value="smooks-response-config.xml"/>
  <property name="LoggingMessages" value="false" />
  <property name="serviceName" value="PingWS"/>
</action>

As with the soapUI SOAPClient it is possible to further transform the SOAP request to add custom SOAP headers or to further manipulate the SOAP body before the invocation of the web service. Here is another sample from the quickstarts:

<action name="soapui-client-action"
        class="org.jboss.soa.esb.actions.soap.wise.SOAPClient">
  <property name="wsdl" value="http://127.0.0.1:8080/Quickstart_webservice_consumer_wise3/HelloWorldWS?wsdl" />
  <property name="SOAPAction" value="sayHello"/>
  <property name="EndPointName" value="HelloWorldPort"/>
  <property name="LoggingMessages" value="true" />
  <property name="smooks-handler-config"value="smooks-handler.xml"></property>
    <property name="serviceName" value="HelloWorldWS"/>
</action>

Have a go hero – Smooks configurations

Take a look at the quickstarts webservice_consumer_wise, webservice_consumer_wise2, webservice_consumer_wise3, and webservice_consumer_wise4. Familiarize yourself with the approach these quickstarts apply.

Custom handlers

The Wise SOAPClient also supports the configuration of JAX-WS handlers, both LogicalHandler and SOAPHandler, which can enable additional processing of the incoming and outgoing messages. A sample configuration will look like this:

<action class="org.jboss.soa.esb.actions.soap.wise.SOAPClient"
        name="soap-wise-client-action">
  <property name="wsdl"
            value="http://localhost:8080/BookService?wsdl"/>
  <property name="SOAPAction" value="getBooks"/>
  <property name="EndPointName" value="BookServicePort"/>
  <property name="custom-handlers"
         value="org.jboss.soa.esb.samples.chapter8.MyLogHandler"/>
</action>

A simple implementation of this type of handler is shown:

package org.jboss.soa.esb.samples.chapter8;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;

public class MyLogHandler implements SOAPHandler<SOAPMessageContext> {
    private static Set<QName> headers;

    static {
        HashSet<QName> set = new HashSet<QName>();
        headers = Collections.unmodifiableSet(set);
    }

    public Set<QName> getHeaders() {
        return headers;
    }

    public void close(MessageContext messageContext) {
    }

    public boolean handleFault(SOAPMessageContext smc) {
        return true;
    }

    public boolean handleMessage(SOAPMessageContext msgContext) {
        System.out.println(msgContext.getMessage());
        return true;
    }

}

Have a go hero – using a custom handler

Go ahead and add the previous code to the src folder and configure the Wise SOAPClient to use this custom handler. Do you see the SOAP message being printed out on the server console?

..................Content has been hidden....................

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