Developing a JAX-WS client for WebSphere transport for SOAP using Eclipse
Develop an Axis2 web service client to run using the IBM MQ transport for SOAP. The sample Axis2 clients provided with IBM MQ transport for SOAP are listed, and the wsimport command used to generate proxies.
Before you begin
Obtain the Axis2 libraries, and configure a development
and test environment to run the client.
Note: The naming of versions and releases used by Axis causes confusion. Typically,
Axis 1.4 refers to the JAX-RPC implementation, and Axis2 to the JAX-WS implementation.
Axis 1.4
is a version level. If you search for Axis 1.4 on the internet, you are taken to http://ws.apache.org/axis/. The page
contains a list of preceding versions of Axis (1.2, 1.3) and the April 22, 2006, final release of
Axis 1.4. There are later releases of Axis 1.4, that fix bugs, but they are all known as Axis 1.4.
It is one of these bug fix releases that is shipped with IBM MQ. For Axis 1.4, use the version of
axis.jar that is shipped with IBM MQ rather than the one obtainable from http://ws.apache.org/axis/.
The Axis website also refers to Axis 1.1
to refer to all the versions of what is more typically called Axis 1.4. Axis 1.2 is used to refer to
what is typically called Axis2.
We can choose to generate proxies for the web service clients for IBM MQ transport for
SOAP using either wsimport or the tooling provided
with an IDE. Eclipse IDE for Java EE
Developer 3.5 SR1 uses wsdl2java. wsimport is
supplied with Java 6. We can
use Java 5 to run client proxies
generated either with wsimport or wsdl2java.
The
sample web service Axis2 clients provided with IBM MQ transport for SOAP were developed
using wsimport ; see Sample Axis2 clients.
The
task that follows demonstrates how to generate and use the proxies
produced by the web services wizard that is packaged with Eclipse
IDE for Java EE Developers.
The sample clients show how to use the proxies produced by wsimport.
To use the web services wizard, you must add an application server that supports Axis2 to the
workbench. The steps show how to configure the Liberty profile to support Axis2 using the workbench.
Configure the application server used in Eclipse IDE for Java EE Developers to support Axis2. In this example,
configure the Liberty profile.
Open the workspace preferences to configure the server: Open Window >
Preferences.
Check the installed JRE is Java50: Click Installed
JREs.
Add the Liberty profile as the server:
Add Axis2: Click Web Services > Axis2 Preferences.
On the Axis2 Runtime tab > Browse... Open the directory
containing the many Axis2 jar files > Apply.
Associate Liberty with Axis2: Click Web Services > Server and
Runtime. Under Server select IBM Liberty Server, and under Web
service runtime, select Apache Axis2 >
Apply > OK
Start the server: Open the Web perspective and open the Servers view. Right click in the Servers
view > New > Server. IBM Liberty Server is selected and configured >
Finish. Start the server.
Check that we have deployed the StockQuoteAxis service to Liberty to run the web service
wizard.
To test the service with the IBM MQ transport for
SOAP service, deploy the service to an IBM MQ transport
for SOAP listener for Axis 1.4; see the Liberty profile.
The Eclipse IDE for Java EE Developers uses Java50 and the web services wizard to generate the proxy classes for the service. The proxy classes are different to the classes created by the wsimport tool provided with Java 6. An alternative approach is to generate the proxy classes using wsimport and import the packages it creates into your Eclipse Java EE IDE for Web Developers.
The web services wizard in the Eclipse IDE for Java EE Developers builds a web service client in a Web project. We can run the client as a simple Java application; it does not require an application server. We can also transfer the code to a Java project, and configure the build path to include the Axis2 JAR files.
Procedure
Create a Web project in a new Enterprise project:
With nothing selected in the Project Explorer > Right-click the white space >
New > Enterprise Application Project > Name it
StockQuoteAxis2EAR > Finish. Reply
No to the window giving you the option of opening the Java EE perspective.
The defaults are set to use Liberty.
Right-click StockQuoteAxis2EAR > New >
Dynamic Web Project. Name the project
StockQuoteAxis2WebClient > Check the EAR membership box to add the project to
StockQuoteAxis2EAR. Liberty is selected as the Target runtime.
In the Configuration section of the New Dynamic Web Project page >
Modify... > Check the Axis2 web services project facet. Dynamic
Web Module 2.5, Java
6.0, and Liberty are already checked. > OK
> Finish. Reply No to the window giving you the option
of opening the Java EE perspective.
Import WSDL for the service into the workspace and generate the client proxy:
In this example, the WSDL document contains the HTTP service binding and becomes the target for the static Web client proxy. We can modify the URL in the web service binding to point to the IBM MQ transport for SOAP URL before generating the client proxy. The static Web client proxy is then the service that is deployed to IBM MQ transport for SOAP.
Launch the Web Services Explorer: either use the icon in the action bar, or Run > Launch the Web Services Explorer.
Select the WSDL explorer by clicking the WSDL icon in the Web Services Explorer window > Click WSDL Main in the Navigator window > Type the URL of the StockQuoteAxis WSDL file > Go.
In this example, obtain the WSDL directly from the HTTP service: http://localhost:8080/StockQuoteAxis/services/StockQuoteAxis?wsdl
In the Navigator, click the line with the URL of the web service. In the Actions window, click Import WSDL to Workbench > Select a StockQuoteAxis2WebClient as the Workbench project > Type the WSDL file name, StockQuoteAxisHTTP.wsdl > Go.
Right-click StockQuoteAxisHTTP.wsdl > Web
Services > Generate Client. Check the configuration information
about the web services page of the wizard is as follows: Server: IBM Liberty Server, web service runtime: Apache Axis2, Client
project: StockQuoteAxis2WebClient, Client EAR project: StockQuoteAxisEAR. To correct the
configuration, click the lines that are wrong.
Click Next > verify the code generation settings > Finish.
Notice that a new package, soap.server, is created and it contains the proxies you require.
Configure the project to run IBM MQ transport for SOAP as the JMS transport.
IBM MQ transport for SOAP provides a transportSender, but no transportReceiver. In other words, IBM MQ transport for SOAP supports Axis2 clients. Currently it does not support Axis2 services.
In the StockQuoteAxis2WebClient project, right-click WebContent\WEB-INF\conf\axis2.xml > Open with... > XML editor.
Search for the last transportSender (towards the end of the file) and find the commented out JMS transportSender > Right-click the line > Add before... > transportSender.
Right-click Name > Edit Attribute > Type the Value: jms
Right-click Class > Edit Attribute > Type the Value: com.ibm.mq.axis2.transport.jms.WMQJMSTransportSender.> Save.
Add com.ibm.mq.axis2.transport.jms.WMQJMSTransportSender to the build path: Right-click StockQuoteAxis2WebClient > Build Path > Configure Build Path... > Click the Libraries tab > Add External JARs.... Select all the JARs in MQ_INSTALLATION_PATH \java\lib > OK.
MQ_INSTALLATION_PATH is the directory where IBM MQ is installed.
Create a synchronous static client, test it using HTTP, then convert the proxy to run the static client using IBM MQ transport for SOAP.
Right-click Java Resources: src > New > Package > Name the package soap.client > Finish
Right-click soap.client > New > Class > Name the class SQA2StaticClient > Finish.
Replace the class with the code in Figure 1 > Save.
Test the client with the StockQuoteAxis service deployed to Liberty, and with IBM MQ transport for SOAP.
In the Project Explorer, right-click SQA2StaticClient > Run
as... > Java
Application.
The result, Response is 55.25 , appears in the Console
view. We can also select the Liberty console window in the Console view, and see the output on the
Liberty server, StockQuoteAxis called with parameter: ibm .
The proxy was built with the service address,
http://localhost:8080/StockQuoteAxis/services/StockQuoteAxis, and so the static
client calls the service running on HTTP. We can change the static client to call the service using
IBM MQ transport for SOAP. The following instructions
change the service address in StockQuoteAxisServiceStub.java without rebuilding
the proxy, and configure the SQA2StaticClient runtime parameters to load
axis2.xml. You configure axis2.xml configures Axis2 to use
IBM MQ transport for SOAP.
Open StockQuoteAxisServiceStub.java >
Replace the two occurrences of
http://localhost:8080/StockQuoteAxis/services/StockQuoteAxis with,
If you run SQA2StaticClient now, it throws an exception because it has not
found a transportSender configured for JMS
The exception is:
Exception: null java.lang.NullPointerException at
soap.server.StockQuoteAxisServiceStub.getQuote(StockQuoteAxisServiceStub.java:547)
at soap.client.SQA2StaticClient.main(SQA2StaticClient.java:11)
In the Project Explorer, right-click SQA2StaticClient > Run
as... > Run Configurations.... Switch to the (x)=
Arguments tab, and in the VM arguments input area, type the path
to the axis2.conf file> Apply >
Run.
The VM argument is:
-Daxis2.xml=${workspace_loc:StockQuoteAxis2WebClient/WebContent/WEB-INF/conf}/axis2.xml.
Or we can provide a standard path to the Axis2 configuration file.
Run SQA2StaticClient again. On this run, you are using the IBM MQ transport for SOAP. Confirm it by checking there is no new
output in the Liberty console. Open the console or command window that is associated with
SimpleJavaListener, and the output there is
StockQuoteAxis called with parameter: ibm .
Create a dynamic client for HTTP and IBM MQ transport for SOAP, and test it.
Right-click soap.client > New > Class > Name the class SQA2DynamicClient > Finish.
Replace the class with the code in Figure 2 > Save.
Create a Run configuration for SQA2DynamicClient.java, and add the path to axis2.xml:
-Daxis2.xml=${workspace_loc:StockQuoteAxis2WebClient/WebContent/WEB-INF/conf}/axis2.xml
Run SQA2DynamicClient. Check the console output for the
SQA2DynamicClient, Liberty and SimpleJavaListener.
Create an asynchronous client, and access the result in a callback handler, and in the main program thread.
The asynchronous client proxies created by the web service wizard for Eclipse Java EE IDE for Web Developers differ from the proxies created by wsimport. The wsimport proxies use Future, Response, and AsyncHandler generic types.
The web service wizard for Eclipse Java EE IDE for Web Developers creates a StockQuoteAxisServiceCallbackHandler abstract class. You must extend StockQuoteAxisServiceCallbackHandler and create a callback handler.
Right-click soap.client > New > Class > Name the class SQA2CallbackHandler > Finish.
The client samples are generated for the sample StockQuoteAxis server. Generate the WSDL with the amqwdepoyWMQServer command, specifying the -w switch to select rpcLiteral style. Use the following command to generate the proxies for the samples: