From 517609638e03d901d797c993bf8cacbf99d5b37a Mon Sep 17 00:00:00 2001 From: nash Date: Sun, 22 Jun 2008 14:13:35 +0000 Subject: Fix TUSCANY-2418 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@670360 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/binding/ws/axis2/Axis2ServiceProvider.java | 113 ++++++++++++- .../sca/binding/ws/axis2/TuscanyListingAgent.java | 165 +++++++----------- .../itests/QuestionMarkWSDLImportTestCase.java | 96 +++++++++++ .../QuestionMarkWSDLImportTestCaseFIXME.java | 84 ---------- .../itests/QuestionMarkWSDLIncludeTestCase.java | 96 +++++++++++ .../QuestionMarkWSDLIncludeTestCaseFIXME.java | 84 ---------- .../ws/axis2/itests/QuestionMarkWSDLTestCase.java | 10 +- .../sca/binding/ws/axis2/itests/customerdefs.xsd | 27 +++ .../sca/binding/ws/axis2/itests/customerinfo.xsd | 31 ++++ .../axis2/itests/questionmark-import-nested.wsdl | 70 ++++++++ .../ws/axis2/itests/questionmark-import.wsdl | 139 ++++++---------- .../ws/axis2/itests/questionmark-include.wsdl | 184 +++++++++++---------- .../interfacedef/wsdl/xml/WSDLModelResolver.java | 36 +++- .../tuscany/sca/xsd/xml/XSDModelResolver.java | 16 +- 14 files changed, 688 insertions(+), 463 deletions(-) create mode 100644 java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java delete mode 100644 java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCaseFIXME.java create mode 100644 java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java delete mode 100644 java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCaseFIXME.java create mode 100644 java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd create mode 100644 java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd create mode 100644 java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java index df7f339c62..1bfd20e937 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java @@ -27,6 +27,7 @@ import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -38,6 +39,8 @@ import java.util.logging.Logger; import javax.wsdl.Definition; import javax.wsdl.Import; import javax.wsdl.Port; +import javax.wsdl.Types; +import javax.wsdl.extensions.UnknownExtensibilityElement; import javax.wsdl.extensions.soap.SOAPAddress; import javax.wsdl.extensions.soap12.SOAP12Address; import javax.xml.namespace.QName; @@ -85,6 +88,7 @@ import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; import org.apache.tuscany.sca.invocation.Message; import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.policy.PolicySet; @@ -98,12 +102,22 @@ import org.apache.tuscany.sca.runtime.ReferenceParameters; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.apache.tuscany.sca.runtime.RuntimeComponentService; import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.xsd.XSDefinition; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; import org.apache.ws.security.WSSecurityEngineResult; import org.apache.ws.security.handler.WSHandlerConstants; import org.apache.ws.security.handler.WSHandlerResult; import org.osoa.sca.ServiceRuntimeException; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + public class Axis2ServiceProvider { + public static final String IMPORT_TAG = "import"; + public static final String INCLUDE_TAG = "include"; private static final Logger logger = Logger.getLogger(Axis2ServiceProvider.class.getName()); @@ -129,6 +143,21 @@ public class Axis2ServiceProvider { private static final String DEFAULT_QUEUE_CONNECTION_FACTORY = "TuscanyQueueConnectionFactory"; + //Schema element names + public static final String ELEM_SCHEMA = "schema"; + + //Schema URI + public static final String NS_URI_XSD_1999 = "http://www.w3.org/1999/XMLSchema"; + public static final String NS_URI_XSD_2000 = "http://www.w3.org/2000/10/XMLSchema"; + public static final String NS_URI_XSD_2001 = "http://www.w3.org/2001/XMLSchema"; + + //Schema QNames + public static final QName Q_ELEM_XSD_1999 = new QName(NS_URI_XSD_1999, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2000 = new QName(NS_URI_XSD_2000, ELEM_SCHEMA); + public static final QName Q_ELEM_XSD_2001 = new QName(NS_URI_XSD_2001, ELEM_SCHEMA); + public static final List XSD_QNAME_LIST = + Arrays.asList(new QName[] {Q_ELEM_XSD_1999, Q_ELEM_XSD_2000, Q_ELEM_XSD_2001}); + public Axis2ServiceProvider(RuntimeComponent component, AbstractContract contract, WebServiceBinding wsBinding, @@ -290,8 +319,7 @@ public class Axis2ServiceProvider { URI uriPath = new URI(endpointURL); String stringURIPath = uriPath.getPath(); - //[nash] Need a leading slash for WSDL imports to work with ?wsdl - /* + /* [nash] Need a leading slash for WSDL imports to work with ?wsdl // remove any "/" from the start of the path if (stringURIPath.startsWith("/")) { stringURIPath = stringURIPath.substring(1, stringURIPath.length()); @@ -425,6 +453,9 @@ public class Axis2ServiceProvider { } } + // Add schema information to the AxisService (needed for "?xsd=" support) + addSchemas(wsBinding.getWSDLDefinition(), axisService); + // Use the existing WSDL Parameter wsdlParam = new Parameter(WSDLConstants.WSDL_4_J_DEFINITION, null); wsdlParam.setValue(definition); @@ -432,6 +463,12 @@ public class Axis2ServiceProvider { Parameter userWSDL = new Parameter("useOriginalwsdl", "true"); axisService.addParameter(userWSDL); + // Modify schema imports and includes to add "servicename?xsd=" prefix. + // Axis2 does this for schema extensibility elements, but Tuscany has + // overriden the WSDl4J deserializer to create UnknownExtensibilityElement + // elements in place of these. + modifySchemaImportsAndIncludes(definition, name); + // Axis2 1.3 has a bug with returning incorrect values for the port // addresses. To work around this, compute the values here. Parameter modifyAddr = new Parameter("modifyUserWSDLPortAddress", "false"); @@ -447,6 +484,74 @@ public class Axis2ServiceProvider { return axisService; } + private void addSchemas(WSDLDefinition wsdlDef, AxisService axisService) { + for (XSDefinition xsDef : wsdlDef.getXmlSchemas()) { + axisService.addSchema(xsDef.getSchema()); + updateSchemaRefs(xsDef.getSchema(), axisService.getName()); + } + for (WSDLDefinition impDef : wsdlDef.getImportedDefinitions()) { + addSchemas(impDef, axisService); + } + } + + private void updateSchemaRefs(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + String location = extSchema.getSchemaLocation(); + if (location.indexOf(":/") < 0 & location.indexOf("?xsd=") < 0) { + extSchema.setSchemaLocation(name + "?xsd=" + location); + } + updateSchemaRefs(extSchema.getSchema(), name); + } + } + } + + private void modifySchemaImportsAndIncludes(Definition definition, String name){ + // adjust the schema locations in types section + Types types = definition.getTypes(); + if (types != null) { + for (Iterator iter = types.getExtensibilityElements().iterator(); iter.hasNext();) { + Object ext = iter.next(); + if (ext instanceof UnknownExtensibilityElement && + XSD_QNAME_LIST.contains(((UnknownExtensibilityElement)ext).getElementType())) { + changeLocations(((UnknownExtensibilityElement)ext).getElement(), name); + } + } + } + for (Iterator iter = definition.getImports().values().iterator(); iter.hasNext();) { + Vector values = (Vector)iter.next(); + for (Iterator valuesIter = values.iterator(); valuesIter.hasNext();) { + Import wsdlImport = (Import)valuesIter.next(); + modifySchemaImportsAndIncludes(wsdlImport.getDefinition(), name); + } + } + } + + private void changeLocations(Element element, String name) { + NodeList nodeList = element.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + String tagName = nodeList.item(i).getLocalName(); + if (IMPORT_TAG.equals(tagName) || INCLUDE_TAG.equals(tagName)) { + processImport(nodeList.item(i), name); + } + } + } + + private void processImport(Node importNode, String name) { + NamedNodeMap nodeMap = importNode.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Node attribute = nodeMap.item(i); + if (attribute.getNodeName().equals("schemaLocation")) { + String location = attribute.getNodeValue(); + if (location.indexOf(":/") < 0 & location.indexOf("?xsd=") < 0) { + attribute.setNodeValue(name + "?xsd=" + location); + } + } + } + } + private String getPortAddress(Port port) { Object ext = port.getExtensibilityElements().get(0); if (ext instanceof SOAPAddress) { @@ -606,8 +711,8 @@ public class Axis2ServiceProvider { } private void createPolicyHandlers() throws IllegalAccessException, - InstantiationException, - ClassNotFoundException { + InstantiationException, + ClassNotFoundException { if (wsBinding instanceof PolicySetAttachPoint) { PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; PolicyHandler policyHandler = null; diff --git a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java index 8e2e40c753..2342e7f6ef 100644 --- a/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java +++ b/java/sca/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java @@ -58,6 +58,7 @@ import org.apache.axis2.wsdl.WSDLConstants; import org.apache.neethi.Policy; import org.apache.neethi.PolicyRegistry; import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaExternal; /** * A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work @@ -86,6 +87,68 @@ public class TuscanyListingAgent extends ListingAgent { return serviceName; } + /** + * Override ?xsd processing so that WSDL documents with XSD imports + * and includes work correctly. When we move to Axis2 1.4, we may + * be able to use SchemaSupplier to do this in a cleaner way. + */ + @Override + public void processListService(HttpServletRequest req, + HttpServletResponse res) + throws IOException, ServletException { + + String url = req.getRequestURL().toString(); + String query = req.getQueryString(); + int xsd = query.indexOf("xsd"); + if (xsd >= 0) { + String serviceName = extractServiceName(url); + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + Object serviceObj = services.get(serviceName); + if (serviceObj != null) { + String xsds = req.getParameter("xsd"); + if (xsds != null && !"".equals(xsds)) { + // a schema name (perhaps with path) is present + AxisService axisService = (AxisService)serviceObj; + ArrayList schemas = axisService.getSchema(); + for (Object rootSchema : axisService.getSchema()) { + XmlSchema schema = getSchema(((XmlSchema)rootSchema), xsds); + if (schema != null) { + // found the schema + res.setContentType("text/xml"); + OutputStream out = res.getOutputStream(); + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + return; + } + } + } + } + } + } + // in all other cases, delegate to the Axis2 code + super.processListService(req, res); + } + + private XmlSchema getSchema(XmlSchema parentSchema, String name) { + for (Iterator iter = parentSchema.getIncludes().getIterator(); iter.hasNext();) { + Object obj = iter.next(); + if (obj instanceof XmlSchemaExternal) { + XmlSchemaExternal extSchema = (XmlSchemaExternal)obj; + if (extSchema.getSchemaLocation().endsWith(name)) { + return extSchema.getSchema(); + } else { + XmlSchema schema = getSchema(extSchema.getSchema(), name); + if (schema != null) { + return schema; + } + } + } + } + return null; + } + private String findAxisServiceName(String path) { HashMap services = configContext.getAxisConfiguration().getServices(); if (services == null) { @@ -130,106 +193,4 @@ public class TuscanyListingAgent extends ListingAgent { } } - private String extractHostAndPort(String filePart, boolean isHttp) { - int ipindex = filePart.indexOf("//"); - String ip = null; - if (ipindex >= 0) { - ip = filePart.substring(ipindex + 2, filePart.length()); - int seperatorIndex = ip.indexOf(":"); - int slashIndex = ip.indexOf("/"); - String port; - if (seperatorIndex >= 0) { - port = ip.substring(seperatorIndex + 1, slashIndex); - ip = ip.substring(0, seperatorIndex); - } else { - ip = ip.substring(0, slashIndex); - port = "80"; - } - if (isHttp) { - configContext.setProperty(RUNNING_PORT, port); - } - } - return ip; - } - - private Policy findPolicy(String id, AxisDescription des) { - - List policyElements = des.getPolicyInclude().getPolicyElements(); - PolicyRegistry registry = des.getPolicyInclude().getPolicyRegistry(); - - Object policyComponent; - - Policy policy = registry.lookup(id); - - if (policy != null) { - return policy; - } - - for (Iterator iterator = policyElements.iterator(); iterator.hasNext();) { - policyComponent = iterator.next(); - - if (policyComponent instanceof Policy) { - // policy found for the id - - if (id.equals(((Policy) policyComponent).getId())) { - return (Policy) policyComponent; - } - } - } - - AxisDescription child; - - for (Iterator iterator = des.getChildren(); iterator.hasNext();) { - child = (AxisDescription) iterator.next(); - policy = findPolicy(id, child); - - if (policy != null) { - return policy; - } - } - - return null; - } - - /** - * Hack to get ?wsdl working with soap 1.2 - * Fixed in Axis2 1.3 - */ - private void patchSOAP12Port(AxisService as) throws AxisFault { - Parameter wsld4jdefinition = as.getParameter(WSDLConstants.WSDL_4_J_DEFINITION); - Definition definition = (Definition) wsld4jdefinition.getValue(); - setPortAddress(definition, null, as); - } - - /** - * This is a copy of the AxisService setPortAddress patched to work with SOAP 1.2 Addresses - * Fixed in Axis2 1.3 - */ - private void setPortAddress(Definition definition, String requestIP, AxisService axisService) throws AxisFault { - Iterator serviceItr = definition.getServices().values().iterator(); - while (serviceItr.hasNext()) { - Service serviceElement = (Service) serviceItr.next(); - Iterator portItr = serviceElement.getPorts().values().iterator(); - while (portItr.hasNext()) { - Port port = (Port) portItr.next(); - List list = port.getExtensibilityElements(); - for (int i = 0; i < list.size(); i++) { - Object extensibilityEle = list.get(i); - String locationURI = null; - if (requestIP == null) { - locationURI = axisService.getEPRs()[0]; - } else { -// can't do this as the method's not visible, but Tuscany doesn't use this path anyway -// locationURI = axisService.getEPRs(requestIP)[0]); - } - if (extensibilityEle instanceof SOAPAddress) { - ((SOAPAddress) extensibilityEle).setLocationURI(locationURI); - } else if (extensibilityEle instanceof SOAP12Address) { - ((SOAP12Address) extensibilityEle).setLocationURI(locationURI); - } - } - } - } - } - } diff --git a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java new file mode 100644 index 0000000000..bfccb62cc7 --- /dev/null +++ b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCase.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.axis2.transport.http.server.HttpUtils; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev$ $Date$ + */ +public class QuestionMarkWSDLImportTestCase extends TestCase { + + private SCADomain domain; + + /** + * Tests ?wsdl works and returns the correct port endpoint from the WSDL + */ + public void testWSDLImportPortEndpoint() throws Exception { + InputStream inp = new URL("http://localhost:8086/AccountService?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose", false); + wsdlReader.setFeature("javax.wsdl.importDocuments", true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8086/AccountService?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://account2/AccountService/$promoted$.ep1", "AccountService")); + Port port = service.getPort("AccountSoapPort"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":8086/AccountService", endpoint); + } + + private String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-import.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCaseFIXME.java b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCaseFIXME.java deleted file mode 100644 index 6ecba4782a..0000000000 --- a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLImportTestCaseFIXME.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -package org.apache.tuscany.sca.binding.ws.axis2.itests; - -import java.util.List; - -import javax.wsdl.Definition; -import javax.wsdl.Port; -import javax.wsdl.Service; -import javax.wsdl.extensions.soap.SOAPAddress; -import javax.wsdl.factory.WSDLFactory; -import javax.wsdl.xml.WSDLReader; -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - -import org.apache.axis2.transport.http.server.HttpUtils; -import org.apache.tuscany.sca.host.embedded.SCADomain; - -/** - * Test ?wsdl works and that the returned WSDL has the correct endpoint - * - * @version $Rev$ $Date$ - */ -public class QuestionMarkWSDLImportTestCaseFIXME extends TestCase { - - private SCADomain domain; - - /** - * Tests ?wsdl works and returns the correct port endpoint from the WSDL - */ - public void testWSDLImportPortEndpoint() throws Exception { - WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); - wsdlReader.setFeature("javax.wsdl.verbose", false); - wsdlReader.setFeature("javax.wsdl.importDocuments", true); - - Definition definition = wsdlReader.readWSDL("http://localhost:8086/AccountService?wsdl"); - assertNotNull(definition); - Service service = definition.getService(new QName("http://account2", "AccountService")); - Port port = service.getPort("AccountSoapPort"); - - String endpoint = getEndpoint(port); - String ip = HttpUtils.getIpAddress(); - assertEquals("http://" + ip + ":8086/AccountService", endpoint); - } - - private String getEndpoint(Port port) { - List wsdlPortExtensions = port.getExtensibilityElements(); - for (final Object extension : wsdlPortExtensions) { - if (extension instanceof SOAPAddress) { - return ((SOAPAddress) extension).getLocationURI(); - } - } - throw new RuntimeException("no SOAPAddress"); - } - - @Override - protected void setUp() throws Exception { - domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-import.composite"); - } - - @Override - protected void tearDown() throws Exception { - domain.close(); - } - -} diff --git a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java new file mode 100644 index 0000000000..aa54316660 --- /dev/null +++ b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCase.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +package org.apache.tuscany.sca.binding.ws.axis2.itests; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.axis2.transport.http.server.HttpUtils; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned WSDL has the correct endpoint + * + * @version $Rev: 660340 $ $Date: 2008-05-27 01:08:32 +0100 (Tue, 27 May 2008) $ + */ +public class QuestionMarkWSDLIncludeTestCase extends TestCase { + + private SCADomain domain; + + /** + * Tests ?wsdl works and returns the correct port endpoint from the WSDL + */ + public void testWSDLIncludePortEndpoint() throws Exception { + InputStream inp = new URL("http://localhost:8085/AccountService?wsdl").openStream(); + BufferedReader br = new BufferedReader(new InputStreamReader(inp)); + String line; + while((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose", false); + wsdlReader.setFeature("javax.wsdl.importDocuments", true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/AccountService?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://accounts/AccountService/$promoted$.ep1", "AccountService")); + Port port = service.getPort("AccountSoapPort"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":8085/AccountService", endpoint); + } + + private String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-include.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCaseFIXME.java b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCaseFIXME.java deleted file mode 100644 index 6a0ab74135..0000000000 --- a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLIncludeTestCaseFIXME.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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. - */ - -package org.apache.tuscany.sca.binding.ws.axis2.itests; - -import java.util.List; - -import javax.wsdl.Definition; -import javax.wsdl.Port; -import javax.wsdl.Service; -import javax.wsdl.extensions.soap.SOAPAddress; -import javax.wsdl.factory.WSDLFactory; -import javax.wsdl.xml.WSDLReader; -import javax.xml.namespace.QName; - -import junit.framework.TestCase; - -import org.apache.axis2.transport.http.server.HttpUtils; -import org.apache.tuscany.sca.host.embedded.SCADomain; - -/** - * Test ?wsdl works and that the returned WSDL has the correct endpoint - * - * @version $Rev: 660340 $ $Date: 2008-05-27 01:08:32 +0100 (Tue, 27 May 2008) $ - */ -public class QuestionMarkWSDLIncludeTestCaseFIXME extends TestCase { - - private SCADomain domain; - - /** - * Tests ?wsdl works and returns the correct port endpoint from the WSDL - */ - public void testWSDLIncludePortEndpoint() throws Exception { - WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); - wsdlReader.setFeature("javax.wsdl.verbose", false); - wsdlReader.setFeature("javax.wsdl.importDocuments", true); - - Definition definition = wsdlReader.readWSDL("http://localhost:8085/AccountService?wsdl"); - assertNotNull(definition); - Service service = definition.getService(new QName("http://accounts", "AccountService")); - Port port = service.getPort("AccountSoapPort"); - - String endpoint = getEndpoint(port); - String ip = HttpUtils.getIpAddress(); - assertEquals("http://" + ip + ":8085/AccountService", endpoint); - } - - private String getEndpoint(Port port) { - List wsdlPortExtensions = port.getExtensibilityElements(); - for (final Object extension : wsdlPortExtensions) { - if (extension instanceof SOAPAddress) { - return ((SOAPAddress) extension).getLocationURI(); - } - } - throw new RuntimeException("no SOAPAddress"); - } - - @Override - protected void setUp() throws Exception { - domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl-include.composite"); - } - - @Override - protected void tearDown() throws Exception { - domain.close(); - } - -} diff --git a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java index 2b62c3b013..ac9da19119 100644 --- a/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java +++ b/java/sca/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java @@ -45,7 +45,6 @@ import org.apache.tuscany.sca.host.embedded.SCADomain; */ public class QuestionMarkWSDLTestCase extends TestCase { - private static boolean newGenerator = true; private SCADomain domain; /** @@ -59,6 +58,7 @@ public class QuestionMarkWSDLTestCase extends TestCase { System.out.println(line); } br.close(); + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); wsdlReader.setFeature("javax.wsdl.verbose",false); wsdlReader.setFeature("javax.wsdl.importDocuments",true); @@ -85,16 +85,16 @@ public class QuestionMarkWSDLTestCase extends TestCase { System.out.println(line); } br.close(); + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); wsdlReader.setFeature("javax.wsdl.verbose",false); wsdlReader.setFeature("javax.wsdl.importDocuments",true); Definition definition = wsdlReader.readWSDL("http://localhost:8085/foo/bar?wsdl"); assertNotNull(definition); - Service service = definition.getService(new QName( - "http://itests.axis2.ws.binding.sca.tuscany.apache.org" + (newGenerator ? "/" : ""), - newGenerator ? "HelloWorldService" : "HelloWorld")); - Port port = service.getPort(newGenerator ? "HelloWorldPort" : "HelloWorldSOAP11port_http"); + Service service = definition.getService(new QName("http://itests.axis2.ws.binding.sca.tuscany.apache.org/", + "HelloWorldService")); + Port port = service.getPort("HelloWorldPort"); String endpoint = getEndpoint(port); String ip = HttpUtils.getIpAddress(); diff --git a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd new file mode 100644 index 0000000000..ec67b84851 --- /dev/null +++ b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerdefs.xsd @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd new file mode 100644 index 0000000000..7c903c6394 --- /dev/null +++ b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/customerinfo.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + diff --git a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl new file mode 100644 index 0000000000..41a491361f --- /dev/null +++ b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import-nested.wsdl @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl index e57163e6c4..99a8c6d81d 100644 --- a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl +++ b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-import.wsdl @@ -1,90 +1,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl index 4000568977..80e4b62801 100644 --- a/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl +++ b/java/sca/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-include.wsdl @@ -1,90 +1,94 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java b/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java index 9581f78980..0004774afa 100644 --- a/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java +++ b/java/sca/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java @@ -282,6 +282,9 @@ public class WSDLModelResolver implements ModelResolver { // Lookup a definition for the given namespace String namespace = ((WSDLDefinition)unresolved).getNamespace(); + if (namespace == null) { + return modelClass.cast(unresolved); + } List list = map.get(namespace); WSDLDefinition resolved = aggregate(list); if (resolved != null && !resolved.isUnresolved()) { @@ -352,12 +355,40 @@ public class WSDLModelResolver implements ModelResolver { reader.setFeature("javax.wsdl.importDocuments", true); // FIXME: We need to decide if we should disable the import processing by WSDL4J // reader.setFeature("javax.wsdl.importDocuments", false); - reader.setExtensionRegistry(wsdlExtensionRegistry); + reader.setExtensionRegistry(wsdlExtensionRegistry); // use a custom registry WSDLLocatorImpl locator = new WSDLLocatorImpl(artifactURL, is); Definition definition = reader.readWSDL(locator); wsdlDef.setDefinition(definition); + // If this definition imports any definitions from other namespaces, + // set the correct WSDLDefinition import relationships. + for (Map.Entry> entry : + ((Map>)definition.getImports()).entrySet()) { + if (!entry.getKey().equals(definition.getTargetNamespace())) { + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); + wsdlDefinition.setUnresolved(true); + wsdlDefinition.setNamespace(entry.getKey()); + WSDLDefinition resolved = resolveModel(WSDLDefinition.class, wsdlDefinition); + if (!resolved.isUnresolved()) { + for (javax.wsdl.Import imp : entry.getValue()) { + if (resolved.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) { + // this WSDLDefinition contains the imported document + wsdlDef.getImportedDefinitions().add(resolved); + } else { + // this is a facade, so look in its imported definitions + for (WSDLDefinition def : resolved.getImportedDefinitions()) { + if (def.getDefinition().getDocumentBaseURI().equals(imp.getDefinition().getDocumentBaseURI())) { + wsdlDef.getImportedDefinitions().add(def); + break; + } + } + } + } + } + } + } + //Read inline schemas readInlineSchemas(wsdlDef, definition); } catch (WSDLException e) { @@ -427,6 +458,9 @@ public class WSDLModelResolver implements ModelResolver { contribution.getModelResolver().resolveModel(XSDefinition.class, xsDefinition); if (resolved != null && !resolved.isUnresolved()) { if (!wsdlDefinition.getXmlSchemas().contains(resolved)) { + // Don't add resolved because it may be an aggregate that + // contains more than we need. The resolver will have + // set the specific schema we need into unresolved. wsdlDefinition.getXmlSchemas().add(xsDefinition); } } diff --git a/java/sca/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java b/java/sca/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java index 42b34c7acc..652d9e8d83 100644 --- a/java/sca/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java +++ b/java/sca/modules/xsd-xml/src/main/java/org/apache/tuscany/sca/xsd/xml/XSDModelResolver.java @@ -87,11 +87,13 @@ public class XSDModelResolver implements ModelResolver { // Lookup a definition for the given namespace String namespace = definition.getNamespace(); List list = map.get(namespace); + XSDefinition modelXSD = null; if (list != null && definition.getDocument() != null) { // Set the document for the inline schema int index = list.indexOf(definition); - if (index != -1) { - list.get(index).setDocument(definition.getDocument()); + if (index != -1) { // a matching (not identical) document was found + modelXSD = list.get(index); + modelXSD.setDocument(definition.getDocument()); } } if (list == null && definition.getDocument() != null) { @@ -107,6 +109,14 @@ public class XSDModelResolver implements ModelResolver { throw new ContributionRuntimeException(e); } if (resolved != null && !resolved.isUnresolved()) { + if (definition.isUnresolved() && definition.getSchema() == null && modelXSD != null) { + // Update the unresolved model with schema information and mark it + // resolved. This information in the unresolved model is needed when + // this method is called by WSDLModelResolver.readInlineSchemas(). + definition.setSchema(modelXSD.getSchema()); + definition.setSchemaCollection(modelXSD.getSchemaCollection()); + definition.setUnresolved(false); + } return modelClass.cast(resolved); } @@ -221,7 +231,7 @@ public class XSDModelResolver implements ModelResolver { java.lang.String schemaLocation, java.lang.String baseUri) { try { - if (schemaLocation == null || schemaLocation.startsWith("/")) { + if (schemaLocation == null) { return null; } URL url = null; -- cgit v1.2.3