axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: xml-axis/java/test/wsdl/jaxrpchandler ClientHandler.java JAXRPCHandlerTestCase.java ServerHandler.java StockQuoteImpl.java build.xml client_deploy.wsdd deploy.wsdd jaxrpchandler.wsdl server_deploy.wsdd undeploy.wsdd
Date Wed, 04 Sep 2002 14:55:30 GMT
dims        2002/09/04 07:55:30

  Added:       java/test/wsdl/jaxrpchandler ClientHandler.java
                        JAXRPCHandlerTestCase.java ServerHandler.java
                        StockQuoteImpl.java build.xml client_deploy.wsdd
                        deploy.wsdd jaxrpchandler.wsdl server_deploy.wsdd
                        undeploy.wsdd
  Log:
  Patch from "Greg Truty" <gtruty@us.ibm.com> for JAXRPC Handler testcase + changes.
  
  Notes from Greg:
  I've made a bit of progress w/the Handler code and have testcase plus some
  code changes (along w/some other bugs that I have noticed).  This is on a
  version of todays driver (9/03).
  
  The testcase is included below in test\jaxrpchandler.  It tests the
  addition of a client/server side handler, along w/ client-config and
  programatic API access changes.  It deploys/undeploys the service
  appropriately.  The handler adds a header element at each of the hook
  points, incrementing a counter in the header.  Lastly, on the client
  response, it checks to ensure the counter has been updated appropriate and
  calls a static method to the testcase (it's out-of-band) to confirm that
  the handlers executed appropriately.
  
  The code changes take into account the role/header/parameter options (which
  were wrong/missing in the code orginally checked in).
  
  Revision  Changes    Path
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/ClientHandler.java
  
  Index: ClientHandler.java
  ===================================================================
  package test.wsdl.jaxrpchandler;
  
  import javax.xml.namespace.QName;
  import javax.xml.rpc.handler.Handler;
  import javax.xml.rpc.handler.HandlerInfo;
  import javax.xml.rpc.handler.MessageContext;
  import javax.xml.rpc.handler.soap.SOAPMessageContext;
  import javax.xml.soap.*;
  import java.util.Iterator;
  
  /**
   */
  public class ClientHandler implements Handler {
  
  	private final static String _actorURI = "myActorURI";
  	/**
  	 * Constructor for ClientHandler.
  	 */
  	public ClientHandler() {
  		super();
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#handleRequest(MessageContext)
  	 */
  	public boolean handleRequest(MessageContext context) {
  		System.out.println("Hey - in Handle request");
  		try {
  			SOAPMessageContext smc = (SOAPMessageContext) context;
  			SOAPMessage msg = smc.getMessage();
  			SOAPPart sp = msg.getSOAPPart();
  			SOAPEnvelope se = sp.getEnvelope();
  			SOAPHeader sh = se.getHeader();
  			Name name =
  			se.createName(
  						 "HeaderTest",
  						 "AXIS",
  						 "http://xml.apache.org/axis");
  			SOAPHeaderElement she = sh.addHeaderElement(name);
  			she.setActor(_actorURI);
  			she.addAttribute(se.createName("counter", "", ""), "1");
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  
  		return false;
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#handleResponse(MessageContext)
  	 */
  	public boolean handleResponse(MessageContext context) {
  		System.out.println("Hey - in Handle response");
  		try {
  			String counter = null;
  			SOAPMessageContext smc = (SOAPMessageContext) context;
  			SOAPMessage msg = smc.getMessage();
  			SOAPPart sp = msg.getSOAPPart();
  			SOAPEnvelope se = sp.getEnvelope();
  			SOAPHeader sh = se.getHeader();
  			Name name =
  			se.createName(
  						 "HeaderTest",
  						 "AXIS",
  						 "http://xml.apache.org/axis");
  			Iterator iter = sh.extractHeaderElements(_actorURI);
  			while (iter.hasNext()) {
  				SOAPHeaderElement she = (SOAPHeaderElement) iter.next();
  				counter =
  				she.getAttributeValue(se.createName("counter", "", ""));
  				System.out.println(
  								  "The counter in the element sent back is " + counter);
  			}
  
  			if (counter.equals("3"))
  				JAXRPCHandlerTestCase.completeRoundtrip();
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  
  		return false;
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#handleFault(MessageContext)
  	 */
  	public boolean handleFault(MessageContext context) {
  		return false;
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#init(HandlerInfo)
  	 */
  	public void init(HandlerInfo config) {
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#destroy()
  	 */
  	public void destroy() {
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#getHeaders()
  	 */
  	public QName[] getHeaders() {
  		return null;
  	}
  
  }
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/JAXRPCHandlerTestCase.java
  
  Index: JAXRPCHandlerTestCase.java
  ===================================================================
  package test.wsdl.jaxrpchandler;
  
  import junit.framework.TestCase;
  
  import org.apache.axis.client.AdminClient;
  import org.apache.axis.utils.Admin;
  import javax.xml.rpc.ParameterMode;
  import javax.xml.namespace.QName;
  import javax.xml.rpc.handler.HandlerRegistry;
  import javax.xml.rpc.handler.HandlerInfo;
  
  import org.apache.axis.AxisFault;
  import org.apache.axis.client.Call;
  import org.apache.axis.client.Service;
  import org.apache.axis.encoding.XMLType;
  import org.apache.axis.utils.Options;
  
  import java.net.URL;
  
  /**
   *
   */
  public class JAXRPCHandlerTestCase extends TestCase {
  
  	private static boolean _roundtrip = false;
  	public static void completeRoundtrip() {
  		_roundtrip = true;
  	}
  
  	/**
  	 * Default constructor for use as service
  	 */
  	public JAXRPCHandlerTestCase() {
  		super("JAXRPCHandlerTest");
  	}
  
  	public JAXRPCHandlerTestCase(String name) {
  		super(name);
  	}
  
  	public void testStockQuote() throws Exception {
  	    String[] args = {};
  	    goStockQuote(args);
  	}
  
  	public void goStockQuote(String[] args) throws Exception {
  		Options opts = new Options( args );
  		args = opts.getRemainingArgs();
  
  		URL url = new URL(opts.getURL());
  		String user = opts.getUser();
  		String passwd = opts.getPassword();
  		System.out.println("URL is " + url);
  
  		_roundtrip = false;
  		doTestDeploy();
  		float val = getQuote(url,false);
  		assertEquals("Stock price is not the expected 55.25 +/- 0.01", val, 55.25, 0.01);
  		assertTrue("Expected setting for config-based handlers should be true", _roundtrip ==
true);
  		doTestClientUndeploy();
  		_roundtrip = false;
  		val = getQuote(url,true);
  		assertEquals("Stock price is not the expected 55.25 +/- 0.01", val, 55.25, 0.01);
  		assertTrue("Expected setting for programmatic-based handlers should be true", _roundtrip
== true);
  		doTestServerUndeploy();
  
  	}
  
  	public float getQuote (URL url, boolean runJAXRPCHandler) throws Exception {
  		StockQuoteService  service = new StockQuoteServiceLocator();
  		if (runJAXRPCHandler) {
  			HandlerRegistry hr = service.getHandlerRegistry();
  			java.util.List lhi = new java.util.Vector();
  			test.wsdl.jaxrpchandler.ClientHandler mh = new test.wsdl.jaxrpchandler.ClientHandler();

  			Class myhandler = mh.getClass();
  			HandlerInfo hi = new HandlerInfo(myhandler,null,null);
  			lhi.add(hi);
  			hr.setHandlerChain(new QName("","jaxrpchandler"),lhi);
  		}
  
  		float res;
  
  		StockQuote sq = service.getjaxrpchandler(url);
  		res = sq.getQuote("XXX");
  
  		return res;
  	}
  
  	public static void main(String[] args) throws Exception {
  		JAXRPCHandlerTestCase test = new JAXRPCHandlerTestCase("test");
  		test.goStockQuote(args);
  	}
  
  	public void doTestClientUndeploy() throws Exception {
  		String[] args1 = { "client", "test/wsdl/jaxrpchandler/undeploy.wsdd"};
  		Admin.main(args1);
  	}
  
  	public void doTestServerUndeploy() throws Exception {
  		String[] args = { "test/wsdl/jaxrpchandler/undeploy.wsdd"};
  		AdminClient.main(args);
  	}
  
  	public void doTestDeploy() throws Exception {
  		String[] args = { "test/wsdl/jaxrpchandler/server_deploy.wsdd"};
  		AdminClient.main(args);
  		String[] args1 = { "client", "test/wsdl/jaxrpchandler/client_deploy.wsdd"};
  		Admin.main(args1);
  	}
  
  }
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/ServerHandler.java
  
  Index: ServerHandler.java
  ===================================================================
  package test.wsdl.jaxrpchandler;
  
  import javax.xml.namespace.QName;
  import javax.xml.rpc.handler.Handler;
  import javax.xml.rpc.handler.HandlerInfo;
  import javax.xml.rpc.handler.MessageContext;
  import javax.xml.rpc.handler.soap.SOAPMessageContext;
  import javax.xml.soap.*;
  import java.util.*;
  
  /**
   */
  public class ServerHandler implements Handler {
  
  	private int _counter = 0;
  	public final static String _actorURI = "myActorURI";
  	/**
  	 * Constructor for ClientHandler.
  	 */
  	public ServerHandler() {
  		super();
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#handleRequest(MessageContext)
  	 */
  	public boolean handleRequest(MessageContext context) {
  		System.out.println("Hey - in Handle request");
  		try {
  			SOAPMessageContext smc = (SOAPMessageContext) context;
  			SOAPMessage msg = smc.getMessage();
  			SOAPPart sp = msg.getSOAPPart();
  			SOAPEnvelope se = sp.getEnvelope();
  			SOAPHeader sh = se.getHeader();
  			Name name = se.createName("HeaderTest", "AXIS",
  									  "http://xml.apache.org/axis");
  			Iterator iter = sh.extractHeaderElements(_actorURI);
  			while (iter.hasNext()) {
  				SOAPHeaderElement she = (SOAPHeaderElement) iter.next();
  				String counter = she.getAttributeValue(se.createName("counter","",""));
  				_counter = Integer.parseInt(counter) + 1;
  			}
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  
  		return false;
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#handleResponse(MessageContext)
  	 */
  	public boolean handleResponse(MessageContext context) {
  
  		System.out.println("Hey - in Handle response");
  		try {
  			SOAPMessageContext smc = (SOAPMessageContext) context;
  			SOAPMessage msg = smc.getMessage();
  			SOAPPart sp = msg.getSOAPPart();
  			SOAPEnvelope se = sp.getEnvelope();
  			SOAPHeader sh = se.getHeader();
  			Name name = se.createName("HeaderTest", "AXIS",
  									  "http://xml.apache.org/axis");
  			SOAPHeaderElement she = sh.addHeaderElement(name);
  			she.addAttribute(se.createName("counter","",""), new Integer(_counter +1).toString());
  			she.setActor(_actorURI);
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  		return false;
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#handleFault(MessageContext)
  	 */
  	public boolean handleFault(MessageContext context) {
  		return false;
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#init(HandlerInfo)
  	 */
  	public void init(HandlerInfo config) {
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#destroy()
  	 */
  	public void destroy() {
  	}
  
  	/**
  	 * @see javax.xml.rpc.handler.Handler#getHeaders()
  	 */
  	public QName[] getHeaders() {
  		return null;
  	}
  
  }
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/StockQuoteImpl.java
  
  Index: StockQuoteImpl.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:  
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "AXIS" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written 
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  package test.wsdl.jaxrpchandler;
  
  /**
   * See \samples\stock\readme for info.
   *
   */
  public class StockQuoteImpl {
  
    public float getQuote (String symbol) throws Exception {
  
      if ( symbol.equals("XXX") ) return( (float) 55.25 );
      else return( 0 );
    }
  }
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/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/jaxrpchandler"/>
  
          &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,clean"/>
  
  <target name="compile" depends="copy">
    <echo message="Compiling test.${componentName}"/>
      <!-- This is (OK, "will be") a comprehensive test of XML schema types -->
      <wsdl2java url="${axis.home}/test/wsdl/jaxrpchandler/jaxrpchandler.wsdl"
                 output="${build.dir}/work"
                 serverSide="no"
                 testcase="no">
      </wsdl2java>
  
      <copy todir="${build.dir}/work/test/wsdl/jaxrpchandler" overwrite="yes">
        <fileset dir="${axis.home}/test/wsdl/jaxrpchandler">
          <include name="**/*.java"/>
        </fileset>
      </copy>
  
  
    <javac srcdir="${build.dir}/work" destdir="${build.dest}" debug="${debug}">
      <classpath>
          <path refid="classpath"/>
      </classpath>
      <include name="${componentName}/*.java"/>
    </javac>
  </target>
  
  <target name="run">
  	<antcall target="execute-Component" />
  </target>
  
  </project>
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/client_deploy.wsdd
  
  Index: client_deploy.wsdd
  ===================================================================
  <deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/" 
      xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
    <service name="jaxrpchandler">
      <handlerInfoChain>
         <handlerInfo classname="test.wsdl.jaxrpchandler.ClientHandler">
         <parameter name="param1" value="value1"/>
         <parameter name="param4" value="value4"/>
         <parameter name="param3" value="value3"/>
         <header qname="ns11:Bob" xmlns:ns11="http://bob.com/stuff"/>
         <header qname="ns12:Fred" xmlns:ns12="http://fred.com/stuff"/>
         <header qname="ns12:Fred" xmlns:ns12="FredNS"/>
         <header qname="ns11:Bob" xmlns:ns11="BobNS"/>
         <header qname="Tom"/>
         </handlerInfo>
         <role soapActorName="Mary"/>
      </handlerInfoChain>
    </service>
  </deployment>
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/deploy.wsdd
  
  Index: deploy.wsdd
  ===================================================================
  <deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/" 
      xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
    <service name="urn:jaxrpchandlertest" provider="java:RPC">
      <parameter name="className" value="samples.stock.StockQuoteService"/>
      <parameter name="allowedMethods" value="getQuote"/>
      <parameter name="wsdlServicePort" value="GetQuote"/>
    </service>
  </deployment>
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/jaxrpchandler.wsdl
  
  Index: jaxrpchandler.wsdl
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <wsdl:definitions targetNamespace="urn:jaxrpchandler.wsdl.test" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:jaxrpchandler.wsdl.test"
xmlns:intf="urn:jaxrpchandler.wsdl.test" 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="getQuoteRequest">
      <wsdl:part name="symbol" type="xsd:string"/>
    </wsdl:message>
    <wsdl:message name="getQuoteResponse">
      <wsdl:part name="getQuoteReturn" type="xsd:float"/>
    </wsdl:message>
    <wsdl:portType name="StockQuote">
      <wsdl:operation name="getQuote" parameterOrder="symbol">
        <wsdl:input message="intf:getQuoteRequest" name="getQuoteRequest"/>
        <wsdl:output message="intf:getQuoteResponse" name="getQuoteResponse"/>
      </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="GetQuoteSoapBinding" type="intf:StockQuote">
      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="getQuote">
        <wsdlsoap:operation soapAction=""/>
        <wsdl:input name="getQuoteRequest">
          <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="jaxrpchandler"
use="encoded"/>
        </wsdl:input>
        <wsdl:output name="getQuoteResponse">
          <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="jaxrpchandler"
use="encoded"/>
        </wsdl:output>
      </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="StockQuoteService">
      <wsdl:port binding="intf:GetQuoteSoapBinding" name="jaxrpchandler">
        <wsdlsoap:address location="http://localhost:8080/axis/services/jaxrpchandler"/>
      </wsdl:port>
    </wsdl:service>
  </wsdl:definitions>
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/server_deploy.wsdd
  
  Index: server_deploy.wsdd
  ===================================================================
  <deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/" 
      xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
    <service name="jaxrpchandler" provider="java:RPC">
      <handlerInfoChain>
         <handlerInfo classname="test.wsdl.jaxrpchandler.ServerHandler"/>
      </handlerInfoChain>
      <parameter name="className" value="test.wsdl.jaxrpchandler.StockQuoteImpl"/>
      <parameter name="allowedMethods" value="getQuote"/>
      <parameter name="wsdlServicePort" value="GetQuote"/>
    </service>
  </deployment>
  
  
  
  1.1                  xml-axis/java/test/wsdl/jaxrpchandler/undeploy.wsdd
  
  Index: undeploy.wsdd
  ===================================================================
  <undeployment name="test" xmlns="http://xml.apache.org/axis/wsdd/">
    <service name="jaxrpchandler"/>
  </undeployment>
  
  
  

Mime
View raw message