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);
}
public interface IHelloWeb extends IHello, java.rmi.Remote {}
<?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 ch13JbiProxy 3_AccessExternalWebService 1_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:
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);
}
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();
}
}
}
public interface IHelloProxy
{
public String hello(String input);
}
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.