gdaniels 02/03/17 20:03:36 Modified: java/src/org/apache/axis MessageContext.java java/src/org/apache/axis/client AxisClient.java Call.java java/src/org/apache/axis/handlers BasicHandler.java java/src/org/apache/axis/handlers/soap SOAPService.java Added: java/src/org/apache/axis/configuration BasicClientConfig.java BasicServerConfig.java java/test/properties PackageTests.java PropertyHandler.java TestScopedProperties.java Log: * Flesh out the scoped properties pattern some. Now we always set the MC's property parent to the service if we set one. The Call object now takes care of making sure that the client-side service has the Call as it's property parent. * Introduce APIs on Call to make setting up client-side Handlers/services easier. This is really handy for hard-coding client usage of Handlers. * Unit tests for scoped properties * Introduce BasicServerConfig and BasicClientConfig, which are essentially SimpleProviders which are pre-configured with hardcoded transports (local for both, and HTTP as well for the client side) * Clean up AxisClient handling of service handlers, use what is in the MessageContext, since Call now sets it if necessary. Revision Changes Path 1.84 +4 -0 xml-axis/java/src/org/apache/axis/MessageContext.java Index: MessageContext.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/MessageContext.java,v retrieving revision 1.83 retrieving revision 1.84 diff -u -r1.83 -r1.84 --- MessageContext.java 9 Mar 2002 22:12:48 -0000 1.83 +++ MessageContext.java 18 Mar 2002 04:03:35 -0000 1.84 @@ -499,6 +499,10 @@ setOperationStyle(service.getStyle()); setEncodingStyle((service.getStyle() == ServiceDesc.STYLE_RPC) ? Constants.URI_CURRENT_SOAP_ENC : ""); + + // This MessageContext should now defer properties it can't find + // to the Service's options. + bag.setParent(sh.getOptions()); } } 1.42 +7 -8 xml-axis/java/src/org/apache/axis/client/AxisClient.java Index: AxisClient.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/AxisClient.java,v retrieving revision 1.41 retrieving revision 1.42 diff -u -r1.41 -r1.42 --- AxisClient.java 6 Mar 2002 20:34:17 -0000 1.41 +++ AxisClient.java 18 Mar 2002 04:03:35 -0000 1.42 @@ -62,6 +62,7 @@ import org.apache.axis.Handler; import org.apache.axis.MessageContext; import org.apache.axis.SimpleTargetedChain; +import org.apache.axis.handlers.soap.SOAPService; import org.apache.axis.utils.JavaUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -145,18 +146,16 @@ // When do we call init/cleanup?? - SimpleTargetedChain service = null ; + SOAPService service = null ; msgContext.setPastPivot(false); /* Process the Service Specific Request Chain */ /**********************************************/ - hName = msgContext.getTargetService(); - if ( hName != null && (h = getService( hName )) != null ) { - if ( h instanceof SimpleTargetedChain ) { - service = (SimpleTargetedChain) h ; - h = service.getRequestHandler(); - } - if ( h != null ) h.invoke( msgContext ); + service = msgContext.getService(); + if ( service != null ) { + h = service.getRequestHandler(); + if ( h != null ) + h.invoke( msgContext ); } /* Process the Global Request Chain */ 1.100 +71 -20 xml-axis/java/src/org/apache/axis/client/Call.java Index: Call.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/client/Call.java,v retrieving revision 1.99 retrieving revision 1.100 diff -u -r1.99 -r1.100 --- Call.java 15 Mar 2002 17:15:51 -0000 1.99 +++ Call.java 18 Mar 2002 04:03:35 -0000 1.100 @@ -81,6 +81,8 @@ import org.apache.axis.utils.JavaUtils; import org.apache.axis.attachments.AttachmentPart; import org.apache.axis.InternalException; +import org.apache.axis.Handler; +import org.apache.axis.handlers.soap.SOAPService; import org.apache.axis.description.OperationDesc; import org.apache.axis.description.ServiceDesc; @@ -1724,28 +1726,39 @@ } msgContext.setEncodingStyle(encodingStyle); - /** - * Go thru the properties and ones that are Axis specific, and - * need to be moved to the msgContext - do so. - * TBD: - * security.auth.subject - */ - if (myProperties != null) { - msgContext.setPropertyParent(myProperties); - } - // Determine client target service - reqMsg = msgContext.getRequestMessage(); - reqEnv = reqMsg.getSOAPEnvelope(); - SOAPBodyElement body = reqEnv.getFirstBody(); - - if ( body.getPrefix() == null ) body.setPrefix( "m" ); - if ( body.getNamespaceURI() == null ) { - throw new AxisFault("Call.invoke", - JavaUtils.getMessage("cantInvoke00", body.getName()), + if (myService != null) { + // If we have a SOAPService kicking around, use that directly + msgContext.setService(myService); + } else { + if (targetService != null) { + // No explicit service. If we have a target service name, + // try that. + msgContext.setTargetService(targetService); + } else { + // No direct config, so try the namespace of the first body. + reqMsg = msgContext.getRequestMessage(); + reqEnv = reqMsg.getSOAPEnvelope(); + SOAPBodyElement body = reqEnv.getFirstBody(); + + // Does this make any sense to anyone? If not, we should remove it. + // --Glen 03/16/02 + //if ( body.getPrefix() == null ) body.setPrefix( "m" ); + if ( body.getNamespaceURI() == null ) { + throw new AxisFault("Call.invoke", + JavaUtils.getMessage("cantInvoke00", body.getName()), null, null); - } else if (msgContext.getService() == null) { - msgContext.setTargetService(body.getNamespaceURI()); + } else { + msgContext.setTargetService(body.getNamespaceURI()); + } + } + + SOAPService svc = msgContext.getService(); + if (svc != null) { + svc.setPropertyParent(myProperties); + } else { + msgContext.setPropertyParent(myProperties); + } } if (log.isDebugEnabled()) { @@ -1830,6 +1843,44 @@ return this.service; } + private SOAPService myService = null; + private String targetService = null; + + /** + * + */ + public void setSOAPService(SOAPService service) + { + myService = service; + if (service != null) { + // Set the service so that it defers missing property gets to the + // Call. So when client-side Handlers get at the MessageContext, + // the property scoping will be MC -> SOAPService -> Call + service.setPropertyParent(myProperties); + } + } + + /** + * Sets the client-side request and response Handlers. This is handy + * for programatically setting up client-side work without deploying + * via WSDD or the EngineConfiguration mechanism. + */ + public void setClientHandlers(Handler reqHandler, Handler respHandler) + { + // Create a SOAPService which will be used as the client-side service + // handler. + setSOAPService(new SOAPService(reqHandler, null, respHandler)); + } + + /** + * Set the target service name on the client side. Note that an explicit + * set of an actual SOAPService (with setSOAPService()) will override + * this. + */ + public void setTargetService(String targetService) + { + this.targetService = targetService; + } protected java.util.Vector attachmentParts= new java.util.Vector(); 1.1 xml-axis/java/src/org/apache/axis/configuration/BasicClientConfig.java Index: BasicClientConfig.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 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 [EMAIL PROTECTED] * * 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 org.apache.axis.configuration; import org.apache.axis.transport.local.LocalSender; import org.apache.axis.transport.http.HTTPSender; import org.apache.axis.Handler; import org.apache.axis.SimpleTargetedChain; /** * A SimpleProvider set up with hardcoded basic configuration for a client * (i.e. http and local transports). * * @author Glen Daniels ([EMAIL PROTECTED]) */ public class BasicClientConfig extends SimpleProvider { /** * Constructor - deploy client-side basic transports. */ public BasicClientConfig() { Handler h = new LocalSender(); SimpleTargetedChain transport = new SimpleTargetedChain(h); deployTransport("local", transport); h = new HTTPSender(); transport = new SimpleTargetedChain(h); deployTransport("http", transport); } } 1.1 xml-axis/java/src/org/apache/axis/configuration/BasicServerConfig.java Index: BasicServerConfig.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 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 [EMAIL PROTECTED] * * 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 org.apache.axis.configuration; import org.apache.axis.transport.local.LocalSender; import org.apache.axis.transport.local.LocalResponder; import org.apache.axis.transport.http.HTTPSender; import org.apache.axis.Handler; import org.apache.axis.SimpleTargetedChain; /** * A SimpleProvider set up with hardcoded basic configuration for a server * (i.e. local transport). Mostly handy for testing. * * @author Glen Daniels ([EMAIL PROTECTED]) */ public class BasicServerConfig extends SimpleProvider { /** * Constructor - deploy a hardcoded basic server-side configuration. */ public BasicServerConfig() { Handler h = new LocalResponder(); SimpleTargetedChain transport = new SimpleTargetedChain(null, null, h); deployTransport("local", transport); } } 1.27 +13 -2 xml-axis/java/src/org/apache/axis/handlers/BasicHandler.java Index: BasicHandler.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/BasicHandler.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- BasicHandler.java 15 Mar 2002 05:07:11 -0000 1.26 +++ BasicHandler.java 18 Mar 2002 04:03:36 -0000 1.27 @@ -58,6 +58,7 @@ import org.apache.axis.Handler; import org.apache.axis.MessageContext; import org.apache.axis.utils.JavaUtils; +import org.apache.axis.utils.LockableHashtable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -81,9 +82,19 @@ protected static Log log = LogFactory.getLog(BasicHandler.class.getName()); - protected Hashtable options ; + protected Hashtable options; protected String name; + /** Should this Handler use a LockableHashtable for options? */ + protected void initHashtable(boolean makeLockable) + { + if (makeLockable) { + options = new LockableHashtable(); + } else { + options = new Hashtable(); + } + } + /** Stubbed-out methods. Override in your child class to implement * any real behavior. */ @@ -112,7 +123,7 @@ * Set the given option (name/value) in this handler's bag of options */ public void setOption(String name, Object value) { - if ( options == null ) options = new Hashtable(); + if ( options == null ) initHashtable(false); options.put( name, value ); } 1.51 +9 -1 xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java Index: SOAPService.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java,v retrieving revision 1.50 retrieving revision 1.51 diff -u -r1.50 -r1.51 --- SOAPService.java 5 Mar 2002 14:02:13 -0000 1.50 +++ SOAPService.java 18 Mar 2002 04:03:36 -0000 1.51 @@ -73,6 +73,7 @@ import org.apache.axis.message.SOAPEnvelope; import org.apache.axis.message.SOAPHeader; import org.apache.axis.utils.JavaUtils; +import org.apache.axis.utils.LockableHashtable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -85,6 +86,7 @@ import java.util.Vector; import java.util.ArrayList; import java.util.HashMap; +import java.util.Hashtable; import java.beans.IntrospectionException; /** A <code>SOAPService</code> is a Handler which encapsulates a SOAP @@ -188,6 +190,7 @@ */ public SOAPService() { + initHashtable(true); initTypeMappingRegistry(); } @@ -197,8 +200,8 @@ */ public SOAPService(Handler reqHandler, Handler pivHandler, Handler respHandler) { + this(); init(reqHandler, new SOAPRequestHandler(), pivHandler, null, respHandler); - initTypeMappingRegistry(); } private void initTypeMappingRegistry() { @@ -270,6 +273,11 @@ public void setServiceDescription(ServiceDesc serviceDescription) { this.serviceDescription = serviceDescription; + } + + public void setPropertyParent(Hashtable parent) + { + ((LockableHashtable)options).setParent(parent); } /********************************************************************* * Administration and management APIs 1.1 xml-axis/java/test/properties/PackageTests.java Index: PackageTests.java =================================================================== package test.properties; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Test package for property tests */ public class PackageTests extends TestCase { public PackageTests(String name) { super(name); } public static Test suite() throws Exception { TestSuite suite = new TestSuite(); suite.addTestSuite(TestScopedProperties.class); return suite; } } 1.1 xml-axis/java/test/properties/PropertyHandler.java Index: PropertyHandler.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 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 [EMAIL PROTECTED] * * 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.properties; import org.apache.axis.handlers.BasicHandler; import org.apache.axis.handlers.soap.SOAPService; import org.apache.axis.MessageContext; import org.apache.axis.AxisFault; /** * Combination of two functions for this test. * * 1) When invoked as a Handler, save the value of the PROP_NAME property * into a field so the test can look at it later. (used to test client- * side) * * 2) When used as a back-end service, return the value of the PROP_NAME * property (used to test server-side) * * @author Glen Daniels ([EMAIL PROTECTED]) */ public class PropertyHandler extends BasicHandler { private String propVal; public void invoke(MessageContext msgContext) throws AxisFault { // Get the "normal" property value, and save it away. propVal = msgContext.getStrProp(TestScopedProperties.PROP_NAME); // Set the "override" property directly in the MC. msgContext.setProperty(TestScopedProperties.OVERRIDE_NAME, TestScopedProperties.OVERRIDE_VALUE); } public String getPropVal() { return propVal; } public void setPropVal(String propVal) { this.propVal = propVal; } public String testScopedProperty() throws Exception { MessageContext context = MessageContext.getCurrentContext(); String propVal = context.getStrProp(TestScopedProperties.PROP_NAME); return propVal; } public String testOverrideProperty() throws Exception { MessageContext context = MessageContext.getCurrentContext(); String propVal = context.getStrProp(TestScopedProperties.OVERRIDE_NAME); return propVal; } } 1.1 xml-axis/java/test/properties/TestScopedProperties.java Index: TestScopedProperties.java =================================================================== /* * The Apache Software License, Version 1.1 * * * Copyright (c) 2002 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 [EMAIL PROTECTED] * * 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.properties; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.handlers.soap.SOAPService; import org.apache.axis.providers.java.RPCProvider; import org.apache.axis.transport.local.LocalTransport; import org.apache.axis.server.AxisServer; import org.apache.axis.configuration.SimpleProvider; import org.apache.axis.configuration.DefaultEngineConfigurationFactory; import org.apache.axis.configuration.BasicServerConfig; import org.apache.axis.configuration.BasicClientConfig; import org.apache.axis.EngineConfiguration; import org.apache.axis.Handler; import junit.framework.TestCase; /** * Test scoped properties. This test confirms that MessageContext.getProperty * will correctly defer to a higher-level property scope (the Call on the * client side, the SOAPService on the server side) to obtain values for * properties that are not explicitly set in the MessageContext itself. * * @author Glen Daniels ([EMAIL PROTECTED]) */ public class TestScopedProperties extends TestCase { public static final String PROP_NAME = "test.property"; public static final String CLIENT_VALUE = "client-side property value!"; public static final String SERVER_VALUE = "this is the server side value"; public static final String OVERRIDE_NAME = "override.property"; public static final String OVERRIDE_VALUE = "The REAL value!"; private SOAPService service; private PropertyHandler serverHandler = new PropertyHandler(); private SimpleProvider config; private AxisServer server; public TestScopedProperties(String s) { super(s); } /** * Sets up the server side for this test. We deploy a service with * a PropertyHandler as a request handler, and PropertyHandler as the * backend class as well. We set an option on the service to a well- * known value (PROP_NAME -> PROP_VALUE), and also set an option on * the service (OVERRIDE_NAME) which we expect to be overriden by * an explicit setting in the MessageContext. */ protected void setUp() throws Exception { config = new BasicServerConfig(); server = new AxisServer(config); // Deploy a service which contains an option that we expect to be // available by asking the MessageContext in the service method (see // PropertyHandler.java). RPCProvider provider = new RPCProvider(); service = new SOAPService(serverHandler, provider, null); service.setOption("className", PropertyHandler.class.getName()); service.setOption("allowedMethods", "*"); // Here's the interesting property. service.setOption(PROP_NAME, SERVER_VALUE); // Also set a property which we expect to be overriden by an explicit // value in the MessageContext (see PropertyHandler.invoke()). We // should never see this value. service.setOption(OVERRIDE_NAME, SERVER_VALUE); config.deployService("service", service); } /** * Basic scoped properties test. Set up a client side service with a * PropertyHandler as the request handler, then set a property on the * Call which we expect to be available when the request handler queries * the MessageContext. Call the backend service, and make sure the * client handler, the server handler, and the result all agree on what * the values should be. */ public void testScopedProperties() throws Exception { BasicClientConfig config = new BasicClientConfig(); PropertyHandler clientHandler = new PropertyHandler(); SOAPService clientService = new SOAPService(clientHandler, null, null); config.deployService("service", clientService); Service s = new Service(config); Call call = new Call(s); // Set a property on the Call which we expect to be available via // the MessageContext in the client-side handler. call.setProperty(PROP_NAME, CLIENT_VALUE); LocalTransport transport = new LocalTransport(server); transport.setRemoteService("service"); call.setTransport(transport); // Make the call. String result = (String)call.invoke("service", "testScopedProperty", new Object [] { }); assertEquals("Returned scoped property wasn't correct", SERVER_VALUE, result); // Confirm that both the client and server side properties were // correctly read. assertEquals("Client-side scoped property wasn't correct", CLIENT_VALUE, clientHandler.getPropVal()); assertEquals("Server-side scoped property wasn't correct", SERVER_VALUE, serverHandler.getPropVal()); } /** * Test overriding a property that's set in the service with an explicit * setting in the MessageContext. The server-side handler will set the * OVERRIDDE_NAME property, and the "testOverrideProperty" method will * return the value it sees, which should match. */ public void testMessageContextOverride() throws Exception { // Only the server side matters on this one, so don't bother with // special client config. Call call = new Call(new Service()); LocalTransport transport = new LocalTransport(server); transport.setRemoteService("service"); call.setTransport(transport); // Make the call. String result = (String)call.invoke("service", "testOverrideProperty", new Object [] { }); assertEquals("Overriden property value didn't match", OVERRIDE_VALUE, result); } /** * Test of three-level client scopes (MC -> service -> Call). * * Set a property on the Call, then try the invocation. The client-side * handler should see the Call value. Then set the same property to a * different value in the client-side service object, and confirm that * when we invoke again we see the new value. */ public void testFullClientScopes() throws Exception { Call call = new Call(new Service()); PropertyHandler clientHandler = new PropertyHandler(); SOAPService clientService = new SOAPService(clientHandler, null, null); call.setSOAPService(clientService); // Set a property on the Call which we expect to be available via // the MessageContext in the client-side handler. call.setProperty(PROP_NAME, CLIENT_VALUE); LocalTransport transport = new LocalTransport(server); transport.setRemoteService("service"); call.setTransport(transport); // First call should get the value from the Call object. call.invoke("testOverrideProperty", new Object [] { }); assertEquals("Client-side scoped property from Call wasn't correct", CLIENT_VALUE, clientHandler.getPropVal()); // Now set the same option on the client service, which should // take precedence over the value in the Call. clientService.setOption(PROP_NAME, OVERRIDE_VALUE); // Second call should now get the value from the client service. call.invoke("testOverrideProperty", new Object [] { }); assertEquals("Client-side scoped property from service wasn't correct", OVERRIDE_VALUE, clientHandler.getPropVal()); } }