ws-axis-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: r154854 - in webservices/axis/trunk/java/modules/samples/src: java/interop/doclit/InteropStub.java java/interop/doclit/SOAPStructEncoder.java java/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java jsp/ test/interop/ test/interop/doclit/ test/interop/doclit/InteropStubTest.java
Date Tue, 22 Feb 2005 14:44:30 GMT
Author: ajith
Date: Tue Feb 22 06:44:24 2005
New Revision: 154854

URL: http://svn.apache.org/viewcvs?view=rev&rev=154854
Log:
Adding the interop client and the test code

Added:
    webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java
    webservices/axis/trunk/java/modules/samples/src/jsp/
    webservices/axis/trunk/java/modules/samples/src/test/interop/
    webservices/axis/trunk/java/modules/samples/src/test/interop/doclit/
    webservices/axis/trunk/java/modules/samples/src/test/interop/doclit/InteropStubTest.java
Modified:
    webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/SOAPStructEncoder.java
    webservices/axis/trunk/java/modules/samples/src/java/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java

Added: webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java?view=auto&rev=154854
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java Tue
Feb 22 06:44:24 2005
@@ -0,0 +1,202 @@
+package interop.doclit;
+
+import org.apache.axis.addressing.AddressingConstants;
+import org.apache.axis.addressing.EndpointReference;
+import org.apache.axis.clientapi.Call;
+import org.apache.axis.engine.AxisFault;
+import org.apache.axis.om.OMElement;
+import org.apache.axis.om.OMFactory;
+import org.apache.axis.om.OMNamespace;
+import org.apache.axis.om.OMText;
+import org.apache.axis.om.SOAPBody;
+import org.apache.axis.om.SOAPEnvelope;
+import org.apache.axis.testUtils.SimpleTypeEncodingUtils;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+/*
+* 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.
+*/
+public class InteropStub {
+
+    private static final String INTEROP_NS_URI = "http://soapinterop.org/xsd";
+    private static final String INTEROP_PREFIX = "itop";
+
+    private OMFactory factory ;
+    //private XMLOutputFactory outputFactory;
+    private OMNamespace interopNS;
+    private String endpointURL;
+    private String SOAPAction;
+
+    public String getSOAPAction() {
+        return SOAPAction;
+    }
+
+    public void setSOAPAction(String SOAPAction) {
+        this.SOAPAction = SOAPAction;
+    }
+
+
+    public InteropStub(String endpointURL) {
+        this.endpointURL = endpointURL;
+        factory= OMFactory.newInstance();
+
+        //outputFactory = XMLOutputFactory.newInstance();
+        this.interopNS = this.factory.createOMNamespace(INTEROP_NS_URI,INTEROP_PREFIX);
+
+    }
+
+    private SOAPEnvelope getEmptyEnvelop(){
+        return factory.getDefaultEnvelope();
+    }
+
+    public SOAPStruct echoStruct(SOAPStruct inputEchoStruct){
+        try{
+
+            OMElement echoStructElementNode = factory.createOMElement("echoStructParam",interopNS);
+
+            OMElement echoStructVarFloatElement = factory.createOMElement("varFloat",interopNS);
+            echoStructVarFloatElement.addChild(factory.createText(inputEchoStruct.getVarFloat()
+""));
+            echoStructElementNode.addChild(echoStructVarFloatElement);
+
+            OMElement echoStructVarIntElementNode = factory.createOMElement("varInt",interopNS);
+            echoStructVarIntElementNode.addChild(factory.createText(inputEchoStruct.getVarInt()
+""));
+            echoStructElementNode.addChild(echoStructVarIntElementNode);
+
+            OMElement echoStructVarStringElementNode = factory.createOMElement("varString",interopNS);
+            echoStructVarStringElementNode.addChild(factory.createText(inputEchoStruct.getVarString()));
+            echoStructElementNode.addChild(echoStructVarStringElementNode);
+
+            SOAPEnvelope sendEnvelope = getEmptyEnvelop();
+            sendEnvelope.getBody().addChild(echoStructElementNode);
+
+            SOAPEnvelope returnEnvelope = getSyncResult(sendEnvelope);
+
+            SOAPBody SOAPBody = returnEnvelope.getBody();
+            if (SOAPBody.hasFault()){
+                throw new AxisFault("SOAP Fault",SOAPBody.getFault().getException());
+            }
+
+            OMElement elt = (OMElement)SOAPBody.getChildWithName(new QName(INTEROP_NS_URI,"echoStructReturn"));
+            if (elt==null){
+                throw new AxisFault("Return element not found");
+            }
+
+
+            XMLStreamReader pullParser = elt.getPullParser(false);
+            pullParser.next();
+            SOAPStruct soapStructure = (SOAPStruct)new SOAPStructEncoder().deSerialize(pullParser);
+
+            return soapStructure;
+
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return null;
+
+
+    }
+
+
+    public String[] echoStringArray(String[] input){
+        try {
+
+            OMElement echoStringArrayParamElementNode = factory.createOMElement("echoStringArrayParam",interopNS);
+            OMElement echoStringArrayElement;
+            for (int i = 0; i < input.length; i++) {
+                echoStringArrayElement = factory.createOMElement("string",interopNS);
+                echoStringArrayParamElementNode.addChild(echoStringArrayElement);
+                echoStringArrayElement.addChild(factory.createText(input[i]));
+            }
+
+            SOAPEnvelope sendEnvelope = getEmptyEnvelop();
+            sendEnvelope.getBody().addChild(echoStringArrayParamElementNode);
+
+            SOAPEnvelope returnEnvelope = getSyncResult(sendEnvelope);
+
+
+            SOAPBody SOAPBody = returnEnvelope.getBody();
+            if (SOAPBody.hasFault()){
+                throw new AxisFault("SOAP Fault",SOAPBody.getFault().getException());
+            }
+
+            OMElement elt = (OMElement)SOAPBody.getChildWithName(new QName(INTEROP_NS_URI,"echoStringArrayReturn"));
+            if (elt==null){
+                throw new AxisFault("Return element not found");
+            }
+
+            return SimpleTypeEncodingUtils.deserializeStringArray(elt.getPullParser(true));
+
+
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    public String echoString(String input){
+        try {
+
+            OMElement echoStringParamElementNode = factory.createOMElement("echoStringParam",interopNS);
+            OMText echoStringTextNode = factory.createText(echoStringParamElementNode,input);
+            echoStringParamElementNode.addChild(echoStringTextNode);
+
+            SOAPEnvelope sendEnvelope = getEmptyEnvelop();
+            sendEnvelope.getBody().addChild(echoStringParamElementNode);
+
+            SOAPEnvelope returnEnvelope = getSyncResult(sendEnvelope);
+
+            SOAPBody SOAPBody = returnEnvelope.getBody();
+            if (SOAPBody.hasFault()){
+                throw new AxisFault("SOAP Fault",SOAPBody.getFault().getException());
+            }
+
+            OMElement elt = (OMElement)SOAPBody.getChildWithName(new QName(INTEROP_NS_URI,"echoStringReturn"));
+            if (elt==null){
+                throw new AxisFault("Return element not found");
+            }
+
+            return elt.getFirstChild().getValue();
+
+        } catch (AxisFault axisFault) {
+            axisFault.printStackTrace();
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+
+    private SOAPEnvelope getSyncResult(SOAPEnvelope env) throws AxisFault {
+        EndpointReference targetEPR = new EndpointReference(AddressingConstants.WSA_TO,
+                this.endpointURL);
+        Call call = new Call();
+        call.setTo(targetEPR);
+        if (SOAPAction!=null){
+            call.setAction(SOAPAction);
+        }
+        return call.sendReceive(env);
+
+    }
+
+
+}

Modified: webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/SOAPStructEncoder.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/SOAPStructEncoder.java?view=diff&r1=154853&r2=154854
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/SOAPStructEncoder.java
(original)
+++ webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/SOAPStructEncoder.java
Tue Feb 22 06:44:24 2005
@@ -15,16 +15,16 @@
  */
  
 package interop.doclit;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-
 import org.apache.axis.engine.AxisFault;
 import org.apache.axis.om.OMException;
 import org.apache.axis.testUtils.Encoder;
 import org.apache.axis.testUtils.SimpleTypeEncodingUtils;
 import org.xml.sax.ContentHandler;
 
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
 public class SOAPStructEncoder implements Encoder {
     
     public static final String URI = "http://soapinterop.org/xsd";
@@ -60,7 +60,7 @@
                     }else if(VAR_FLOAT.equals(localName)){
                         struct.setVarFloat(SimpleTypeEncodingUtils.deserializeFloat(xpp));
                               
                     }else{
-                        throw new AxisFault("Unknown elemnt "+ localName);              
     
+                        throw new AxisFault("Unknown element "+ localName);
                     }
                 }
                 if (XMLStreamConstants.END_ELEMENT == event) {

Modified: webservices/axis/trunk/java/modules/samples/src/java/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/java/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java?view=diff&r1=154853&r2=154854
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/java/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java
(original)
+++ webservices/axis/trunk/java/modules/samples/src/java/org/apache/axis/testUtils/SimpleTypeEncodingUtils.java
Tue Feb 22 06:44:24 2005
@@ -96,11 +96,13 @@
                 event = xpp.next();
             }
             event = xpp.next();
+            System.out.println("Element name    ----" + xpp.getLocalName());
             while (XMLStreamConstants.END_ELEMENT != event) {
                 if (XMLStreamConstants.CHARACTERS == event && !xpp.isWhiteSpace())
{
                     value = xpp.getText();
                 }
                 event = xpp.next();
+                System.out.println("Element name    ----" + xpp.getLocalName());
             }
         } catch (XMLStreamException e) {
             throw AxisFault.makeFault(e);

Added: webservices/axis/trunk/java/modules/samples/src/test/interop/doclit/InteropStubTest.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/test/interop/doclit/InteropStubTest.java?view=auto&rev=154854
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/test/interop/doclit/InteropStubTest.java
(added)
+++ webservices/axis/trunk/java/modules/samples/src/test/interop/doclit/InteropStubTest.java
Tue Feb 22 06:44:24 2005
@@ -0,0 +1,84 @@
+package interop.doclit;
+
+import junit.framework.TestCase;
+
+/*
+* 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.
+*
+*
+*/
+public class InteropStubTest extends TestCase{
+
+//    private static String ASP_NET_ENDPOINT = "http://mssoapinterop.org/asmx/wsdl/InteropTestDocLit.asmx";
+    private static String ASP_NET_ENDPOINT = "http://localhost:8081/asmx/wsdl/InteropTestDocLit.asmx";
+    private static String OPENLINK_ENDPOINT = "http://demo.openlinksw.com/r3/DocLit";
+
+
+    private void testEchoString(String endpoint,String soapAction){
+        InteropStub stub = new InteropStub(endpoint);
+        stub.setSOAPAction(soapAction==null?"":soapAction);
+        String echoValue = "Hello World";
+        assertEquals(stub.echoString(echoValue),echoValue);
+    }
+    private void testEchoStringArray(String endpoint,String soapAction){
+        InteropStub stub = new InteropStub(endpoint);
+        stub.setSOAPAction(soapAction==null?"":soapAction);
+        String[] echoValueArray = new String[20];
+        for (int i = 0; i < echoValueArray.length; i++) {
+            echoValueArray[i]="s"+i;
+        }
+        String[] returnEchoArray = stub.echoStringArray(echoValueArray);
+
+        //the elements are added in reverse order. So comparison must be
+        //inverted
+        int length = returnEchoArray.length;
+        for (int i = 0; i < length; i++) {
+            assertEquals(returnEchoArray[i],echoValueArray[length-1-i]);
+        }
+    }
+
+    private void testEchoStruct(String endpoint,String soapAction){
+        InteropStub stub = new InteropStub(endpoint);
+        stub.setSOAPAction(soapAction==null?"":soapAction);
+
+        SOAPStruct structToSend = new SOAPStruct();
+        structToSend.setVarFloat(new Float(22.22).floatValue());
+        structToSend.setVarInt(12);
+        structToSend.setVarString("Hello");
+
+        SOAPStruct returnStruct = stub.echoStruct(structToSend);
+
+        assertTrue(returnStruct.equals(structToSend));
+
+    }
+
+    public void testASPEndPoint(){
+//       testEchoString(ASP_NET_ENDPOINT,"\"http://soapinterop.org/\"");
+//        testEchoStringArray(ASP_NET_ENDPOINT,"\"http://soapinterop.org/\"");
+        testEchoStruct(ASP_NET_ENDPOINT,"\"http://soapinterop.org/\"");
+
+    }
+    public void testOpenlinkEndPoint(){
+        testEchoString(OPENLINK_ENDPOINT,null);
+
+    }
+
+//    public static void main(String[] args) {
+//        String x = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header></soapenv:Header><soapenv:Body><itop:echoStringParam
xmlns:itop=\"http://soapinterop.org/xsd\">Hello World</itop:echoStringParam></soapenv:Body></soapenv:Envelope>";
+//
+//        System.out.println(x);
+//        System.out.println(x.getBytes().length);
+//    }
+}



Mime
View raw message