gdaniels 02/02/12 09:18:29 Modified: java/samples/echo deploy.wsdd java/src/org/apache/axis EngineConfiguration.java java/src/org/apache/axis/configuration FileProvider.java NullProvider.java SimpleProvider.java java/src/org/apache/axis/deployment/wsdd WSDDChain.java WSDDDeployment.java WSDDHandler.java WSDDService.java WSDDTargetedChain.java WSDDTransport.java java/src/org/apache/axis/message BodyBuilder.java java/test/encoding TestBody.java Log: Improve the namespace-based dispatch logic. You may now specify, in the WSDD, a service which looks like this: <service name="foo" provider="..."> <namespace>http://foo.com/</namespace> <namespace>http://bar.com/</namespace> ... </service> The URL to the service will be ...services/foo, as expected. If body-based dispatch is necessary, we will dispatch any body element with the namespaces "http://foo.com/", "http://bar.com/", or "foo" to this service. Revision Changes Path 1.15 +2 -1 xml-axis/java/samples/echo/deploy.wsdd Index: deploy.wsdd =================================================================== RCS file: /home/cvs/xml-axis/java/samples/echo/deploy.wsdd,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- deploy.wsdd 10 Feb 2002 02:23:53 -0000 1.14 +++ deploy.wsdd 12 Feb 2002 17:18:28 -0000 1.15 @@ -9,7 +9,8 @@ <deployment name="test" xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"> - <service name="http://soapinterop.org/" provider="java:RPC" > + <service name="echo" provider="java:RPC" > + <namespace>http://soapinterop.org/</namespace> <parameter name="className" value="samples.echo.EchoService" /> <parameter name="allowedMethods" value="*" /> <beanMapping xmlns:echo="http://soapinterop.org/xsd" qname="echo:SOAPStructStruct" 1.4 +9 -0 xml-axis/java/src/org/apache/axis/EngineConfiguration.java Index: EngineConfiguration.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/EngineConfiguration.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- EngineConfiguration.java 30 Jan 2002 16:19:11 -0000 1.3 +++ EngineConfiguration.java 12 Feb 2002 17:18:28 -0000 1.4 @@ -112,6 +112,15 @@ * @throws ConfigurationException XXX */ public Handler getService(QName qname) throws ConfigurationException; + + /** + * Get a service which has been mapped to a particular namespace + * + * @param namespace a namespace URI + * @return an instance of the appropriate Service, or null + */ + public Handler getServiceByNamespaceURI(String namespace) + throws ConfigurationException; /** * retrieve an instance of the named transport 1.19 +11 -0 xml-axis/java/src/org/apache/axis/configuration/FileProvider.java Index: FileProvider.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/FileProvider.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- FileProvider.java 12 Feb 2002 15:34:22 -0000 1.18 +++ FileProvider.java 12 Feb 2002 17:18:28 -0000 1.19 @@ -233,6 +233,17 @@ } /** + * Get a service which has been mapped to a particular namespace + * + * @param namespace a namespace URI + * @return an instance of the appropriate Service, or null + */ + public Handler getServiceByNamespaceURI(String namespace) + throws ConfigurationException { + return deployment.getServiceByNamespaceURI(namespace); + } + + /** * retrieve an instance of the named transport * @param qname XXX * @return XXX 1.3 +5 -0 xml-axis/java/src/org/apache/axis/configuration/NullProvider.java Index: NullProvider.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/NullProvider.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- NullProvider.java 28 Jan 2002 18:23:00 -0000 1.2 +++ NullProvider.java 12 Feb 2002 17:18:28 -0000 1.3 @@ -108,6 +108,11 @@ return null; } + public Handler getServiceByNamespaceURI(String namespace) + throws ConfigurationException { + return null; + } + public Handler getHandler(QName qname) throws ConfigurationException { return null; } 1.3 +14 -0 xml-axis/java/src/org/apache/axis/configuration/SimpleProvider.java Index: SimpleProvider.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/configuration/SimpleProvider.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SimpleProvider.java 28 Jan 2002 18:23:00 -0000 1.2 +++ SimpleProvider.java 12 Feb 2002 17:18:28 -0000 1.3 @@ -208,6 +208,20 @@ return service; } + /** + * Get a service which has been mapped to a particular namespace + * + * @param namespace a namespace URI + * @return an instance of the appropriate Service, or null + */ + public Handler getServiceByNamespaceURI(String namespace) + throws ConfigurationException { + Handler service = (Handler)services.get(new QName("",namespace)); + if ((service == null) && (defaultConfiguration != null)) + service = defaultConfiguration.getServiceByNamespaceURI(namespace); + return service; + } + public Handler getHandler(QName qname) throws ConfigurationException { Handler handler = (Handler)handlers.get(qname); if ((defaultConfiguration != null) && (handler == null)) 1.23 +2 -2 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDChain.java Index: WSDDChain.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDChain.java,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- WSDDChain.java 29 Jan 2002 11:23:48 -0000 1.22 +++ WSDDChain.java 12 Feb 2002 17:18:28 -0000 1.23 @@ -201,9 +201,9 @@ } public void deployToRegistry(WSDDDeployment registry) - throws WSDDException { + { if (getQName() != null) - registry.deployHandler(this); + registry.addHandler(this); for (int n = 0; n < handlers.size(); n++) { WSDDHandler handler = (WSDDHandler)handlers.get(n); 1.24 +63 -7 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDDeployment.java Index: WSDDDeployment.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDDeployment.java,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- WSDDDeployment.java 7 Feb 2002 23:47:40 -0000 1.23 +++ WSDDDeployment.java 12 Feb 2002 17:18:28 -0000 1.24 @@ -87,6 +87,29 @@ private HashMap transports = new HashMap(); private Vector typeMappings = new Vector(); private WSDDGlobalConfiguration globalConfig = null; + + /** Mapping of namespaces -> services */ + private HashMap namespaceToServices = new HashMap(); + + void addHandler(WSDDHandler handler) + { + handlers.put(handler.getQName(), handler); + } + + void addService(WSDDService service) + { + WSDDService oldService = (WSDDService)services.get(service.getQName()); + if (oldService != null) { + oldService.removeNamespaceMappings(this); + } + services.put(service.getQName(), service); + } + + void addTransport(WSDDTransport transport) + { + transports.put(transport.getQName(), transport); + } + /** * Put a WSDDHandler into this deployment, replacing any other @@ -96,7 +119,7 @@ */ public void deployHandler(WSDDHandler handler) { - handlers.put(handler.getQName(), handler); + handler.deployToRegistry(this); } /** @@ -107,7 +130,7 @@ */ public void deployTransport(WSDDTransport transport) { - transports.put(transport.getQName(), transport); + transport.deployToRegistry(this); } /** @@ -118,7 +141,7 @@ */ public void deployService(WSDDService service) { - services.put(service.getQName(), service); + service.deployToRegistry(this); } /** @@ -186,19 +209,19 @@ elements = getChildElements(e, "chain"); for (i = 0; i < elements.length; i++) { WSDDChain chain = new WSDDChain(elements[i]); - chain.deployToRegistry(this); + deployHandler(chain); } elements = getChildElements(e, "transport"); for (i = 0; i < elements.length; i++) { WSDDTransport transport = new WSDDTransport(elements[i]); - transport.deployToRegistry(this); + deployTransport(transport); } elements = getChildElements(e, "service"); for (i = 0; i < elements.length; i++) { WSDDService service = new WSDDService(elements[i]); - service.deployToRegistry(this); + deployService(service); } elements = getChildElements(e, "typeMapping"); @@ -248,7 +271,7 @@ i = services.values().iterator(); while (i.hasNext()) { WSDDService service = (WSDDService) i.next(); - target.deployService(service); + service.deployToRegistry(target); } i = typeMappings.iterator(); @@ -435,6 +458,16 @@ return null; } + public Handler getServiceByNamespaceURI(String namespace) + throws ConfigurationException + { + WSDDService s = (WSDDService)namespaceToServices.get(namespace); + if (s != null) { + return s.getInstance(this); + } + + return null; + } public void configureEngine(AxisEngine engine) throws ConfigurationException { @@ -482,5 +515,28 @@ public Hashtable getGlobalOptions() throws ConfigurationException { return globalConfig.getParametersTable(); + } + + /** + * Register a particular namepsace which maps to a given WSDDService. + * This will be used for namespace-based dispatching. + * + * @param namespace a namespace URI + * @param service the target WSDDService + */ + public void registerNamespaceForService(String namespace, + WSDDService service) + { + namespaceToServices.put(namespace, service); + } + + /** + * Remove a namespace -> WSDDService mapping. + * + * @param namespace the namespace URI to unmap + */ + public void removeNamespaceMapping(String namespace) + { + namespaceToServices.remove(namespace); } } 1.16 +2 -2 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDHandler.java Index: WSDDHandler.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDHandler.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- WSDDHandler.java 28 Jan 2002 18:23:00 -0000 1.15 +++ WSDDHandler.java 12 Feb 2002 17:18:28 -0000 1.16 @@ -120,7 +120,7 @@ } public void deployToRegistry(WSDDDeployment deployment) - throws WSDDException { - deployment.deployHandler(this); + { + deployment.addHandler(this); } } 1.39 +45 -2 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java Index: WSDDService.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDService.java,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- WSDDService.java 8 Feb 2002 22:57:19 -0000 1.38 +++ WSDDService.java 12 Feb 2002 17:18:28 -0000 1.39 @@ -86,6 +86,9 @@ private Vector faultFlows = new Vector(); private Vector typeMappings = new Vector(); + /** Which namespaces should auto-dispatch to this service? */ + private Vector namespaces = new Vector(); + private String descriptionURL; private SOAPService cachedService = null; @@ -126,6 +129,13 @@ new WSDDBeanMapping(beanMappingElements[i]); typeMappings.add(mapping); } + + Element [] namespaceElements = getChildElements(e, "namespace"); + for (int i = 0; i < namespaceElements.length; i++) { + // Register a namespace for this service + String ns = XMLUtils.getChildCharacterData(namespaceElements[i]); + namespaces.add(ns); + } String typeStr = e.getAttribute("provider"); if (typeStr != null && !typeStr.equals("")) @@ -185,6 +195,16 @@ faultFlows.toArray(t); return t; } + + /** + * Obtain the list of namespaces registered for this service + * @return a Vector of namespaces (Strings) which should dispatch to + * this service + */ + public Vector getNamespaces() + { + return namespaces; + } /** * @@ -355,6 +375,12 @@ for (int i=0; i < typeMappings.size(); i++) { ((WSDDTypeMapping) typeMappings.elementAt(i)).writeToContext(context); } + + for (int i=0; i < namespaces.size(); i++ ) { + context.startElement(new QName("", "namespace"), null); + context.writeString((String)namespaces.get(i)); + context.endElement(); + } context.endElement(); } @@ -365,9 +391,26 @@ } public void deployToRegistry(WSDDDeployment registry) - throws WSDDException { - registry.deployService(this); + { + registry.addService(this); + + // Register the name of the service as a valid namespace, just for + // backwards compatibility + registry.registerNamespaceForService(getQName().getLocalPart(), this); + + for (int i = 0; i < namespaces.size(); i++) { + String namespace = (String) namespaces.elementAt(i); + registry.registerNamespaceForService(namespace, this); + } super.deployToRegistry(registry); + } + + public void removeNamespaceMappings(WSDDDeployment registry) + { + for (int i = 0; i < namespaces.size(); i++) { + String namespace = (String) namespaces.elementAt(i); + registry.removeNamespaceMapping(namespace); + } } } 1.7 +0 -1 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTargetedChain.java Index: WSDDTargetedChain.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTargetedChain.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- WSDDTargetedChain.java 29 Jan 2002 11:23:48 -0000 1.6 +++ WSDDTargetedChain.java 12 Feb 2002 17:18:28 -0000 1.7 @@ -234,7 +234,6 @@ } public void deployToRegistry(WSDDDeployment registry) - throws WSDDException { // deploy any named subparts if (requestFlow != null) { 1.19 +2 -2 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTransport.java Index: WSDDTransport.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDTransport.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- WSDDTransport.java 28 Jan 2002 18:23:01 -0000 1.18 +++ WSDDTransport.java 12 Feb 2002 17:18:28 -0000 1.19 @@ -122,8 +122,8 @@ } public void deployToRegistry(WSDDDeployment registry) - throws WSDDException { - registry.deployTransport(this); + { + registry.addTransport(this); super.deployToRegistry(registry); } 1.15 +13 -5 xml-axis/java/src/org/apache/axis/message/BodyBuilder.java Index: BodyBuilder.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/BodyBuilder.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- BodyBuilder.java 26 Jan 2002 02:47:22 -0000 1.14 +++ BodyBuilder.java 12 Feb 2002 17:18:29 -0000 1.15 @@ -63,6 +63,8 @@ import org.apache.axis.Constants; import org.apache.axis.MessageContext; import org.apache.axis.AxisFault; +import org.apache.axis.Handler; +import org.apache.axis.ConfigurationException; import org.apache.axis.encoding.DeserializationContext; import org.apache.axis.utils.JavaUtils; import org.apache.log4j.Category; @@ -110,17 +112,24 @@ Constants.ATTR_ROOT); if ((root != null) && root.equals("0")) isRoot = false; + MessageContext msgContext = context.getMessageContext(); + if (isRoot && - context.getMessageContext().getServiceHandler() == null) { + msgContext.getServiceHandler() == null) { if (category.isDebugEnabled()) { category.debug(JavaUtils.getMessage("dispatching00",namespace)); } try { - context.getMessageContext().setTargetService(namespace); - } catch (AxisFault fault) { - throw new SAXException(fault); + Handler serviceHandler = msgContext. + getAxisEngine(). + getConfig(). + getServiceByNamespaceURI(namespace); + if (serviceHandler != null) + msgContext.setServiceHandler(serviceHandler); + } catch (ConfigurationException e) { + // oh well... } } @@ -128,7 +137,6 @@ * a) have an non-root element, or * b) have a non-RPC service */ - MessageContext msgContext = context.getMessageContext(); if (localName.equals(Constants.ELEM_FAULT) && namespace.equals(Constants.URI_SOAP_ENV)) { 1.9 +3 -1 xml-axis/java/test/encoding/TestBody.java Index: TestBody.java =================================================================== RCS file: /home/cvs/xml-axis/java/test/encoding/TestBody.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TestBody.java 28 Jan 2002 18:23:03 -0000 1.8 +++ TestBody.java 12 Feb 2002 17:18:29 -0000 1.9 @@ -48,8 +48,10 @@ SOAPEnvelope envelope = message.getSOAPPart().getAsSOAPEnvelope(); RPCElement body = (RPCElement) envelope.getFirstBody(); + // This is not necessarily true anymore... + //assertEquals("Namespace does not equal the message context target service.", namespace, msgContext.getTargetService()); + // verify the service is set - assertEquals("Namespace does not equal the message context target service.", namespace, msgContext.getTargetService()); assertEquals("The target is not the same as the message context service handler", target, msgContext.getServiceHandler()); }