Eran, thanks for answering the question.
The bottom line is:
-----------------
I'm trying to use the ReplyTo header. So I'll be more than thankful if you can send me the simplest example for calling a service on HTTP and getting response back via HTTP using the ReplyTo node in WS-Addressing.
About the question:
-----------------
I tried to use the ReplyTo header using the Axis2 userguide samples.
In the Axis2 samples\userguide there is an example of a service called MyService which has three methods: echo, ping and pingF
package userguide.example1;
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 javax.xml.stream.XMLStreamException;
/**
* Created by IntelliJ IDEA.
* User: Jaliya
* Date: Jun 2, 2005
* Time: 2:17:58 PM
*/
public class MyService {
public OMElement echo(OMElement element) throws XMLStreamException {
//Praparing the OMElement so that it can be attached to another OM Tree.
//First the OMElement should be completely build in case it is not fully built and still
//some of the xml is in the stream.
element.build();
//Secondly the OMElement should be detached from the current OMTree so that it can be attached
//some other OM Tree. Once detached the OmTree will remove its connections to this OMElement.
element.detach();
return element;
}
public void ping(OMElement element) throws XMLStreamException {
//Do some processing
}
public void pingF(OMElement element) throws AxisFault{
throw new AxisFault("Fault being thrown");
}
}
And there is a client called EchoNonBlockingDualClient which calls the echo method in the MyService service:
package userguide.clients;
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.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.client.async.AsyncResult;
import org.apache.axis2.client.async.Callback;
import javax.xml.namespace.QName;
/**
* Sample for asynchronous dual channel non-blocking service invocation.
* Message Exchage Pattern IN-OUT
* Ulitmate asynchronous service invocation sample.
*/
public class EchoNonBlockingDualClient {
private static EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2/services/MyService");
public static void main(String[] args) {
ServiceClient sender = null;
try {
OMElement payload = ClientUtil.getEchoOMElement();
Options options = new Options();
options.setTo(targetEPR);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setUseSeparateListener(true);
options.setAction("urn:echo"); // this is the action mapping we put within the service.xml
//Callback to handle the response
Callback callback = new Callback() {
public void onComplete(AsyncResult result) {
System.out.println(result.getResponseEnvelope());
}
public void onError(Exception e) {
e.printStackTrace();
}
};
//Non-Blocking Invocation
sender = new ServiceClient();
sender.engageModule(new QName(Constants.MODULE_ADDRESSING));
sender.setOptions(options);
sender.sendReceiveNonBlocking(payload, callback);
//Wait till the callback receives the response.
while (!callback.isComplete()) {
Thread.sleep(1000);
}
//Need to close the Client Side Listener.
} catch (AxisFault axisFault) {
axisFault.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
sender.finalizeInvoke();
} catch (AxisFault axisFault) {
//have to ignore this
}
}
}
}
I wanted the result of the echo method call to be sent to the MyService service, and call the ping method. So I added the following
options.setReplyTo(new EndpointReference("http://localhost:8080/axis2/services/MyService"));
In the EchoNonBlockingDualClient so that the result of the echo call would be sent to MyService service, and changed the result of the echo method to be ping element (for calling the ping method of MyService).
public OMElement echo(OMElement element) throws XMLStreamException {
OMElement o = getPingOMElement();
return o;
}
private OMElement getPingOMElement() {
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace(
"http://example1.org/example1", "example1");
OMElement method = fac.createOMElement("ping", omNs);
OMElement value = fac.createOMElement("Text", omNs);
value.addChild(fac.createOMText(value, "Axis2 Ping String "));
method.addChild(value);
return method;
}
Maybe I don’t understand the whole point around the ReplyTo, but I expected that the EchoNonBlockingDualClient will call the MyService.echo() method and the result of this call would be sent to the MyService with the ping action, calling the ping method.
But the ping method was not called at all.
Thanks,
Munir
-----Original Message-----
From: Eran Chinthaka [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 29, 2006 4:23 PM
To: [email protected]
Subject: Re: ReplyTo is not working
Munir Badir wrote:
> As a result I expected that the echo method would call the ping method,
> but it didn’t. Can anyone help?
I'm still confused in understanding the question. If you can explain a
bit with your code, it will be helpful in answering this question.
Thanks,
Chinthaka
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
