Axis2 WebService client with Eclipse

C

carmelo

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 (http://today.java.net/pub/a/today/
2006/12/13/invoking-web-services-using-apache-axis2.html) I've found
the following code, which should work as client:

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
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(
"http://localhost:8080/axis2/services/HelloAxisWorld"));
// Setting action ,and which can be found from the wsdl of the
// service
opts.setAction("urn:echo");

//opts.setTransportInProtocol("http");
//opts.setUseSeparateListener(true);

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()
.getFirstElement();
System.out.println(msgContext.toString());
System.out.println(msgContext.getEnvelope().toString());
System.out.println(msgContext.getEnvelope().getBody()
.getFirstElement());
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().getBody()
.getFault().toString());

}

/**
* 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("OnComplete!!!");

}
};

sender.setOptions(opts);

sender.engageModule("addressing");

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) {
callback.wait(45000);
if (!finish) {
throw new AxisFault(
"Server was shutdown as the async response take too long to
complete");
}
}
}
} finally {
if (sender != null)
sender.disengageModule("addressing");
sender.cleanup();
}

}

public static OMElement createPayLoad() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://ws.apache.org/
axis2",
"ns1");
OMElement method = fac.createOMElement("echo", omNs);
OMElement value = fac.createOMElement("value", omNs);
value.setText("Hello , my first service utilization");
method.addChild(value);
return method;
}

}


The only customization I did was to set Options to:

opts.setTo(new EndpointReference(
"http://localhost:8080/axis2/services/HelloAxisWorld"));

- 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
Carmelo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top