You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by mi...@fortis.com on 2006/05/29 10:22:28 UTC
[axis 2][sandesha] The responses concatenate with echostring example
Hi everybody !
I am a beginner with axis 2.0, I have tried to run the example
echostring with WS-ReliableMessaging (module sandesha)
in a JSP page but I got some problems,...
When I run the example I got as response the following string :
"echo1echo2echo3".
But if I run it again, even from another computer, I got the response
"echo1echo2echo3echo1echo2echo3" !
Is it normal ? What should I do to avoid this ? I have added
"serviceClient.finalizeInvoke();"
at the end to release resources.
Here is the code I am using :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.File"%>
<%@ page import="javax.xml.namespace.QName"%>
<%@ page import="org.apache.axiom.om.OMAbstractFactory"%>
<%@ page import="org.apache.axiom.om.OMElement"%>
<%@ page import="org.apache.axiom.om.OMFactory"%>
<%@ page import="org.apache.axiom.om.OMNamespace"%>
<%@ page import="org.apache.axiom.soap.SOAPBody"%>
<%@ page import="org.apache.axis2.Constants"%>
<%@ page import="org.apache.axis2.addressing.EndpointReference"%>
<%@ page import="org.apache.axis2.client.Options"%>
<%@ page import="org.apache.axis2.client.ServiceClient"%>
<%@ page import="org.apache.axis2.client.async.AsyncResult"%>
<%@ page import="org.apache.axis2.client.async.Callback"%>
<%@ page import="org.apache.axis2.context.ConfigurationContext"%>
<%@ page import="org.apache.axis2.context.ConfigurationContextFactory"%>
<%@ page import="org.apache.sandesha2.client.SandeshaClientConstants"%>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="IBM Software Development Platform">
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="theme/Master.css" rel="stylesheet"
type="text/css">
<TITLE>index.jsp</TITLE>
</HEAD>
<BODY>
<h1> Test Technique Web Services</h1>
<h2> AXIS 2.0 Web Service Reliable Messaging Client</h2>
<P>Placez le contenu ici.</P>
<%!
private final static String applicationNamespaceName =
"http://tempuri.org/";
private final static String echoString = "echoString";
private final static String Text = "Text";
private final static String Sequence = "Sequence";
private final static String echoStringResponse =
"echoStringResponse";
private final static String EchoStringReturn = "EchoStringReturn";
private static String toEPR =
"http://127.0.0.1:9080/axis2/services/RMSampleService";
private static String CLIENT_REPO_PATH =
"c:\\Winprog\\WorkspacesRSA\\WSRMClient";
%>
<%!
private static OMElement getEchoOMBlock(String text, String sequenceKey)
{
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace applicationNamespace =
fac.createOMNamespace(applicationNamespaceName,"ns1");
OMElement echoStringElement = fac.createOMElement(echoString,
applicationNamespace);
OMElement textElem =
fac.createOMElement(Text,applicationNamespace);
OMElement sequenceElem =
fac.createOMElement(Sequence,applicationNamespace);
textElem.setText(text);
sequenceElem.setText(sequenceKey);
echoStringElement.addChild(textElem);
echoStringElement.addChild(sequenceElem);
return echoStringElement;
}
static class TestCallback extends Callback {
String name = null;
public TestCallback (String name) {
this.name = name;
}
public void onComplete(AsyncResult result) {
SOAPBody body = result.getResponseEnvelope().getBody();
OMElement echoStringResponseElem =
body.getFirstChildWithName(new QName
(applicationNamespaceName,echoStringResponse));
OMElement echoStringReturnElem =
echoStringResponseElem.getFirstChildWithName(new QName
(applicationNamespaceName,EchoStringReturn));
String resultStr = echoStringReturnElem.getText();
System.out.println("Callback '" + name + "' got result:" +
resultStr);
}
public void onError (Exception e) {
System.out.println("Error reported for test call back");
e.printStackTrace();
}
}
%>
<%
String axis2_xml = CLIENT_REPO_PATH + File.separator
+"client_axis2.xml";
try{
System.out.println("-- Creation of context");
ConfigurationContext configContext =
org.apache.axis2.context.ConfigurationContextFactory.createConfiguration
ContextFromFileSystem(CLIENT_REPO_PATH,axis2_xml);
System.out.println("-- Service client");
ServiceClient serviceClient = new ServiceClient
(configContext,null);
System.out.println("Options");
Options clientOptions = new Options ();
System.out.println("-- YOP 5");
clientOptions.setTo(new EndpointReference(toEPR));
clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
clientOptions.setUseSeparateListener(true);
serviceClient.setOptions(clientOptions);
// serviceClient.engageModule(new QName ("sandesha2"));
// serviceClient.engageModule(new QName ("addressing"));
System.out.println("-- Set Callback");
Callback callback1 = new TestCallback ("Callback 1");
serviceClient.sendReceiveNonBlocking
(getEchoOMBlock("echo1","sequence1"),callback1);
Callback callback2 = new TestCallback ("Callback 2");
serviceClient.sendReceiveNonBlocking(getEchoOMBlock("echo2","sequence1")
,callback2);
//clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE,
"true");
Callback callback3 = new TestCallback ("Callback 3");
serviceClient.sendReceiveNonBlocking(getEchoOMBlock("echo3","sequence1")
,callback3);
clientOptions.setProperty(SandeshaClientConstants.LAST_MESSAGE,
"true");
Callback callback4 = new TestCallback ("Callback 4");
serviceClient.sendReceiveNonBlocking(getEchoOMBlock("echo4","sequence2")
,callback4);
System.out.println("-- before last while");
while (!callback3.isComplete()) {
Thread.sleep(1000);
}
System.out.println("-- before sleep");
Thread.sleep(4000);
System.out.println("-- after sleep");
serviceClient.finalizeInvoke();
}catch (Exception e){
System.out.println("ERROR !!!!");
e.printStackTrace();
}
%>
</BODY>
</HTML>