axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject svn commit: r149379 - in webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1: EchoInt.java InteropTest_Stub.java SampleEnvironmentCreator.java TestServer.java
Date Tue, 01 Feb 2005 09:53:30 GMT
Author: chathura
Date: Tue Feb  1 01:53:27 2005
New Revision: 149379

URL: http://svn.apache.org/viewcvs?view=rev&rev=149379
Log:
Completed Sample for EchoInt

Added:
    webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/EchoInt.java
Modified:
    webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/InteropTest_Stub.java
    webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/SampleEnvironmentCreator.java
    webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/TestServer.java

Added: webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/EchoInt.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/EchoInt.java?view=auto&rev=149379
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/EchoInt.java
(added)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/EchoInt.java
Tue Feb  1 01:53:27 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2001-2004 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 org.apache.axis.samples.userguide.example1;
+
+import java.net.URL;
+
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.engine.EngineUtils;
+
+/**
+ * @author chathura@opensource.lk
+ * 
+ */
+public class EchoInt {
+	
+	public static void main(String[] args) throws Exception {
+		InteropTest_Stub clientStub = new InteropTest_Stub();
+		URL url = new URL("http","127.0.0.1",EngineUtils.TESTING_PORT,"/axis/services/EchoXMLService");
+		clientStub.setEnePointReference(new EndpointReference(AddressingConstants.WSA_TO, url.toString()));
+		Integer echoInt = clientStub.echoInt(new Integer(794));
+		System.out.println(echoInt);
+		
+	}
+
+}

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/InteropTest_Stub.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/InteropTest_Stub.java?view=diff&r1=149378&r2=149379
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/InteropTest_Stub.java
(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/InteropTest_Stub.java
Tue Feb  1 01:53:27 2005
@@ -26,8 +26,10 @@
 import org.apache.axis.om.OMFactory;
 import org.apache.axis.om.OMNamespace;
 import org.apache.axis.om.OMNode;
+import org.apache.axis.om.OMText;
 import org.apache.axis.om.SOAPEnvelope;
-import org.apache.axis.samples.utils.OMUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
  * This file is hand written for the M1 demp purposes and will be 
@@ -38,6 +40,7 @@
 
 	private OMFactory omFactory = OMFactory.newInstance();
 	private Call call = new Call();
+	protected Log log = LogFactory.getLog(this.getClass());
 	
 		
 	
@@ -56,11 +59,16 @@
 	public java.lang.String echoString(java.lang.String inputValue)throws AxisFault{
 		this.validate();
 		SOAPEnvelope responceEnvelop = call.sendReceive(this.getSOAPEnvelopForEchoString(inputValue));

-		return this.getEchoStringFromSOAPEnvelop(responceEnvelop);
-		
-		
-		
+		return this.getEchoStringFromSOAPEnvelop(responceEnvelop);	
 	}
+	
+	public Integer echoInt(Integer inputValue) throws AxisFault{
+		this.validate();
+		SOAPEnvelope responceEnvelop = call.sendReceive(this.getSOAPEnvelopForEchoInt(inputValue));
	
+		return this.getEchoIntFromSOAPEnvelop(responceEnvelop);		
+	}
+	
+	
 	//\\\\\\\\\\\\\\\\End Webservice Operations\\\\\\\\\\\\\\\\\\//
 	
 	
@@ -74,16 +82,28 @@
 	
 	
 	protected SOAPEnvelope getSOAPEnvelopForEchoString(String value){
-		SOAPEnvelope envelop = OMUtil.getEmptySoapEnvelop();
+		SOAPEnvelope envelop = OMFactory.newInstance().getDefaultEnvelope();
 		OMNamespace interopNamespace = envelop.declareNamespace("http://soapinterop.org/", "interop");
 		OMElement echoStringMessage = omFactory.createOMElement("echoStringRequest", interopNamespace);
-		OMElement text = omFactory.createOMElement("Text", null);
+		OMElement text = omFactory.createOMElement("Text", interopNamespace);
 		text.addChild(omFactory.createText(value));
 		echoStringMessage.addChild(text);
-		envelop.addChild(echoStringMessage);
+		envelop.getBody().addChild(echoStringMessage);
 		return envelop;
 	}
 	
+	protected SOAPEnvelope getSOAPEnvelopForEchoInt(Integer value){
+		SOAPEnvelope envelope = OMFactory.newInstance().getDefaultEnvelope();
+		OMNamespace namespace = envelope.declareNamespace("http://soapinterop.org/", "interop");
+		OMElement echoIntMessage = omFactory.createOMElement("echoInt", namespace);
+		OMElement text = omFactory.createOMElement("Text", namespace);
+		text.addChild(omFactory.createText(value.toString()));
+		echoIntMessage.addChild(text);
+		envelope.getBody().addChild(echoIntMessage);
+		return envelope;		
+	}
+	
+	
 	protected String getEchoStringFromSOAPEnvelop(SOAPEnvelope envelop){
 		OMElement body = envelop.getBody();
 		OMElement response = null;
@@ -93,17 +113,41 @@
 			if(child instanceof OMElement && "echoStringResponse".equalsIgnoreCase(((OMElement)child).getLocalName())){
 				response = (OMElement)child;				
 			}
-		}
-		
+		}		
 		Iterator textChild = response.getChildrenWithName(new QName("", "Text"));
 		String value= null;
 		if(textChild.hasNext()){
 			 value = ((String)((OMElement)textChild.next()).getValue());
 		}
