axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/client Stub.java
Date Thu, 07 Aug 2003 21:38:22 GMT
tomj        2003/08/07 14:38:22

  Modified:    java/src/org/apache/axis/client Stub.java
  Added:       java/test/wsdl/stubheaders build.xml StubHeaderImpl.java
                        stubheaders.wsdl StubHeaderServiceTestCase.java
  Log:
  Add back in the ability to get response SOAP headers via the Stub.
  Add a test case to make sure it works.
  
  This was removed in April 2003 to fix the problem where response headers
  would be placed in the same place as request headers.  The solution to
  that went (way) too far, and in Axis 1.1, you can only get response headers
  if you have the Call object, which you can get from the Service object, which
  you *can't* get from the Stub object.
  
  Solution is to add 2 new Stub APIs:
      public SOAPHeaderElement[] getResponseHeaders()
      public SOAPHeaderElement getResponseHeader(String namespace, String partName)
  
  This makes it explicit that the response headers are separate from
   the request headers.
  
  Revision  Changes    Path
  1.1                  xml-axis/java/test/wsdl/stubheaders/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" ?>
  <!DOCTYPE project [
          <!ENTITY properties SYSTEM "file:../../../xmls/properties.xml">
          <!ENTITY paths  SYSTEM "file:../../../xmls/path_refs.xml">
          <!ENTITY taskdefs SYSTEM "file:../../../xmls/taskdefs.xml">
          <!ENTITY taskdefs_post_compile SYSTEM "file:../../../xmls/taskdefs_post_compile.xml">
          <!ENTITY targets SYSTEM "file:../../../xmls/targets.xml">
  ]>
  
  <!-- ===================================================================
  <description>
     Test/Sample Component file for Axis
  
  Notes:
     This is a build file for use with the Jakarta Ant build tool.
  
  Prerequisites:
  
     jakarta-ant from http://jakarta.apache.org
  
  Build Instructions:
     To compile
          ant compile
     To execute
          ant run
  
  Author:
    Matt Seibert mseibert@us.ibm.com
  
  Copyright:
    Copyright (c) 2002-2003 Apache Software Foundation.
  </description>
  ==================================================================== -->
  
  <project default="compile">
  
  <property name="axis.home" location="../../.." />
  <property name="componentName" value="test/wsdl/stubheaders" />
          &properties;
          &paths;
          &taskdefs;
          &taskdefs_post_compile;
          &targets;
  
  
  <target name="clean">
      <echo message="Removing ${build.dir}/classes/${componentName} and ${build.dir}/work/${componentName}"
