Velocity Reviews

Velocity Reviews (
-   Java (
-   -   Axis2 WebService client with Eclipse (

carmelo 10-20-2008 01:41 PM

Axis2 WebService client with Eclipse
Hi everybody,
I developed an Axis2 WebService with Netbeans, and its client. It was
easy enough, because Netbeans made it simple...
Now I'd like to develop the client with Eclipse, because I need to
integrate it into an application developed with Eclipse. Importing the
jar file created by Netbeans it works easily, but it doesn't seem a
"clean" solution...

Searching on the internet (
2006/12/13/invoking-web-services-using-apache-axis2.html) I've found
the following code, which should work as client:

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.async.AxisCallback;
import org.apache.axis2.context.MessageContext;

public class WSClient

public static boolean finish = false;

public static void main(String[] args) throws Exception {

ServiceClient sender = new ServiceClient();

// create option object
Options opts = new Options();

try {
// setting target EPR
opts.setTo(new EndpointReference(
// Setting action ,and which can be found from the wsdl of the
// service


AxisCallback callback = new AxisCallback() {

* This is called when we receive a message.
* @param msgContext
* the (response) MessageContext
public void onMessage(MessageContext msgContext) {
OMElement result = msgContext.getEnvelope().getBody()
System.out.println(msgContext.getEnvelope().toStri ng());
System.out.println(msgContext.getEnvelope().getBod y()
finish = true;

* This gets called when a fault message is received.
* @param msgContext
* the MessageContext containing the fault.
public void onFault(MessageContext msgContext) {
System.out.println(msgContext.getEnvelope().getBod y()


* This gets called ONLY when an internal processing exception
* occurs.
* @param e
* the Exception which caused the problem
public void onError(Exception e) {

* This is called at the end of the MEP no matter what happens,
* quite like a finally block.
public void onComplete() {




System.out.println("-------Invoke the service---------");

sender.sendReceiveNonBlocking(createPayLoad(), callback);

// wait till you get the response, in real applications you do not
// need
// to do this, since once the response arrive axis2 will notify
// callback,
// then you can implement callback to do whatever you want, may be
// to update GUI

synchronized (callback) {
if (!finish) {
if (!finish) {
throw new AxisFault(
"Server was shutdown as the async response take too long to
} finally {
if (sender != null)


public static OMElement createPayLoad() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("
OMElement method = fac.createOMElement("echo", omNs);
OMElement value = fac.createOMElement("value", omNs);
value.setText("Hello , my first service utilization");
return method;


The only customization I did was to set Options to:

opts.setTo(new EndpointReference(

- I get the following runtime exception:

Exception in thread "main" org.apache.axis2.AxisFault: Unable to
engage module : addressing

I hope you can help me solving this problem
Thank you very much in advance

All times are GMT. The time now is 05:00 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.