You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by aj...@apache.org on 2005/02/22 17:37:54 UTC

svn commit: r154874 - webservices/axis/trunk/java/modules/samples/src/java/interop/doclit webservices/axis/trunk/java/modules/samples/src/java/interop/util webservices/axis/trunk/java/modules/samples/src/jsp

Author: ajith
Date: Tue Feb 22 08:37:52 2005
New Revision: 154874

URL: http://svn.apache.org/viewcvs?view=rev&rev=154874
Log:
Improving the web based interop test client

Added:
    webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropRequestHandler.java
    webservices/axis/trunk/java/modules/samples/src/java/interop/util/Constants.java
Modified:
    webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java
    webservices/axis/trunk/java/modules/samples/src/java/interop/util/InteropTO.java
    webservices/axis/trunk/java/modules/samples/src/jsp/index.jsp

Added: webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropRequestHandler.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropRequestHandler.java?view=auto&rev=154874
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropRequestHandler.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropRequestHandler.java Tue Feb 22 08:37:52 2005
@@ -0,0 +1,104 @@
+package interop.doclit;
+
+import interop.util.InteropTO;
+import interop.util.Constants;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamException;
+import java.io.ByteArrayOutputStream;
+
+import org.apache.axis.om.SOAPEnvelope;
+
+/*
+* 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 InteropRequestHandler {
+
+    private  XMLOutputFactory writerFactory = XMLOutputFactory.newInstance();
+
+
+    public void handleInteropRequest(InteropTO interopTransferTo) throws Exception{
+        int requestType = interopTransferTo.getType();
+        if (requestType==Constants.InteropConstants.ECHO_STRING_SERVICE){
+            interopEchoString(interopTransferTo);
+        }else if (requestType==Constants.InteropConstants.ECHO_STRUCT_SERVICE){
+            interopEchoStruct(interopTransferTo);
+        }else if (requestType==Constants.InteropConstants.ECHO_STRING_ARRAY_SERVICE){
+           interopEchoStringArray(interopTransferTo);
+        }
+    }
+
+    private void interopEchoStruct(InteropTO transferTo) throws Exception{
+            String endpointURL = transferTo.getURL();
+            String SOAPAction = transferTo.getSOAPAction();
+
+            InteropStub interopStub = new InteropStub(endpointURL);
+            interopStub.setSOAPAction(SOAPAction);
+            //call method
+            SOAPStruct soapStruct = new SOAPStruct();
+            soapStruct.setVarFloat(transferTo.getStructfloat());
+            soapStruct.setVarInt(transferTo.getStructint());
+            soapStruct.setVarString(transferTo.getStructString());
+            interopStub.echoStruct(soapStruct);
+            //update the envelopes
+            updateEnvelopes(interopStub,transferTo);
+
+        }
+
+
+     private void interopEchoStringArray(InteropTO transferTo) throws Exception{
+        String endpointURL = transferTo.getURL();
+        String SOAPAction = transferTo.getSOAPAction();
+
+        InteropStub interopStub = new InteropStub(endpointURL);
+        interopStub.setSOAPAction(SOAPAction);
+        //call method
+        interopStub.echoStringArray(transferTo.getArraValue());
+        //update the envelopes
+        updateEnvelopes(interopStub,transferTo);
+
+    }
+
+    private void interopEchoString(InteropTO transferTo) throws Exception{
+        String endpointURL = transferTo.getURL();
+        String SOAPAction = transferTo.getSOAPAction();
+
+        InteropStub interopStub = new InteropStub(endpointURL);
+        interopStub.setSOAPAction(SOAPAction);
+        //call method
+        interopStub.echoString(transferTo.getStringValue());
+        //update the envelopes
+        updateEnvelopes(interopStub,transferTo);
+
+    }
+
+    private void updateEnvelopes(InteropStub stub,InteropTO transferTo) throws Exception{
+        transferTo.setRequest(writeStringFromEnvelope(stub.getSentEnvelope()));
+        transferTo.setResponse(writeStringFromEnvelope(stub.getRecvdEnvelope()));
+
+    }
+
+    private String writeStringFromEnvelope(SOAPEnvelope env) throws XMLStreamException {
+        ByteArrayOutputStream output = new ByteArrayOutputStream(100);
+        XMLStreamWriter writer = writerFactory.createXMLStreamWriter(output);
+        env.serialize(writer, true);
+        writer.flush();
+        return new String(output.toByteArray());
+    }
+
+}

Modified: 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=diff&r1=154873&r2=154874
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/java/interop/doclit/InteropStub.java Tue Feb 22 08:37:52 2005
@@ -41,6 +41,21 @@
     private String endpointURL;
     private String SOAPAction;
 
+    //these are special attributes to provide the input and output SOAP envelopes
+    private SOAPEnvelope sentEnvelope;
+    private SOAPEnvelope recvdEnvelope;
+
+    public SOAPEnvelope getSentEnvelope() {
+        return sentEnvelope;
+    }
+
+
+    public SOAPEnvelope getRecvdEnvelope() {
+        return recvdEnvelope;
+    }
+
+
+
     public String getSOAPAction() {
         return SOAPAction;
     }
@@ -83,7 +98,9 @@
             SOAPEnvelope sendEnvelope = getEmptyEnvelop();
             sendEnvelope.getBody().addChild(echoStructElementNode);
 
+            this.sentEnvelope = sendEnvelope;
             SOAPEnvelope returnEnvelope = getSyncResult(sendEnvelope);
+            this.recvdEnvelope = returnEnvelope;
 
             SOAPBody SOAPBody = returnEnvelope.getBody();
             if (SOAPBody.hasFault()){
@@ -128,7 +145,9 @@
             SOAPEnvelope sendEnvelope = getEmptyEnvelop();
             sendEnvelope.getBody().addChild(echoStringArrayParamElementNode);
 
+            this.sentEnvelope = sendEnvelope;
             SOAPEnvelope returnEnvelope = getSyncResult(sendEnvelope);
+            this.recvdEnvelope = returnEnvelope;
 
 
             SOAPBody SOAPBody = returnEnvelope.getBody();
@@ -162,7 +181,9 @@
             SOAPEnvelope sendEnvelope = getEmptyEnvelop();
             sendEnvelope.getBody().addChild(echoStringParamElementNode);
 
+            this.sentEnvelope = sendEnvelope;
             SOAPEnvelope returnEnvelope = getSyncResult(sendEnvelope);
+            this.recvdEnvelope = returnEnvelope;
 
             SOAPBody SOAPBody = returnEnvelope.getBody();
             if (SOAPBody.hasFault()){

Added: webservices/axis/trunk/java/modules/samples/src/java/interop/util/Constants.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/java/interop/util/Constants.java?view=auto&rev=154874
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/java/interop/util/Constants.java (added)
+++ webservices/axis/trunk/java/modules/samples/src/java/interop/util/Constants.java Tue Feb 22 08:37:52 2005
@@ -0,0 +1,27 @@
+package interop.util;
+
+/*
+ * 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 Constants {
+    public class InteropConstants{
+        public static final int ECHO_STRING_SERVICE=0;
+        public static final int ECHO_STRING_ARRAY_SERVICE=1;
+        public static final int ECHO_STRUCT_SERVICE=2;
+
+    }
+}

Modified: webservices/axis/trunk/java/modules/samples/src/java/interop/util/InteropTO.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/java/interop/util/InteropTO.java?view=diff&r1=154873&r2=154874
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/java/interop/util/InteropTO.java (original)
+++ webservices/axis/trunk/java/modules/samples/src/java/interop/util/InteropTO.java Tue Feb 22 08:37:52 2005
@@ -1,4 +1,4 @@
-package org.apache.axis.interop.util;
+package interop.util;
 
 /**
  * Created by IntelliJ IDEA.

Modified: webservices/axis/trunk/java/modules/samples/src/jsp/index.jsp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/modules/samples/src/jsp/index.jsp?view=diff&r1=154873&r2=154874
==============================================================================
--- webservices/axis/trunk/java/modules/samples/src/jsp/index.jsp (original)
+++ webservices/axis/trunk/java/modules/samples/src/jsp/index.jsp Tue Feb 22 08:37:52 2005
@@ -1,5 +1,7 @@
+<%@ page import="interop.util.Constants,
+                 interop.doclit.InteropRequestHandler"%>
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
-<jsp:useBean id="interopBean" scope="request" class="org.apache.axis.interop.util.InteropTO" />
+<jsp:useBean id="interopBean" scope="request" class="interop.util.InteropTO" />
 <jsp:setProperty name="interopBean" property="*" />
 
 
@@ -55,55 +57,35 @@
     <%
       if (request.getParameter("submit") != null) {
           int type = interopBean.getType();
+          System.out.println("type = " + type);
           switch(type){
-              case 1: {
+              case Constants.InteropConstants.ECHO_STRING_SERVICE: {
                    interopBean.setStringValue((String)request.getParameter("StringValue"));
                   break;
               }
-              case 2: {
+              case Constants.InteropConstants.ECHO_STRING_ARRAY_SERVICE: {
                   String [] values = new String[10];
-                  for(int i =1 ; i<= 10 ; i++){
-                     values[i] =(String)request.getParameter("arryValue" + i);
+                  for(int i =0 ; i< 9 ; i++){
+                     values[i] =(String)request.getParameter("arryValue" + (i+1));
+                      System.out.println("values[i] = " + values[i]);
                   }
                   interopBean.setArraValue(values);
                   break;
               }
-              case 3 : {
+              case Constants.InteropConstants.ECHO_STRUCT_SERVICE : {
                   interopBean.setStructString((String)request.getParameter("structValue1"));
                   interopBean.setStructint(Integer.parseInt(request.getParameter("structValue2")));
                   interopBean.setStructfloat(Float.parseFloat(request.getParameter("structValue3")));
                   break;
               }
           }
-          interopBean.setRequest(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
-"   <soapenv:Header></soapenv:Header>\n" +
-"   <soapenv:Body>\n" +
-"      <itop:echoStructParam xmlns:itop=\"http://soapinterop.org/xsd\">\n" +
-"         <itop:varString>Hello</itop:varString>\n" +
-"         <itop:varInt>12</itop:varInt>\n" +
-"         <itop:varFloat>22.22</itop:varFloat>\n" +
-"      </itop:echoStructParam>\n" +
-"   </soapenv:Body></soapenv:Envelope>");
-          interopBean.setResponse(" <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
-"   <soapenv:Header></soapenv:Header>\n" +
-"   <soapenv:Body>\n" +
-"      <itop:echoStructParam xmlns:itop=\"http://soapinterop.org/xsd\">\n" +
-"         <itop:varString>Hello</itop:varString>\n" +
-"         <itop:varInt>12</itop:varInt>\n" +
-"         <itop:varFloat>22.22</itop:varFloat>\n" +
-"      </itop:echoStructParam>\n" +
-"   </soapenv:Body></soapenv:Envelope>");
-          interopBean.printMe();
+        new InteropRequestHandler().handleInteropRequest(interopBean);
       }
     %>
 
 
-
-
-
-
-
         <jsp:include page="include/header.inc"></jsp:include>
+
        	<h3>Welcome to Axis interop testing.</h3><br/>
         <br>
         <form method="post" name="InteropTesting" action="index.jsp">
@@ -124,18 +106,19 @@
           <tr>
           <td></td>
           <td>
-              <input type="radio" name="type" value="1"  onclick="displayStringRow();hideStringArrayRow();hideStructRow();"  checked>Echo String</input>
+              <input type="radio" name="type" value="<%=Constants.InteropConstants.ECHO_STRING_SERVICE%>"  onclick="displayStringRow();hideStringArrayRow();hideStructRow();"  checked>Echo String</input>
+
           </td>
           </tr>
            <tr>
            <td></td>
             <td>
-              <input type="radio" name="type" onclick="hideStringRow(); displayStringArrayRow();hideStructRow();"  value="2">Echo String Array</input>
+              <input type="radio" name="type" onclick="hideStringRow(); displayStringArrayRow();hideStructRow();"  value="<%=Constants.InteropConstants.ECHO_STRING_ARRAY_SERVICE%>">Echo String Array</input>
           </td>
           </tr>
            <tr><td></td>
            <td>
-              <input type="radio" name="type" onclick="hideStringRow();hideStringArrayRow();displayStructRow();" value="3">Echo strct</input>
+              <input type="radio" name="type" onclick="hideStringRow();hideStringArrayRow();displayStructRow();" value="<%=Constants.InteropConstants.ECHO_STRUCT_SERVICE%>">Echo Struct</input>
           </td>
           </tr>
           </table>