/>
      <delete dir="${build.dir}/classes/${componentName}"/>
      <delete dir="${build.dir}/work/${componentName}"/>
  </target>
  
  <target name="copy" depends="setenv"/>
  
  <target name="compile" depends="copy">
    <echo message="Compiling test.wsdl.stubheaders"/>
      <!-- This tests holders for complextype Bug:10247 -->
      <wsdl2java url="${axis.home}/test/wsdl/stubheaders/stubheaders.wsdl"
                 output="${axis.home}/build/work"
                 serverSide="yes"
                 testcase="yes">
          <mapping namespace="http://echo.services" package="test.wsdl.stubheaders"/>
      </wsdl2java>
  
      <copy todir="${build.dir}/work/test/wsdl/stubheaders" overwrite="yes">
        <fileset dir="${axis.home}/test/wsdl/stubheaders">
          <include name="*TestCase.java"/>
          <include name="*Impl.java"/>
        </fileset>
      </copy>
  
      <javac srcdir="${build.dir}/work" destdir="${build.dest}" fork="${javac.fork}"
             debug="${debug}">
        <classpath refid="classpath" />
        <include name="test/wsdl/stubheaders/*.java" />
      </javac>
  </target>
  
  <target name="run" >
    <antcall target="execute-Component" />
  </target>
  
  </project>
  
  
  
  1.1                  xml-axis/java/test/wsdl/stubheaders/StubHeaderImpl.java
  
  Index: StubHeaderImpl.java
  ===================================================================
  /**
   * StubHeaderImpl.java
   *
   * Test implimentation.
   * Make sure the service sees a SOAP header added by the Sub API.
   * Set a different header in the response to the test can verify it.
   */
  
  package test.wsdl.stubheaders;
  
  import org.apache.axis.MessageContext;
  import org.apache.axis.message.SOAPEnvelope;
  import org.apache.axis.message.SOAPHeaderElement;
  
  public class StubHeaderImpl implements test.wsdl.stubheaders.StubHeaderInterface {
  
      public java.lang.String echo(java.lang.String in) throws java.rmi.RemoteException {
          String ret = null;
          MessageContext mc = MessageContext.getCurrentContext();
  
          // Verify the existence of in the input header
          SOAPEnvelope env = mc.getRequestMessage().getSOAPEnvelope();
          SOAPHeaderElement header = env.getHeaderByName("http://test.org/inputheader", "headerin");
          if (header != null)
          {
              ret = header.getObjectValue().toString();
          }
  
          // add a different output header to the response
          env = mc.getResponseMessage().getSOAPEnvelope();
          SOAPHeaderElement hdr =
                  new SOAPHeaderElement("http://test.org/outputheader", "headerout", "outputvalue");
          env.addHeader(hdr);
  
          // just return the input header, so test can validate it
          return ret;
      }
  
  }
  
  
  
  1.1                  xml-axis/java/test/wsdl/stubheaders/stubheaders.wsdl
  
  Index: stubheaders.wsdl
  ===================================================================
  <?xml version="1.0" encoding="UTF-8" ?> 
  <wsdl:definitions targetNamespace="http://echo.services"
      xmlns:intf="http://echo.services"
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
      xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
      xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <wsdl:message name="echoRequest">
          <wsdl:part type="xsd:string" name="in" />
      </wsdl:message>
      <wsdl:message name="echoResponse">
          <wsdl:part type="xsd:string" name="out" />
      </wsdl:message>
      <wsdl:portType name="StubHeaderInterface">
          <wsdl:operation name="echo" parameterOrder="in">
              <wsdl:input message="intf:echoRequest" name="echoRequest" />
              <wsdl:output message="intf:echoResponse" name="echoResponse" />
          </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="StubHeader" type="intf:StubHeaderInterface">
          <wsdlsoap:binding style="rpc"
              transport="http://schemas.xmlsoap.org/soap/http" />
          <wsdl:operation name="echo">
              <wsdlsoap:operation soapAction="" />
              <wsdl:input name="echoRequest">
                  <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
                      namespace="http://types.echo.services" use="encoded" />
              </wsdl:input>
              <wsdl:output name="echoResponse">
                  <wsdlsoap:body namespace="http://types.echo.services" use="encoded" />
              </wsdl:output>
          </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="StubHeaderService">
          <wsdl:port binding="intf:StubHeader" name="StubHeaderService">
              <wsdlsoap:address
                  location="http://localhost:8080/axis/services/StubHeaderService" />
          </wsdl:port>
      </wsdl:service>
  </wsdl:definitions>
  
  
  
  1.1                  xml-axis/java/test/wsdl/stubheaders/StubHeaderServiceTestCase.java
  
  Index: StubHeaderServiceTestCase.java
  ===================================================================
  /**
   * StubHeaderServiceTestCase.java
   *
   * Test case. Add a SOAP header using the Stub APIs and make sure the
   * service returns a SOAP header that we can read.
   */
  
  package test.wsdl.stubheaders;
  
  import org.apache.axis.message.SOAPHeaderElement;
  
  public class StubHeaderServiceTestCase extends junit.framework.TestCase {
      public StubHeaderServiceTestCase(java.lang.String name) {
          super(name);
      }
      public void test1StubHeaderServiceEcho() throws Exception {
          StubHeaderStub binding;
          try {
              binding = (test.wsdl.stubheaders.StubHeaderStub)
                            new StubHeaderServiceLocator().getStubHeaderService();
          }
          catch (javax.xml.rpc.ServiceException jre) {
              if(jre.getLinkedCause()!=null)
                  jre.getLinkedCause().printStackTrace();
              throw new junit.framework.AssertionFailedError("JAX-RPC ServiceException caught:
" + jre);
          }
          assertNotNull("binding is null", binding);
  
          // Time out after a minute
          binding.setTimeout(60000);
  
          // Set header value via the Stub API
          binding.setHeader("http://test.org/inputheader", "headerin", "inputvalue");
  
          // Test operation
          java.lang.String value = null;
          value = binding.echo(new java.lang.String());
  
          // validate input header was echoed back
          assertEquals("Request header did not reach service", "inputvalue", value);
  
          // Check that getting the list of response headers works
          SOAPHeaderElement[] hdrs = binding.getResponseHeaders();
          assertEquals("List of response headers has the wrong number", 1, hdrs.length );
  
          // Get response header using ONLY the Stub API
          SOAPHeaderElement hdr = binding.getResponseHeader("http://test.org/outputheader",
"headerout");
          assertNotNull("Cant find header 'headerout' in response", hdr);
          assertNotNull("Header object value is NULL", hdr.getObjectValue());
          assertEquals("Response header did not arrive as expected", "outputvalue", hdr.getObjectValue());
  
          // Everything is OK
      }
  
  }
  
  
  
  1.31      +39 -1     xml-axis/java/src/org/apache/axis/client/Stub.java
  
  Index: Stub.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Stub.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- Stub.java	27 Jun 2003 17:16:25 -0000	1.30
  +++ Stub.java	7 Aug 2003 21:38:22 -0000	1.31
  @@ -356,7 +356,24 @@
           }
           return null;
       }
  -    
  +
  +    /**
  +     * Get a response header element
  +     */
  +    public SOAPHeaderElement getResponseHeader(String namespace, String partName) {
  +        try
  +        {
  +            Call lastCall = ((org.apache.axis.client.Service)service).getCall();
  +            if (lastCall == null)
  +                return null;
  +            return lastCall.getResponseMessage().getSOAPEnvelope().getHeaderByName(namespace,
partName);
  +        }
  +        catch (Exception e)
  +        {
  +            return null;
  +        }
  +    }
  +
       /**
        * Get the array of header elements
        */ 
  @@ -364,6 +381,27 @@
           SOAPHeaderElement[] array = new SOAPHeaderElement[headers.size()];
           headers.copyInto(array);
           return array;
  +    }
  +
  +    /**
  +     * Get the array of response header elements
  +     */
  +    public SOAPHeaderElement[] getResponseHeaders() {
  +        SOAPHeaderElement[] array = new SOAPHeaderElement[0];
  +        try
  +        {
  +            Call lastCall = ((org.apache.axis.client.Service)service).getCall();
  +            if (lastCall == null)
  +                return array;
  +            Vector h = lastCall.getResponseMessage().getSOAPEnvelope().getHeaders();
  +            array = new SOAPHeaderElement[h.size()];
  +            h.copyInto(array);
  +            return array;
  +        }
  +        catch (Exception e)
  +        {
  +            return array;
  +        }
       }
   
       /**
  
  
  

Mime
View raw message