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 sa...@apache.org on 2004/11/05 06:25:58 UTC

cvs commit: ws-axis/c/samples/client/session/cookie Client.cpp Total.wsdl build.sh readme.txt run.sh server-config.wsdd test.sh

samisa      2004/11/04 21:25:58

  Added:       c/samples/client/session/cookie Client.cpp Total.wsdl
                        build.sh readme.txt run.sh server-config.wsdd
                        test.sh
  Log:
  Cookie based client session sample code and shell scripts
  
  Revision  Changes    Path
  1.1                  ws-axis/c/samples/client/session/cookie/Client.cpp
  
  Index: Client.cpp
  ===================================================================
  /*
   *   Copyright 2003-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.
   *
   * @author Samisa Abeysinghe (sabeysinghe@virtusa.com)
   *
   */
  
  #include <iostream>
  #include <axis/AxisGenException.hpp>
  #include "./gen_src/Total.h"
  
  using namespace std;
  
  static void
  usage (char *programName, char *defaultURL)
  {
      cout << "\nUsage:\n"
  	<< programName << " [-? | inc_size [service_url]] " << endl
  	<< "    -?             Show this help.\n"
  	<< "    inc_size       Step size for increment operation. Default is 10.\n"
  	<< "    service_url    URL of the service.\n"
  	<< "                   Default service URL is assumed to be " << defaultURL
  	<< endl;
  }
  
  
  int
  main (int argc, char *argv[])
  {
      double increment = 10.0;
      char endpoint[256];
  
      // Set default service URL
      sprintf (endpoint, "http://localhost:9090/axis/services/Total");
  
      try
      {
  
  	if (argc > 1)
  	{
  	    // Watch for special case help request
  	    if (!strncmp (argv[1], "-", 1)) // Check for - only so that it works for 
                                              //-?, -h or --help; -anything 
  	    {
  		usage (argv[0], endpoint);
  		return 2;
  	    }
  	    increment = atoi(argv[1]);
  	}
          
          if (argc > 2)
              sprintf (endpoint, argv[2]);
  
  	cout << endl << " Using service at " << endpoint << endl << endl;
  
  	Total ws (endpoint);
  
          ws.setTransportTimeout(2);
  
          double incResult = 0.0;
         
          ws.setMaintainSession(true); 
          cout << "setMaintainSession = true\n";
          cout << "Result = " << ws.inc(increment) << endl;
          cout << "Result = " << ws.inc(increment) << endl;
          ws.setMaintainSession(false); 
          cout << "setMaintainSession = false\n";
          cout << "Result = " << ws.inc(increment) << endl;
          cout << "Result = " << ws.inc(increment) << endl;
          ws.setMaintainSession(true); 
          cout << "setMaintainSession = true\n";
          cout << "Result = " << ws.inc(increment) << endl;
          cout << "Result = " << ws.inc(increment) << endl;
  
      }
      catch (AxisException & e)
      {
  	printf ("Exception : %s\n", e.what ());
      }
      catch (exception & e)
      {
  	printf ("Unknown exception has occured\n");
      }
      catch (...)
      {
  	printf ("Unknown exception has occured\n");
      }
  
      return 0;
  }
  
  
  
  1.1                  ws-axis/c/samples/client/session/cookie/Total.wsdl
  
  Index: Total.wsdl
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <wsdl:definitions targetNamespace="urn:Total" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:Total" xmlns:intf="urn:Total" 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 created by Apache Axis version: 1.2beta
  Built on Mar 31, 2004 (12:47:03 EST)-->
  
     <wsdl:message name="incRequest">
  
        <wsdl:part name="in0" type="xsd:double"/>
  
     </wsdl:message>
  
     <wsdl:message name="incResponse">
  
        <wsdl:part name="incReturn" type="xsd:double"/>
  
     </wsdl:message>
  
     <wsdl:portType name="Total">
  
        <wsdl:operation name="inc" parameterOrder="in0">
  
           <wsdl:input message="impl:incRequest" name="incRequest"/>
  
           <wsdl:output message="impl:incResponse" name="incResponse"/>
  
        </wsdl:operation>
  
     </wsdl:portType>
  
     <wsdl:binding name="TotalSoapBinding" type="impl:Total">
  
        <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  
        <wsdl:operation name="inc">
  
           <wsdlsoap:operation soapAction=""/>
  
           <wsdl:input name="incRequest">
  
              <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Total" use="encoded"/>
  
           </wsdl:input>
  
           <wsdl:output name="incResponse">
  
              <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:Total" use="encoded"/>
  
           </wsdl:output>
  
        </wsdl:operation>
  
     </wsdl:binding>
  
     <wsdl:service name="TotalService">
  
        <wsdl:port binding="impl:TotalSoapBinding" name="Total">
  
           <wsdlsoap:address location="http://localhost:8080/axis/services/Total"/>
  
        </wsdl:port>
  
     </wsdl:service>
  
  </wsdl:definitions>
  
  
  
  1.1                  ws-axis/c/samples/client/session/cookie/build.sh
  
  Index: build.sh
  ===================================================================
  #!/bin/sh
  
  java org.apache.axis.wsdl.WSDL2Java -S true -d Session -Nurn:Total axisj Total.wsdl
  
  cp -f axisj/TotalSoapBindingImpl.java.bak axisj/TotalSoapBindingImpl.java
  
  javac axisj/*.java
  
  #Cannot test with Simple server as it uses href/multiref
  #Configure tomcat based Axis server not to use href/multiref
  #java org.apache.axis.transport.http.SimpleAxisServer -p 9090 &
  
  
  java -classpath $AXISCPP_HOME/lib/axis/wsdl2ws.jar:$CLASSPATH org.apache.axis.wsdl.wsdl2ws.WSDL2Ws -ogen_src -lc++ -sclient Total.wsdl
  
  g++ Client.cpp gen_src/*.cpp -Igen_src -I$AXISCPP_HOME/include -L$AXISCPP_DEPLOY/lib -ldl -laxiscpp_client -oclient
  
  
  
  
  1.1                  ws-axis/c/samples/client/session/cookie/readme.txt
  
  Index: readme.txt
  ===================================================================
  This sample shows how you can use HTTP Cookie based sessions with Axis C++ clients.
  As of now, Cookie based session handling is a 'client side only' feature in Axis C++. 
  Hence, you will have to use Axis Java server side to run this sample.
  It is expected that Axis C++ would support Cookey based sessions on server side in future releases.
  
  1. Generate the Axis Java code for the WSDL file:
  java org.apache.axis.wsdl.WSDL2Java -S true -d Session -Nurn:Total axisj Total.wsdl
  
  2. The implementation logic for Java server side is already written for you. 
  Copy that to Impl file
  cp axisj/TotalSoapBindingImpl.java.bak axisj/TotalSoapBindingImpl.java
  
  Also if you need to compare C++ client's behavior to that if Java client, a Java client
  implementation is also provided in axisj/Client.java
  
  3. Compile the generated Java code
  javac axisj/*.java
  
  4. It is a known fact that Axis C++ cannot handle href/multiref. By default, Axis Java 
  uses href/multiref. So before you run this sample, you have to disable the use of
  href/multiref by Axis Java server by editing server-config.wsdd file in 
  $TOMCAT_HOME/webapps/axis/WEB-INF. In that file set the sendMultiRefs setting to false.
  <parameter name="sendMultiRefs" value="false"/>
  
  Alternatively you can run Axis Java's SimpleAxisServer with href/multiref disabled.
  There is a server-config.wsdd file with href/multiref disabled in this sample's folder,
  so when you run SimpleAxisServer from this folder href/multiref would be disabled.
  java org.apache.axis.transport.http.SimpleAxisServer -p 9090 &
  
  5. Now deploy the Axis Java service.
  java org.apache.axis.client.AdminClient -hlocalhost -p9090 axisj/deploy.wsdd
  
  6. We are done with Java stuff now. Let's generate C++ client side code for the WSDL and
  place the generated code in gen_src sub folder.
  java -classpath $AXISCPP_HOME/lib/axis/wsdl2ws.jar:$CLASSPATH org.apache.axis.wsdl.wsdl2ws.WSDL2Ws -ogen_src -lc++ -sclient Test.wsdl
  
  7. You need to write the client code. It is already done for you and the code is in Client.cpp.
  The only difference when maintaining session with the service from a C++ client, compared to 
  clients that does not maintain session, is to call setMaintainSession() on top of the stub object.
  If you say:
      stubObject.setMaintainSession(true);
  session maintenance would be enabled. To disable session maintanace use:
      stubObject.setMaintainSession(false);
  
  8. Compile the generated code and client code.
  g++ Client.cpp gen_src/*.cpp -Igen_src -I$AXISCPP_HOME/include -L$AXISCPP_DEPLOY/lib -ldl -laxiscpp_client -oclient
  
  9. Run the client.
  ./client
  
  10. If you want to verify that the Java client does the same, run:
  java axisj.Client
  
  There are couple of Linux shell scripts to help you run this sample on Linux.
  Just run:
  ./test.sh
  
  - Samisa...
  
  
  1.1                  ws-axis/c/samples/client/session/cookie/run.sh
  
  Index: run.sh
  ===================================================================
  #!/bin/sh
  java org.apache.axis.transport.http.SimpleAxisServer -p 9090 &
  
  java org.apache.axis.client.AdminClient -hlocalhost -p9090 axisj/deploy.wsdd
  
  echo
  echo Run Java client
  java axisj.Client
  
  echo
  echo Run C++ client
  ./client
  
  
  
  
  1.1                  ws-axis/c/samples/client/session/cookie/server-config.wsdd
  
  Index: server-config.wsdd
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
   <globalConfiguration>
    <parameter name="adminPassword" value="admin"/>
    <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/>
    <parameter name="sendXsiTypes" value="true"/>
    <parameter name="sendMultiRefs" value="false"/>
    <parameter name="sendXMLDeclaration" value="true"/>
    <requestFlow>
     <handler type="java:org.apache.axis.handlers.JWSHandler">
      <parameter name="scope" value="session"/>
     </handler>
     <handler type="java:org.apache.axis.handlers.JWSHandler">
      <parameter name="scope" value="request"/>
      <parameter name="extension" value=".jwr"/>
     </handler>
    </requestFlow>
   </globalConfiguration>
   <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/>
   <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/>
   <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/>
   <service name="AdminService" provider="java:MSG">
    <parameter name="allowedMethods" value="AdminService"/>
    <parameter name="enableRemoteAdmin" value="false"/>
    <parameter name="className" value="org.apache.axis.utils.Admin"/>
    <namespace>http://xml.apache.org/axis/wsdd/</namespace>
   </service>
   <service name="Version" provider="java:RPC">
    <parameter name="allowedMethods" value="getVersion"/>
    <parameter name="className" value="org.apache.axis.Version"/>
   </service>
   <service name="Total" provider="java:RPC">
    <parameter name="allowedMethods" value="*"/>
    <parameter name="wsdlPortType" value="Total"/>
    <parameter name="scope" value="Session"/>
    <parameter name="className" value="axisj.TotalSoapBindingSkeleton"/>
    <parameter name="wsdlServicePort" value="Total"/>
    <parameter name="wsdlTargetNamespace" value="urn:Total"/>
    <parameter name="wsdlServiceElement" value="TotalService"/>
   </service>
   <transport name="http">
    <requestFlow>
     <handler type="URLMapper"/>
     <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/>
    </requestFlow>
    <parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler"/>
    <parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler"/>
    <parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler"/>
   </transport>
   <transport name="local">
    <responseFlow>
     <handler type="LocalResponder"/>
    </responseFlow>
   </transport>
  </deployment>
  
  
  
  1.1                  ws-axis/c/samples/client/session/cookie/test.sh
  
  Index: test.sh
  ===================================================================
  #!/bin/sh
  
  ./build.sh
  ./run.sh