You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2012/03/31 01:53:38 UTC
svn commit: r1307655 - in /cxf/trunk:
rt/core/src/main/java/org/apache/cxf/wsdl11/
rt/core/src/test/java/org/apache/cxf/wsdl11/
rt/core/src/test/resources/org/apache/cxf/wsdl11/
rt/frontend/simple/src/main/java/org/apache/cxf/frontend/ systests/jaxws/s...
Author: dkulp
Date: Fri Mar 30 23:53:37 2012
New Revision: 1307655
URL: http://svn.apache.org/viewvc?rev=1307655&view=rev
Log:
[CXF-4196] Allow and endpoint to expose wsdl using schema imports
Patch from Jason Pell applied
Added:
cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl (with props)
Modified:
cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java
cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterNoWsdlTest.java
cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeterNoWsdl.java
Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?rev=1307655&r1=1307654&r2=1307655&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java Fri Mar 30 23:53:37 2012
@@ -63,6 +63,7 @@ import org.w3c.dom.Element;
import org.apache.cxf.Bus;
import org.apache.cxf.common.WSDLConstants;
import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.service.model.AbstractMessageContainer;
import org.apache.cxf.service.model.AbstractPropertiesHolder;
@@ -96,7 +97,7 @@ import org.apache.ws.commons.schema.XmlS
* the top-level object.
*/
public class ServiceWSDLBuilder {
-
+
private final Map<String, String> ns2prefix;
private Definition definition;
private final List<ServiceInfo> services;
@@ -195,7 +196,12 @@ public class ServiceWSDLBuilder {
portTypes.add(buildPortType(service.getInterface(), portTypeDef));
if (service.getSchemas() != null && service.getSchemas().size() > 0) {
- buildTypes(service.getSchemas(), imports, portTypeDef);
+ if (!useSchemaImports) {
+ buildTypes(service.getSchemas(), imports, portTypeDef);
+ } else {
+ buildTypesWithSchemaImports(service.getSchemas(),
+ imports, portTypeDef);
+ }
}
}
@@ -297,104 +303,177 @@ public class ServiceWSDLBuilder {
final Definition def) {
Types types = def.createTypes();
- Document doc = null;
- try {
- doc = XMLUtils.newDocument();
- } catch (ParserConfigurationException e) {
- throw new RuntimeException("DOM configuration problem", e);
- }
- Element nd = XMLUtils.createElementNS(doc, new QName(WSDLConstants.NS_SCHEMA_XSD,
- "schema"));
- nd.setAttribute("xmlns", WSDLConstants.NS_SCHEMA_XSD);
- doc.appendChild(nd);
-
for (SchemaInfo schemaInfo : schemas) {
-
- if (!useSchemaImports) {
- Schema schemaImpl = getSchemaImplementation(def);
- schemaImpl.setRequired(true);
- schemaImpl.setElementType(WSDLConstants.QNAME_SCHEMA);
- schemaImpl.setElement(schemaInfo.getElement());
- for (XmlSchemaExternal ext : schemaInfo.getSchema().getExternals()) {
- if (ext.getSchema() == null) {
- continue;
+ Schema schemaImpl = getSchemaImplementation(def);
+ schemaImpl.setRequired(true);
+ schemaImpl.setElementType(WSDLConstants.QNAME_SCHEMA);
+ schemaImpl.setElement(schemaInfo.getElement());
+ for (XmlSchemaExternal ext : schemaInfo.getSchema().getExternals()) {
+ if (ext.getSchema() == null) {
+ continue;
+ }
+ if (ext instanceof XmlSchemaImport) {
+ SchemaImport imp = schemaImpl.createImport();
+ imp.setNamespaceURI(((XmlSchemaImport)ext).getNamespace());
+ imp.setSchemaLocationURI(((XmlSchemaImport)ext).getSchemaLocation());
+
+ Schema schemaImpl2 = getSchemaImplementation(def);
+ schemaImpl2.setRequired(true);
+ schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
+ schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
+ try {
+ schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
+ } catch (XmlSchemaSerializerException e) {
+ //ignore
+ }
+ imp.setReferencedSchema(schemaImpl2);
+
+ schemaImpl.addImport(imp);
+ } else if (ext instanceof XmlSchemaInclude) {
+ SchemaReference imp = schemaImpl.createInclude();
+ imp.setSchemaLocationURI(((XmlSchemaInclude)ext).getSchemaLocation());
+
+ Schema schemaImpl2 = getSchemaImplementation(def);
+ schemaImpl2.setRequired(true);
+ schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
+ schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
+ try {
+ schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
+ } catch (XmlSchemaSerializerException e) {
+ //ignore
}
- if (ext instanceof XmlSchemaImport) {
- SchemaImport imp = schemaImpl.createImport();
- imp.setNamespaceURI(((XmlSchemaImport)ext).getNamespace());
- imp.setSchemaLocationURI(((XmlSchemaImport)ext).getSchemaLocation());
-
- Schema schemaImpl2 = getSchemaImplementation(def);
- schemaImpl2.setRequired(true);
- schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
- schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
- try {
- schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
- } catch (XmlSchemaSerializerException e) {
- //ignore
- }
- imp.setReferencedSchema(schemaImpl2);
-
- schemaImpl.addImport(imp);
- } else if (ext instanceof XmlSchemaInclude) {
- SchemaReference imp = schemaImpl.createInclude();
- imp.setSchemaLocationURI(((XmlSchemaInclude)ext).getSchemaLocation());
-
- Schema schemaImpl2 = getSchemaImplementation(def);
- schemaImpl2.setRequired(true);
- schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
- schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
- try {
- schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
- } catch (XmlSchemaSerializerException e) {
- //ignore
- }
- imp.setReferencedSchema(schemaImpl2);
-
- schemaImpl.addInclude(imp);
- } else if (ext instanceof XmlSchemaRedefine) {
- SchemaReference imp = schemaImpl.createRedefine();
- imp.setSchemaLocationURI(((XmlSchemaRedefine)ext).getSchemaLocation());
-
- Schema schemaImpl2 = getSchemaImplementation(def);
- schemaImpl2.setRequired(true);
- schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
- schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
- try {
- schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
- } catch (XmlSchemaSerializerException e) {
- //ignore
- }
- imp.setReferencedSchema(schemaImpl2);
-
- schemaImpl.addRedefine(imp);
+ imp.setReferencedSchema(schemaImpl2);
+
+ schemaImpl.addInclude(imp);
+ } else if (ext instanceof XmlSchemaRedefine) {
+ SchemaReference imp = schemaImpl.createRedefine();
+ imp.setSchemaLocationURI(((XmlSchemaRedefine)ext).getSchemaLocation());
+
+ Schema schemaImpl2 = getSchemaImplementation(def);
+ schemaImpl2.setRequired(true);
+ schemaImpl2.setElementType(WSDLConstants.QNAME_SCHEMA);
+ schemaImpl2.setDocumentBaseURI(ext.getSchema().getSourceURI());
+ try {
+ schemaImpl2.setElement(ext.getSchema().getSchemaDocument().getDocumentElement());
+ } catch (XmlSchemaSerializerException e) {
+ //ignore
}
+ imp.setReferencedSchema(schemaImpl2);
+
+ schemaImpl.addRedefine(imp);
}
- types.addExtensibilityElement(schemaImpl);
- } else {
- //imports
- String name = baseFileName + "_schema" + (++xsdCount) + ".xsd";
- Element imp = XMLUtils.createElementNS(doc,
- new QName(WSDLConstants.NS_SCHEMA_XSD,
- "import"));
- imp.setAttribute("schemaLocation", name);
- imp.setAttribute("namespace", schemaInfo.getNamespaceURI());
- nd.appendChild(imp);
-
- imports.put(name, schemaInfo);
}
+ types.addExtensibilityElement(schemaImpl);
+ }
+ def.setTypes(types);
+ }
+
+ /**
+ * @param schemas
+ * @param imports
+ * @param def
+ */
+ protected void buildTypesWithSchemaImports(final Collection<SchemaInfo> schemas,
+ final Map<String, SchemaInfo> imports, final Definition def) {
+
+ Types types = def.createTypes();
+
+ Map<String, Schema> namespaceToSchemaMap = new HashMap<String, Schema>();
+ Map<String, SchemaInfo> namespaceToSchemaInfo = new HashMap<String, SchemaInfo>();
+
+ for (SchemaInfo schemaInfo : schemas) {
+ Schema schema = getSchemaImplementation(def);
+ schema.setRequired(true);
+ schema.setElementType(WSDLConstants.QNAME_SCHEMA);
+
+ String name = baseFileName + "_schema" + (++xsdCount) + ".xsd";
+ schema.setDocumentBaseURI(name);
+
+
+ try {
+ schema.setElement(schemaInfo.getSchema().getSchemaDocument().getDocumentElement());
+ } catch (XmlSchemaSerializerException e) {
+ //ignore
+ }
+
+ namespaceToSchemaMap.put(schemaInfo.getNamespaceURI(), schema);
+ namespaceToSchemaInfo.put(schemaInfo.getNamespaceURI(), schemaInfo);
+
+ imports.put(name, schemaInfo);
+ }
+
+ for (Schema schema : namespaceToSchemaMap.values()) {
+ Element docElement = schema.getElement();
+
+ List<Element> elementList = DOMUtils
+ .findAllElementsByTagNameNS(docElement, "http://www.w3.org/2001/XMLSchema", "import");
+
+ for (Element el : elementList) {
+ String sn = el.getAttribute("namespace");
+ Schema referencedSchema = namespaceToSchemaMap.get(sn);
+ if (referencedSchema != null) {
+ SchemaInfo schemaInfo = namespaceToSchemaInfo.get(sn);
+
+ el.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
+
+ addSchemaImport(schema, schemaInfo, referencedSchema);
+ }
+ }
}
- if (useSchemaImports) {
- Schema schemaImpl = getSchemaImplementation(def);
- schemaImpl.setRequired(true);
- schemaImpl.setElementType(WSDLConstants.QNAME_SCHEMA);
- schemaImpl.setElement(nd);
- types.addExtensibilityElement(schemaImpl);
+
+ Document doc = createDocument();
+ Element nd = XMLUtils.createElementNS(doc, new QName(WSDLConstants.NS_SCHEMA_XSD, "schema"));
+ nd.setAttribute("xmlns", WSDLConstants.NS_SCHEMA_XSD);
+ doc.appendChild(nd);
+
+ Schema schema = getSchemaImplementation(def);
+ schema.setRequired(true);
+ schema.setElementType(WSDLConstants.QNAME_SCHEMA);
+
+ Collection<String> defNamespaces = CastUtils.cast(def.getNamespaces().values());
+
+ for (SchemaInfo schemaInfo : schemas) {
+ Schema referencedSchema = namespaceToSchemaMap.get(schemaInfo.getNamespaceURI());
+
+ // this ensures only the schemas directly referenced by the wsdl are included.
+ if (defNamespaces.contains(schemaInfo.getNamespaceURI())) {
+ Element impElement = XMLUtils.createElementNS(doc, new QName(WSDLConstants.NS_SCHEMA_XSD,
+ "import"));
+
+ impElement.setAttribute("schemaLocation", referencedSchema.getDocumentBaseURI());
+ impElement.setAttribute("namespace", schemaInfo.getNamespaceURI());
+ nd.appendChild(impElement);
+
+ addSchemaImport(schema, schemaInfo, referencedSchema);
+ }
}
+
+ schema.setElement(nd);
+ types.addExtensibilityElement(schema);
+
def.setTypes(types);
}
+ private Document createDocument() {
+ Document doc = null;
+ try {
+ doc = XMLUtils.newDocument();
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException("DOM configuration problem", e);
+ }
+ return doc;
+ }
+
+ private void addSchemaImport(Schema schema, SchemaInfo schemaInfo, Schema referencedSchema) {
+ SchemaImport imp = schema.createImport();
+ imp.setId(schemaInfo.getSystemId());
+ imp.setNamespaceURI(schemaInfo.getNamespaceURI());
+ imp.setSchemaLocationURI(referencedSchema.getDocumentBaseURI());
+ imp.setReferencedSchema(referencedSchema);
+ schema.addImport(imp);
+ }
+
protected void buildBinding(Collection<BindingInfo> bindingInfos, Collection<PortType> portTypes) {
Binding binding = null;
for (BindingInfo bindingInfo : bindingInfos) {
Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java?rev=1307655&r1=1307654&r2=1307655&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java (original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/wsdl11/ServiceWSDLBuilderTest.java Fri Mar 30 23:53:37 2012
@@ -19,7 +19,11 @@
package org.apache.cxf.wsdl11;
+import java.io.ByteArrayOutputStream;
import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.logging.Logger;
import javax.wsdl.Binding;
@@ -35,17 +39,22 @@ import javax.wsdl.Service;
import javax.wsdl.Types;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.schema.Schema;
+import javax.wsdl.extensions.schema.SchemaImport;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.apache.cxf.Bus;
import org.apache.cxf.binding.BindingFactoryManager;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.transport.DestinationFactory;
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.cxf.wsdl.WSDLManager;
@@ -53,6 +62,7 @@ import org.apache.ws.commons.schema.XmlS
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.easymock.EasyMock;
import org.easymock.IMocksControl;
+
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
@@ -62,6 +72,7 @@ public class ServiceWSDLBuilderTest exte
private static final Logger LOG = LogUtils.getLogger(ServiceWSDLBuilderTest.class);
private static final String WSDL_PATH = "hello_world.wsdl";
private static final String NO_BODY_PARTS_WSDL_PATH = "no_body_parts.wsdl";
+ private static final String WSDL_XSD_IMPORT_PATH = "hello_world_schema_import_test.wsdl";
private Definition def;
private Definition newDef;
@@ -77,6 +88,10 @@ public class ServiceWSDLBuilderTest exte
private DestinationFactory destinationFactory;
private void setupWSDL(String wsdlPath) throws Exception {
+ setupWSDL(wsdlPath, false);
+ }
+
+ private void setupWSDL(String wsdlPath, boolean doXsdImports) throws Exception {
String wsdlUrl = getClass().getResource(wsdlPath).toString();
LOG.info("the path of wsdl file is " + wsdlUrl);
WSDLFactory wsdlFactory = WSDLFactory.newInstance();
@@ -110,7 +125,10 @@ public class ServiceWSDLBuilderTest exte
control.replay();
serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
- newDef = new ServiceWSDLBuilder(bus, serviceInfo).build();
+ ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, serviceInfo);
+ builder.setUseSchemaImports(doXsdImports);
+ builder.setBaseFileName("HelloWorld");
+ newDef = builder.build(new HashMap<String, SchemaInfo>());
}
@After
@@ -307,4 +325,53 @@ public class ServiceWSDLBuilderTest exte
);
}
+ @Test
+ public void testXsdImportMultipleSchemas() throws Exception {
+ setupWSDL(WSDL_XSD_IMPORT_PATH, true);
+
+ Types types = newDef.getTypes();
+ assertNotNull(types);
+
+ Collection<ExtensibilityElement> schemas = CastUtils.cast(types.getExtensibilityElements(),
+ ExtensibilityElement.class);
+ assertEquals(1, schemas.size());
+
+ Schema schema = (Schema)schemas.iterator().next();
+
+ assertEquals(1, schema.getImports().values().size());
+
+ SchemaImport serviceTypesSchemaImport = getImport(schema.getImports(),
+ "http://apache.org/hello_world_soap_http/servicetypes");
+
+ Schema serviceTypesSchema = serviceTypesSchemaImport.getReferencedSchema();
+
+ assertEquals(1, serviceTypesSchema.getImports().values().size());
+ SchemaImport typesSchemaImport = getImport(serviceTypesSchema.getImports(),
+ "http://apache.org/hello_world_soap_http/types");
+
+ Schema typesSchema = typesSchemaImport.getReferencedSchema();
+
+ Document doc = typesSchema.getElement().getOwnerDocument();
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(outputStream, "utf-8");
+ StaxUtils.writeNode(doc, writer, true);
+ writer.close();
+
+ // this is a test to make sure any embedded namespaces are properly included
+ String savedSchema = new String(outputStream.toByteArray(), "UTF-8");
+ assertTrue(savedSchema.contains("http://www.w3.org/2005/05/xmlmime"));
+
+ SchemaImport types2SchemaImport = getImport(typesSchema.getImports(),
+ "http://apache.org/hello_world_soap_http/types2");
+
+ Schema types2Schema = types2SchemaImport.getReferencedSchema();
+ assertNotNull(types2Schema);
+ }
+
+ private SchemaImport getImport(Map<?, ?> imps, String key) {
+ List<SchemaImport> s1 = CastUtils.cast((List<?>)imps.get(key));
+ return s1.get(0);
+ }
+
}
Added: cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl?rev=1307655&view=auto
==============================================================================
--- cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl (added)
+++ cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl Fri Mar 30 23:53:37 2012
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<wsdl:definitions name="HelloWorld"
+ targetNamespace="http://apache.org/hello_world_soap_http" xmlns="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://apache.org/hello_world_soap_http"
+ xmlns:x1="http://apache.org/hello_world_soap_http/servicetypes"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+ <wsdl:types>
+
+ <xsd:schema targetNamespace="http://apache.org/hello_world_soap_http/types2"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://apache.org/hello_world_soap_http/types2"
+ elementFormDefault="qualified">
+
+ <xsd:simpleType name="MyStringType">
+ <xsd:restriction base="xsd:string">
+ <xsd:maxLength value="30" />
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:schema>
+
+ <xsd:schema targetNamespace="http://apache.org/hello_world_soap_http/types"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://apache.org/hello_world_soap_http/types"
+ xmlns:t2="http://apache.org/hello_world_soap_http/types2"
+ elementFormDefault="qualified">
+
+ <xsd:import namespace="http://apache.org/hello_world_soap_http/types2" />
+
+ <xsd:complexType name="ResponseType">
+ <xsd:sequence>
+ <xsd:element name="responseType" type="t2:MyStringType" />
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="File">
+ <xsd:sequence>
+ <xsd:element xmlns:xmime="http://www.w3.org/2005/05/xmlmime"
+ name="content" xmime:expectedContentTypes="application/octet-stream"
+ type="xsd:base64Binary" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:schema>
+
+ <xsd:schema targetNamespace="http://apache.org/hello_world_soap_http/servicetypes"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:tns="http://apache.org/hello_world_soap_http/servicetypes"
+ xmlns:s2="http://apache.org/hello_world_soap_http/types"
+ elementFormDefault="qualified">
+
+ <xsd:import namespace="http://apache.org/hello_world_soap_http/types" />
+
+ <xsd:element name="sayHi">
+ <xsd:complexType />
+ </xsd:element>
+ <xsd:element name="sayHiResponse">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="responseType" type="s2:ResponseType" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="greetMe">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="requestType" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="greetMeResponse">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="responseType" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="greetMeOneWay">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="requestType" type="xsd:string" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="pingMe">
+ <xsd:complexType />
+ </xsd:element>
+ <xsd:element name="pingMeResponse">
+ <xsd:complexType />
+ </xsd:element>
+ <xsd:element name="faultDetail">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="minor" type="xsd:short" />
+ <xsd:element name="major" type="xsd:short" />
+ </xsd:sequence>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ </wsdl:types>
+
+ <wsdl:message name="sayHiRequest">
+ <wsdl:part element="x1:sayHi" name="in" />
+ </wsdl:message>
+ <wsdl:message name="sayHiResponse">
+ <wsdl:part element="x1:sayHiResponse" name="out" />
+ </wsdl:message>
+ <wsdl:message name="greetMeRequest">
+ <wsdl:part element="x1:greetMe" name="in" />
+ </wsdl:message>
+ <wsdl:message name="greetMeResponse">
+ <wsdl:part element="x1:greetMeResponse" name="out" />
+ </wsdl:message>
+ <wsdl:message name="greetMeOneWayRequest">
+ <wsdl:part element="x1:greetMeOneWay" name="in" />
+ </wsdl:message>
+ <wsdl:message name="pingMeRequest">
+ <wsdl:part name="in" element="x1:pingMe" />
+ </wsdl:message>
+ <wsdl:message name="pingMeResponse">
+ <wsdl:part name="out" element="x1:pingMeResponse" />
+ </wsdl:message>
+ <wsdl:message name="pingMeFault">
+ <wsdl:part name="faultDetail" element="x1:faultDetail" />
+ </wsdl:message>
+
+ <wsdl:portType name="Greeter">
+ <wsdl:operation name="sayHi">
+ <wsdl:input message="tns:sayHiRequest" name="sayHiRequest" />
+ <wsdl:output message="tns:sayHiResponse" name="sayHiResponse" />
+ </wsdl:operation>
+
+ <wsdl:operation name="greetMe">
+ <wsdl:input message="tns:greetMeRequest" name="greetMeRequest" />
+ <wsdl:output message="tns:greetMeResponse" name="greetMeResponse" />
+ </wsdl:operation>
+
+ <wsdl:operation name="greetMeOneWay">
+ <wsdl:input message="tns:greetMeOneWayRequest" name="greetMeOneWayRequest" />
+ </wsdl:operation>
+
+ <wsdl:operation name="pingMe">
+ <wsdl:input name="pingMeRequest" message="tns:pingMeRequest" />
+ <wsdl:output name="pingMeResponse" message="tns:pingMeResponse" />
+ <wsdl:fault name="pingMeFault" message="tns:pingMeFault" />
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter">
+ <soap:binding style="document"
+ transport="http://schemas.xmlsoap.org/soap/http" />
+
+ <wsdl:operation name="sayHi">
+ <soap:operation soapAction="" style="document" />
+ <wsdl:input name="sayHiRequest">
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output name="sayHiResponse">
+ <soap:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+
+ <wsdl:operation name="greetMe">
+ <soap:operation soapAction="" style="document" />
+ <wsdl:input name="greetMeRequest">
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output name="greetMeResponse">
+ <soap:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+
+ <wsdl:operation name="greetMeOneWay">
+ <soap:operation soapAction="" style="document" />
+ <wsdl:input name="greetMeOneWayRequest">
+ <soap:body use="literal" />
+ </wsdl:input>
+ </wsdl:operation>
+
+ <wsdl:operation name="pingMe">
+ <soap:operation style="document" />
+ <wsdl:input>
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal" />
+ </wsdl:output>
+ <wsdl:fault name="pingMeFault">
+ <soap:fault name="pingMeFault" use="literal" />
+ </wsdl:fault>
+ </wsdl:operation>
+
+ </wsdl:binding>
+ <wsdl:service name="SOAPService">
+ <wsdl:port binding="tns:Greeter_SOAPBinding" name="SoapPort">
+ <soap:address location="http://localhost:9000/SoapContext/SoapPort" />
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
+
Propchange: cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/core/src/test/resources/org/apache/cxf/wsdl11/hello_world_schema_import_test.wsdl
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java?rev=1307655&r1=1307654&r2=1307655&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java (original)
+++ cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/frontend/WSDLGetUtils.java Fri Mar 30 23:53:37 2012
@@ -44,6 +44,7 @@ import javax.wsdl.extensions.soap.SOAPAd
import javax.wsdl.extensions.soap12.SOAP12Address;
import javax.wsdl.xml.WSDLWriter;
import javax.xml.namespace.QName;
+import javax.xml.transform.dom.DOMSource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -59,6 +60,7 @@ import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.wsdl.WSDLManager;
import org.apache.cxf.wsdl11.ResourceManagerWSDLLocator;
@@ -71,6 +73,7 @@ public class WSDLGetUtils {
public static final String AUTO_REWRITE_ADDRESS = "autoRewriteSoapAddress";
public static final String PUBLISHED_ENDPOINT_URL = "publishedEndpointUrl";
+ public static final String WSDL_CREATE_IMPORTS = "org.apache.cxf.wsdl.create.imports";
private static final String WSDLS_KEY = WSDLGetUtils.class.getName() + ".WSDLs";
private static final String SCHEMAS_KEY = WSDLGetUtils.class.getName() + ".Schemas";
@@ -171,8 +174,16 @@ public class WSDLGetUtils {
}
if (!mp.containsKey("")) {
- Definition def = new ServiceWSDLBuilder(bus,
- endpointInfo.getService()).build();
+ ServiceWSDLBuilder builder =
+ new ServiceWSDLBuilder(bus, endpointInfo.getService());
+
+ builder.setUseSchemaImports(
+ MessageUtils.getContextualBoolean(message, WSDL_CREATE_IMPORTS, false));
+
+ // base file name is ignored if createSchemaImports == false!
+ builder.setBaseFileName(endpointInfo.getService().getName().getLocalPart());
+
+ Definition def = builder.build(new HashMap<String, SchemaInfo>());
mp.put("", def);
updateDefinition(bus, def, mp, smp, base, endpointInfo);
@@ -236,7 +247,13 @@ public class WSDLGetUtils {
bus);
InputSource src = rml.getBaseInputSource();
- doc = StaxUtils.read(src);
+ if (src.getByteStream() != null || src.getCharacterStream() != null) {
+ doc = StaxUtils.read(src);
+ } else { // last resort lets try for the referenced schema itself.
+ // its not thread safe if we use the same document
+ doc = StaxUtils.read(
+ new DOMSource(si.getReferencedSchema().getElement().getOwnerDocument()));
+ }
}
updateDoc(doc, base, mp, smp, message);
Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterNoWsdlTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterNoWsdlTest.java?rev=1307655&r1=1307654&r2=1307655&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterNoWsdlTest.java (original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ClientServerGreeterNoWsdlTest.java Fri Mar 30 23:53:37 2012
@@ -22,6 +22,7 @@ package org.apache.cxf.systest.jaxws;
import java.io.InputStream;
import java.lang.reflect.UndeclaredThrowableException;
import java.net.HttpURLConnection;
+import java.net.URL;
import java.util.HashMap;
import java.util.Map;
@@ -36,6 +37,7 @@ import org.apache.cxf.greeter_control.Gr
import org.apache.cxf.greeter_control.GreeterService;
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.helpers.XPathUtils;
+import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -48,7 +50,17 @@ public class ClientServerGreeterNoWsdlTe
assertTrue("server did not launch correctly",
launchServer(ServerGreeterNoWsdl.class, true));
}
-
+ @Test
+ public void testWSDLImports() throws Exception {
+ URL url = new URL("http://localhost:" + PORT + "/SoapContext/GreeterPort?wsdl");
+ Document doc = StaxUtils.read(url.openStream());
+ Map<String, String> ns = new HashMap<String, String>();
+ ns.put("xsd", "http://www.w3.org/2001/XMLSchema");
+ Node nd = new XPathUtils(ns)
+ .getValueNode("//xsd:import[@namespace='http://cxf.apache.org/greeter_control/types']",
+ doc.getDocumentElement());
+ assertNotNull(nd);
+ }
@Test
public void testInvocation() throws Exception {
Modified: cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeterNoWsdl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeterNoWsdl.java?rev=1307655&r1=1307654&r2=1307655&view=diff
==============================================================================
--- cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeterNoWsdl.java (original)
+++ cxf/trunk/systests/jaxws/src/test/java/org/apache/cxf/systest/jaxws/ServerGreeterNoWsdl.java Fri Mar 30 23:53:37 2012
@@ -19,8 +19,12 @@
package org.apache.cxf.systest.jaxws;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.xml.ws.Endpoint;
+import org.apache.cxf.frontend.WSDLGetUtils;
import org.apache.cxf.greeter_control.GreeterImplNoWsdl;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
@@ -30,7 +34,11 @@ public class ServerGreeterNoWsdl extends
protected void run() {
Object implementor = new GreeterImplNoWsdl();
String address = "http://localhost:" + PORT + "/SoapContext/GreeterPort";
- Endpoint.publish(address, implementor);
+ Endpoint ep = Endpoint.create(implementor);
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put(WSDLGetUtils.WSDL_CREATE_IMPORTS, Boolean.TRUE);
+ ep.setProperties(props);
+ ep.publish(address);
}
public static void main(String[] args) {