-		return value;
-		
+		return value;		
 	}
 	
+	protected Integer getEchoIntFromSOAPEnvelop(SOAPEnvelope envelop) throws AxisFault{
+		OMElement body = envelop.getBody();		
+		OMElement response = null;		
+		Iterator childrenIter = body.getChildren();
+		while(childrenIter.hasNext()){
+			OMNode child = (OMNode) childrenIter.next();
+			if(child instanceof OMElement && "echoIntResponse".equalsIgnoreCase(((OMElement)child).getLocalName())){
+				response = (OMElement)child;				
+			}
+		}
+		
+		Iterator textChild = response.getChildren();
+		while(textChild.hasNext()){
+			OMNode  child = (OMNode) textChild.next();
+			if(child instanceof OMElement && "echoIntReturn".equalsIgnoreCase(((OMElement)child).getLocalName())){
+				
+				OMNode val =((OMElement)child).getFirstChild();
+				if(val instanceof OMText)
+					return new Integer(((OMText)val).getValue());
+				
+			}
+		}
+		
+		this.log.info("Invalid data Binding");
+		throw new AxisFault("Invalid data Binding");	
+	}
 	
 	
 	protected void validate() throws AxisFault{

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/SampleEnvironmentCreator.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/SampleEnvironmentCreator.java?view=diff&r1=149378&r2=149379
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/SampleEnvironmentCreator.java
(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/SampleEnvironmentCreator.java
Tue Feb  1 01:53:27 2005
@@ -15,8 +15,17 @@
  */
 package org.apache.axis.samples.userguide.example1;
 
+import java.io.FileReader;
+import java.net.URL;
+
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
 
+import org.apache.axis.AbstractTestCase;
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.clientapi.Call;
 import org.apache.axis.context.MessageContext;
 import org.apache.axis.description.AxisGlobal;
 import org.apache.axis.description.AxisOperation;
@@ -25,8 +34,10 @@
 import org.apache.axis.engine.EngineUtils;
 import org.apache.axis.impl.description.AxisService;
 import org.apache.axis.impl.description.SimpleAxisOperationImpl;
+import org.apache.axis.impl.llom.builder.StAXSOAPModelBuilder;
 import org.apache.axis.impl.providers.SimpleJavaProvider;
 import org.apache.axis.impl.transport.http.SimpleHTTPReceiver;
+import org.apache.axis.om.SOAPEnvelope;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -34,10 +45,10 @@
  * @author chathura@opensource.lk
  * 
  */
-public class SampleEnvironmentCreator {
+public class SampleEnvironmentCreator extends  AbstractTestCase{
 	
     private Log log = LogFactory.getLog(getClass());
-    private QName serviceName = new QName("","InteropService");
+    private QName serviceName = new QName("","EchoXMLService");
     private QName operationName1 = new QName("http://localhost/my","echoInt");
     private QName operationName2 = new QName("http://localhost/my","echoString");
     private QName transportName = new QName("http://localhost/my","NullTransport");
@@ -47,6 +58,22 @@
     private Thread thisThread = null;
     private SimpleHTTPReceiver sas;
     
+    public SampleEnvironmentCreator(){
+        super(SampleEnvironmentCreator.class.getName());
+//        try {
+//			this.setUp();
+//			this.testInt();
+//			this.tearDown();
+//		} catch (Exception e) {
+//			// TODO Auto-generated catch block
+//			e.printStackTrace();
+//		}
+        
+    }
+
+    public SampleEnvironmentCreator(String testName) {
+        super(testName);
+    }
     
     protected void setUp() throws Exception {
         AxisGlobal global = new AxisGlobal();
@@ -66,12 +93,79 @@
         EngineUtils.createExecutionChains(service);
         engineRegistry.addService(service);
         
-        sas = EngineUtils.startServer(engineRegistry);
-        
-        
+        sas = EngineUtils.startServer(engineRegistry);        
     }
     
     
-    
+    protected void tearDown() throws Exception {
+        EngineUtils.stopServer();    
+        Thread.sleep(1000);
+}
 
+
+public void testInt() throws Exception{
+    try{
+   
+        Call call = new Call();
+        URL url = new URL("http","127.0.0.1",EngineUtils.TESTING_PORT,"/axis/services/EchoXMLService");
+        EndpointReference epr = new EndpointReference(AddressingConstants.WSA_TO, url.toString());
+        call.setTo(epr);
+        SOAPEnvelope reply = call.sendReceive(this.getechoIntEnvelope());
+        reply.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out),
false);
+        
+    }catch(Exception e){
+        e.printStackTrace();
+        tearDown();
+        throw e;
+    }    
+}
+public void testString() throws Exception{
+//    try{
+//        OMFactory fac = OMFactory.newInstance();
+//
+//        OMNamespace omNs = fac.createOMNamespace("http://localhost/my","my");
+//        OMElement method =  fac.createOMElement("echoOMElement",omNs) ;
+//        OMElement value =  fac.createOMElement("myValue",omNs) ;
+//        value.setValue("Isaac Assimov, the foundation Sega");
+//        method.addChild(value);
+//        
+//        Call call = new Call();
+//        URL url = new URL("http","127.0.0.1",EngineUtils.TESTING_PORT,"/axis/services/EchoXMLService");
+//        
+//        CallBack callback = new CallBack() {
+//            public void doWork(OMElement ele) {
+//                System.out.print("got the result = " + ele +" :)");
+//
+//            }
+//            public void reportError(Exception e) {
+//                log.info("reporting error from callback !");
+//                e.printStackTrace();
+//            }
+//        };
+//        
+//        call.asyncCall(method,url,callback);
+//        log.info("send the reqest");
+//        
+//        Thread.sleep(1000);
+//    }catch(Exception e){
+//        e.printStackTrace();
+//        tearDown();
+//        throw e;
+//    }    
+}
+
+ public static void main(String[] args) {
+ 	new SampleEnvironmentCreator();
+	
+}
+
+private SOAPEnvelope getechoIntEnvelope() throws Exception {
+
+    SOAPEnvelope envelope = new StAXSOAPModelBuilder(XMLInputFactory.newInstance().createXMLStreamReader(
+            new FileReader(getTestResourceFile("echo/echoInt.xml")))).getSOAPEnvelope();
+    envelope.serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out),
false);
+    return envelope;
+}
+	
+    
 }

Modified: webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/TestServer.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/TestServer.java?view=diff&r1=149378&r2=149379
==============================================================================
--- webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/TestServer.java
(original)
+++ webservices/axis/trunk/java/dev/scratch/prototype2/samples/org/apache/axis/samples/userguide/example1/TestServer.java
Tue Feb  1 01:53:27 2005
@@ -26,7 +26,7 @@
 	public static void main(String[] args) throws Exception {
 		
 		new SampleEnvironmentCreator().setUp();
-		Thread.sleep(150000);
+		Thread.sleep(300000);
 	}
 	
 	protected void tearDown() throws Exception {



Mime
View raw message