You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ve...@apache.org on 2005/04/25 12:02:00 UTC

cvs commit: ws-axis/java/samples/message build.xml MessageService.java deploy.wsdd TestMsg.java

venkat      2005/04/25 03:02:00

  Modified:    java/samples/message build.xml MessageService.java
                        deploy.wsdd TestMsg.java
  Log:
  Test case for the fix AXIS-1725. Added a new test case for passing javax.xml.soap.SOAPEnvelope.
  
  Revision  Changes    Path
  1.8       +21 -3     ws-axis/java/samples/message/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/samples/message/build.xml,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- build.xml	2 Jun 2004 17:05:15 -0000	1.7
  +++ build.xml	25 Apr 2005 10:02:00 -0000	1.8
  @@ -42,6 +42,11 @@
           &taskdefs_post_compile;
   	&targets;
   
  +  <taskdef name="axis-admin" classname="org.apache.axis.tools.ant.axis.AdminClientTask"
  +    loaderref="axis" >
  +        <classpath refid="classpath"/>
  +  </taskdef>
  +
   <target name="clean"/>
   
   <target name="copy" depends="setenv"/>
  @@ -57,10 +62,23 @@
     </javac>
   </target>
   
  -<target name="deploy"/>
  +<target name="deploy">
  +		<axis-admin xmlfile="${basedir}/deploy.wsdd"/>
  +</target>
  +
  +
  +<target name="run">
   
  -<target name="run"/>
  +			<java classname="samples.message.TestMsg"	fork="yes">
  +				<classpath>
  +						<path refid="classpath"/>
  +				</classpath>
  +			</java>
   
  -<target name="undeploy"/>
  +</target>
  +
  +<target name="undeploy">
  +		<axis-admin xmlfile="${basedir}/undeploy.wsdd"/>
  +</target>
   
   </project>
  
  
  
  1.8       +20 -5     ws-axis/java/samples/message/MessageService.java
  
  Index: MessageService.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/samples/message/MessageService.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- MessageService.java	25 Feb 2004 14:02:23 -0000	1.7
  +++ MessageService.java	25 Apr 2005 10:02:00 -0000	1.8
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002-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.
  @@ -17,6 +17,12 @@
   package samples.message ;
   
   import org.w3c.dom.Element;
  +import javax.xml.soap.SOAPEnvelope;
  +import javax.xml.soap.Name;
  +import javax.xml.soap.SOAPBody;
  +import javax.xml.soap.SOAPBodyElement;
  +import javax.xml.soap.SOAPHeader;
  +import javax.xml.soap.SOAPElement;
   
   /**
    * Simple message-style service sample.
  @@ -24,11 +30,20 @@
   public class MessageService {
       /**
        * Service method, which simply echoes back any XML it receives.
  -     * 
  +     *
        * @param elems an array of DOM Elements, one for each SOAP body element
        * @return an array of DOM Elements to be sent in the response body
  -     */ 
  +     */
       public Element[] echoElements(Element [] elems) {
           return elems;
       }
  +
  +    public void process(SOAPEnvelope req, SOAPEnvelope resp) throws javax.xml.soap.SOAPException {
  +    	SOAPBody body = resp.getBody();
  +    	Name ns0 =  resp.createName("TestNS0", "ns0", "http://example.com");
  +    	Name ns1 =  resp.createName("TestNS1", "ns1", "http://example.com");
  +    	SOAPElement bodyElmnt = body.addBodyElement(ns0);
  +    	SOAPElement el = bodyElmnt.addChildElement(ns1);
  +    	el.addTextNode("TEST RESPONSE");
  +    }
   }
  
  
  
  1.4       +1 -1      ws-axis/java/samples/message/deploy.wsdd
  
  Index: deploy.wsdd
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/samples/message/deploy.wsdd,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- deploy.wsdd	30 Sep 2002 03:36:06 -0000	1.3
  +++ deploy.wsdd	25 Apr 2005 10:02:00 -0000	1.4
  @@ -4,6 +4,6 @@
     <!-- note that either style="message" OR provider="java:MSG" both work -->
     <service name="MessageService" style="message">
       <parameter name="className" value="samples.message.MessageService" />
  -    <parameter name="allowedMethods" value="echoElements" />
  +    <parameter name="allowedMethods" value="echoElements process" />
     </service>
   </deployment>
  
  
  
  1.7       +63 -11    ws-axis/java/samples/message/TestMsg.java
  
  Index: TestMsg.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/samples/message/TestMsg.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestMsg.java	25 Feb 2004 14:02:23 -0000	1.6
  +++ TestMsg.java	25 Apr 2005 10:02:00 -0000	1.7
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2002-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.
  @@ -30,9 +30,19 @@
   import java.net.URL;
   import java.util.Vector;
   
  +import java.io.ByteArrayInputStream;
  +import java.io.ByteArrayOutputStream;
  +import javax.xml.soap.MessageFactory;
  +import javax.xml.soap.SOAPEnvelope;
  +import javax.xml.soap.SOAPMessage;
  +import javax.xml.soap.SOAPPart;
  +import javax.xml.soap.MimeHeaders;
  +import javax.xml.namespace.QName;
  +import org.apache.axis.description.OperationDesc;
  +
   /**
    * Simple test driver for our message service.
  - */ 
  + */
   public class TestMsg {
       public String doit(String[] args) throws Exception {
           Options opts = new Options(args);
  @@ -44,19 +54,19 @@
           call.setTargetEndpointAddress( new URL(opts.getURL()) );
           SOAPBodyElement[] input = new SOAPBodyElement[3];
   
  -        input[0] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo", 
  +        input[0] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo",
                                                                   "e1", "Hello"));
  -        input[1] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo", 
  +        input[1] = new SOAPBodyElement(XMLUtils.StringToElement("urn:foo",
                                                                   "e1", "World"));
   
           DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  -        Document doc            = builder.newDocument();   
  +        Document doc            = builder.newDocument();
           Element cdataElem       = doc.createElementNS("urn:foo", "e3");
  -        CDATASection cdata      = doc.createCDATASection("Text with\n\tImportant  <b>  whitespace </b> and tags! ");	    
  +        CDATASection cdata      = doc.createCDATASection("Text with\n\tImportant  <b>  whitespace </b> and tags! ");
           cdataElem.appendChild(cdata);
  -		
  +
           input[2] = new SOAPBodyElement(cdataElem);
  -        
  +
           Vector          elems = (Vector) call.invoke( input );
           SOAPBodyElement elem  = null ;
           Element         e     = null ;
  @@ -73,12 +83,54 @@
           elem = (SOAPBodyElement) elems.get(2);
           e    = elem.getAsDOM();
           str = str + "Res elem[2]=" + XMLUtils.ElementToString(e);
  -        
  +
           return( str );
       }
   
  +
  +    public void testEnvelope(String[] args) throws Exception {
  +        String xmlString =
  +            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
  +            "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"\n" +
  +            "                   xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
  +            "                   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" +
  +            " <soapenv:Header>\n" +
  +            "  <shw:Hello xmlns:shw=\"http://localhost:8080/axis/services/MessageService\">\n" +
  +            "    <shw:Myname>Tony</shw:Myname>\n" +
  +            "  </shw:Hello>\n" +
  +            " </soapenv:Header>\n" +
  +            " <soapenv:Body>\n" +
  +            "  <shw:process xmlns:shw=\"http://message.samples\">\n" +
  +            "    <shw:City>GENT</shw:City>\n" +
  +            "  </shw:process>\n" +
  +            " </soapenv:Body>\n" +
  +            "</soapenv:Envelope>";
  +
  +        MessageFactory mf = MessageFactory.newInstance();
  +        SOAPMessage smsg =
  +                mf.createMessage(new MimeHeaders(), new ByteArrayInputStream(xmlString.getBytes()));
  +        SOAPPart sp = smsg.getSOAPPart();
  +        SOAPEnvelope se = (SOAPEnvelope)sp.getEnvelope();
  +
  +        Options opts = new Options(args);
  +        opts.setDefaultURL("http://localhost:8080/axis/services/MessageService");
  +
  +        Service  service = new Service();
  +        Call     call    = (Call) service.createCall();
  +
  +        OperationDesc operation = new OperationDesc();
  +        operation.setName("process");
  +        operation.setStyle(org.apache.axis.constants.Style.MESSAGE);
  +        call.setOperation(operation);
  +
  +        call.setTargetEndpointAddress( new URL(opts.getURL()) );
  +        call.invoke((org.apache.axis.message.SOAPEnvelope) se);
  +    }
  +
       public static void main(String[] args) throws Exception {
           String res = (new TestMsg()).doit(args);
           System.out.println(res);
  +
  +        (new TestMsg()).testEnvelope(args);
       }
   }