4 min read

You can use XFire to create stub classes based on your WSDL exposed by your external web service. Now you can inject the stub into your JSR181 SU. The stub will be used by the proxy to generate the exchange with the HTTP provider (which should be referenced as the “service”).

Using JBI proxy now, it is possible to invoke web services in the RPC style from within the JBI bus. For this we leverage the stub classes generated out from the web service WSDL using Axis.

Web Service Code Listing

We are interested in proxy setup to access a remote web service, hence we will not discuss the details of the web service deployment in this section. Instead, we will just browse through the important web service interfaces and the associated WSDL and then move on to binding the proxy.

The web service implements the IHelloWeb remote interface which in turn extends the IHello business interface. They are listed here as follows:

  • IHello.java: IHello is a simple BI, having a single business method hello.
  • public interface IHello
    {
    String hello(String param);
    }

  • IHelloWeb.java: In order to deploy a web service, we need an interface complying with the Java RMI semantics, and IHelloWeb will serve this purpose.
  • public interface IHelloWeb extends IHello, java.rmi.Remote {}

  • HelloWebService.wsdl: The main sections in the web service WSDL is shown as follows:
  • <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions targetNamespace="http://AxisEndToEnd.
    axis.apache.binildas.com" ...>
    <wsdl:types ... />
    <wsdl:message ... />
    <wsdl:portType name="IHelloWeb">
    </wsdl:portType>
    <wsdl:binding name="HelloWebServiceSoapBinding"
    type="impl:IHelloWeb">
    </wsdl:binding>
    <wsdl:service name="IHelloWebService">
    <wsdl:port binding="impl:HelloWebServiceSoapBinding"
    name="HelloWebService">
    <wsdlsoap:address
    location="http://localhost:8080/AxisEndToEnd/services/
    HelloWebService"/>
    </wsdl:port>
    </wsdl:service>
    </wsdl:definitions>

This is enough about the web service and we will move on to the next step.

Axis Generated Client Stubs

We use org.apache.axis.wsdl.WSDL2Java class in the wsdl2java task to generate client-side binding classes and stubs. The main classes are available in the folder ch13JbiProxy3_AccessExternalWebService1_wsgensrc and they are as follows:

  • HelloWebService.java
  • HelloWebServiceSoapBindingStub.java
  • IHelloWeb.java
  • IHelloWebService.java
  • IHelloWebServiceLocator.java

All the above artifacts are Axis generated client-side stubs, hence we will not look into the details of them here. Instead, let us look into the structural relationship between the various developer created and Axis generated artifacts shown in the following figure:

Service Oriented Java Business Integration

Referring to the above diagram, let us understand the relevant artifacts. Here our aim is to generate a JBI proxy for an externally bound web service. We are doing this using the following classes:

  • ITarget.java: This interface is synonymous to the BI IHello, having a single business method hello. We want to auto-route request-response through the JBI proxy. In order to facilitate this we have retained the method signature in the interfaces the same.

  • public interface ITarget
    {
    String hello(String input);
    }

  • TargetService.java: In TargetService, we auto-wire the web service stub. So, the helloWeb instance field in TargetService will hold a reference to the stub to the web service. When the hello method is invoked in TargetService, the call is delegated to the stub which will invoke the remote web service.
  • public class TargetService implements ITarget
    {
    private com.binildas.apache.axis.AxisEndToEnd.
    IHelloWeb helloWeb;
    public TargetService(){}
    public TargetService(com.binildas.apache.axis.
    AxisEndToEnd.IHelloWeb helloWeb)
    {
    this.helloWeb = helloWeb;
    }
    public String hello(String input)
    {
    System.out.println("TargetService.echo : String. this = " +
    this);
    try
    {
    return helloWeb.hello(input);
    }
    catch(Exception exception)
    {
    exception.printStackTrace();
    return exception.getMessage();
    }
    }
    }

  • IHelloProxy.java: We now need to wire the JBI proxy to the web services stub. IHelloProxy is an interface defined for this purpose and hence is having the same single business method, hello.

  • public interface IHelloProxy
    {
    public String hello(String input);
    }

  • IHelloProxyService.java: HelloProxyService is a wrapper or adapter for the JBI proxy. In other words, the helloProxy instance field in HelloProxyService will refer to the JBI proxy.
  • public class HelloProxyService implements IHelloProxy
    {
    private IHelloProxy helloProxy;
    public void setHelloProxy(IHelloProxy helloProxy)
    {
    this.helloProxy = helloProxy;
    }
    public String hello(String input)
    {
    System.out.println("HelloProxyService.hello. this = " + this);
    return helloProxy.hello(input);
    }
    }

The bean wiring discussed in this section is done using Spring and is shown in the next section.

LEAVE A REPLY

Please enter your comment!
Please enter your name here