You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sandesha-dev@ws.apache.org by ch...@apache.org on 2006/10/05 07:57:59 UTC

svn commit: r453112 - in /webservices/sandesha/trunk/java/samples/src/sandesha2/samples: simpleServer/SimpleSandesha2Server.java userguide/AsyncEchoBlockingClient.java userguide/AsyncEchoWithPollingClient.java

Author: chamikara
Date: Wed Oct  4 22:57:58 2006
New Revision: 453112

URL: http://svn.apache.org/viewvc?view=rev&rev=453112
Log:
Updated samples.


Added:
    webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoWithPollingClient.java
Modified:
    webservices/sandesha/trunk/java/samples/src/sandesha2/samples/simpleServer/SimpleSandesha2Server.java
    webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoBlockingClient.java

Modified: webservices/sandesha/trunk/java/samples/src/sandesha2/samples/simpleServer/SimpleSandesha2Server.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/samples/src/sandesha2/samples/simpleServer/SimpleSandesha2Server.java?view=diff&rev=453112&r1=453111&r2=453112
==============================================================================
--- webservices/sandesha/trunk/java/samples/src/sandesha2/samples/simpleServer/SimpleSandesha2Server.java (original)
+++ webservices/sandesha/trunk/java/samples/src/sandesha2/samples/simpleServer/SimpleSandesha2Server.java Wed Oct  4 22:57:58 2006
@@ -25,7 +25,7 @@
 
 public class SimpleSandesha2Server {
 
-	private static String SANDESHA2_HOME = "/home/ruchith/workspace/sandesha2"; //Change this to ur path.
+	private static String SANDESHA2_HOME = "<SANDESHA2_HOME>"; //Change this to ur path.
 	
 	private static String AXIS2_SERVER_PATH = SANDESHA2_HOME + File.separator + "target" + File.separator +"repos" + File.separator + "server" + File.separator;   //this will be available after a maven build
 	

Modified: webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoBlockingClient.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoBlockingClient.java?view=diff&rev=453112&r1=453111&r2=453112
==============================================================================
--- webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoBlockingClient.java (original)
+++ webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoBlockingClient.java Wed Oct  4 22:57:58 2006
@@ -16,23 +16,17 @@
 
 package sandesha2.samples.userguide;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLInputFactory;
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMAttribute;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.impl.llom.factory.OMXMLBuilderFactory;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
-import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.EndpointReference;

Added: webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoWithPollingClient.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoWithPollingClient.java?view=auto&rev=453112
==============================================================================
--- webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoWithPollingClient.java (added)
+++ webservices/sandesha/trunk/java/samples/src/sandesha2/samples/userguide/AsyncEchoWithPollingClient.java Wed Oct  4 22:57:58 2006
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package sandesha2.samples.userguide;
+
+import java.io.File;
+
+import javax.xml.namespace.QName;
+
+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.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.AddressingConstants;
+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 org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContextConstants;
+import org.apache.sandesha2.Sandesha2Constants;
+import org.apache.sandesha2.client.SandeshaClient;
+import org.apache.sandesha2.client.SandeshaClientConstants;
+import org.apache.sandesha2.util.SandeshaUtil;
+
+public class AsyncEchoWithPollingClient {
+	
+	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 String toIP = "127.0.0.1";
+	
+	private String toPort = "8070";
+	
+	private String transportToPort = "8070";
+	
+	private String toEPR = "http://" + toIP +  ":" + toPort + "/axis2/services/RMSampleService";
+	
+	private String transportToEPR = "http://" + toIP +  ":" + transportToPort + "/axis2/services/RMSampleService";
+	
+	private static String SANDESHA2_HOME = "<SANDESHA2_HOME>"; //Change this to ur path.
+	
+	private static String AXIS2_CLIENT_PATH = SANDESHA2_HOME + File.separator + "target" + File.separator +"repos" + File.separator + "client" + File.separator;   //this will be available after a maven build
+	
+	public static void main(String[] args) throws Exception {
+		
+		
+		String axisClientRepo = null;
+		if (args!=null && args.length>0)
+			axisClientRepo = args[0];
+		
+		if (axisClientRepo!=null && !"".equals(axisClientRepo)) {
+			AXIS2_CLIENT_PATH = axisClientRepo;
+			SANDESHA2_HOME = "";
+		}
+		
+		new AsyncEchoWithPollingClient ().run();
+	}
+	
+	private void run () throws Exception {
+		
+		if ("<SANDESHA2_HOME>".equals(SANDESHA2_HOME)){
+			System.out.println("ERROR: Please set the directory you unzipped Sandesha2 as the first option.");
+			return;
+		}
+
+		String axis2_xml = AXIS2_CLIENT_PATH + "client_axis2.xml";
+     
+		ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(AXIS2_CLIENT_PATH,axis2_xml);
+
+		ServiceClient serviceClient = new ServiceClient (configContext,null);	
+		
+		Options clientOptions = new Options ();
+		
+		clientOptions.setTo(new EndpointReference (toEPR));
+		
+//		String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress() + "/" + ServiceClient.ANON_OUT_IN_OP;
+//		clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+		
+		String sequenceKey = SandeshaUtil.getUUID();  //sequence key for thie sequence.
+		clientOptions.setProperty(SandeshaClientConstants.SEQUENCE_KEY,sequenceKey);
+		
+		clientOptions.setReplyTo(new EndpointReference (AddressingConstants.Submission.WSA_ANONYMOUS_URL));
+		
+		clientOptions.setProperty(MessageContextConstants.TRANSPORT_URL,transportToEPR);
+		
+//		clientOptions.setProperty(MessageContextConstants.CHUNKED,Constants.VALUE_FALSE);   //uncomment this to send messages without chunking.
+		
+		clientOptions.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);   //uncomment this to send messages in SOAP 1.2
+		
+		clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,Sandesha2Constants.SPEC_VERSIONS.v1_1);  //uncomment this to send the messages according to the v1_1 spec.
+		
+		clientOptions.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,AddressingConstants.Submission.WSA_NAMESPACE);
+		clientOptions.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID,SandeshaUtil.getUUID());  //Uncomment this to offer a sequenceID for the incoming sequence.
+		clientOptions.setAction("urn:wsrm:EchoString");
+		
+		//You must set the following two properties in the request-reply case.
+		clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+
+		//This asks Axis2 not to start a listner.
+		clientOptions.setUseSeparateListener(true);
+		
+		serviceClient.setOptions(clientOptions);
+
+		Callback callback1 = new TestCallback ("Callback 1");
+		serviceClient.sendReceiveNonBlocking(getEchoOMBlock("echo1",sequenceKey),callback1);
+		
+		Callback callback2 = new TestCallback ("Callback 2");
+		serviceClient.sendReceiveNonBlocking(getEchoOMBlock("echo1",sequenceKey),callback2);
+		
+		Callback callback3 = new TestCallback ("Callback 3");
+		serviceClient.sendReceiveNonBlocking(getEchoOMBlock("echo1",sequenceKey),callback3);
+		
+        while (!callback3.isComplete()) {
+            Thread.sleep(1000);
+        }
+        
+        Thread.sleep(4000);
+        
+        SandeshaClient.terminateSequence(serviceClient);
+        
+	}
+
+	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;
+	}
+
+	public class TestCallback extends Callback {
+
+		String name = null;
+		
+		public TestCallback () {
+			
+		}
+		
+		public TestCallback (String name) {
+			this.name = name;
+		}
+		
+		public void onComplete(AsyncResult result) {
+			//System.out.println("On Complete Called for " + text);
+			SOAPBody body = result.getResponseEnvelope().getBody();
+			
+			OMElement echoStringResponseElem = body.getFirstChildWithName(new QName (applicationNamespaceName,echoStringResponse));
+			if (echoStringResponseElem==null) { 
+				System.out.println("Error: SOAPBody does not have a 'echoStringResponse' child");
+				return;
+			}
+			
+			OMElement echoStringReturnElem = echoStringResponseElem.getFirstChildWithName(new QName (applicationNamespaceName,EchoStringReturn));
+			if (echoStringReturnElem==null) { 
+				System.out.println("Error: 'echoStringResponse' element does not have a 'EchoStringReturn' child");
+				return;
+			}
+			
+			String resultStr = echoStringReturnElem.getText();
+			System.out.println("Callback '" + name +  "' got result:" + resultStr);
+		}
+
+		public void onError (Exception e) {
+			// TODO Auto-generated method stub
+			System.out.println("Error reported for test call back");
+			e.printStackTrace();
+		}
+	}
+
+	
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org