You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by da...@apache.org on 2006/10/10 21:58:48 UTC
svn commit: r462535 - in /incubator/cxf/trunk:
api/src/main/java/org/apache/cxf/service/model/
api/src/test/java/org/apache/cxf/service/model/
common/common/src/main/java/org/apache/cxf/helpers/
rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/...
Author: dandiep
Date: Tue Oct 10 12:58:46 2006
New Revision: 462535
URL: http://svn.apache.org/viewvc?view=rev&rev=462535
Log:
Get Wrapped style WSDL generation working and also Types generation working.
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/MessagePartInfo.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/TypeInfo.java
incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/MessagePartInfoTest.java
incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/TypeInfoTest.java
incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties
incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBServiceModelInitializer.java
incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Messages.properties
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ProviderServiceFactoryBean.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/MessagePartInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/MessagePartInfo.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/MessagePartInfo.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/MessagePartInfo.java Tue Oct 10 12:58:46 2006
@@ -59,7 +59,7 @@
public boolean isElement() {
return isElement;
}
- public void setIsElement(boolean b) {
+ public void setElement(boolean b) {
isElement = b;
}
Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/TypeInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/TypeInfo.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/TypeInfo.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/TypeInfo.java Tue Oct 10 12:58:46 2006
@@ -19,22 +19,17 @@
package org.apache.cxf.service.model;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
+import java.util.List;
public class TypeInfo extends AbstractPropertiesHolder {
- private static final Logger LOG = LogUtils.getL7dLogger(TypeInfo.class);
ServiceInfo service;
- Map<String, SchemaInfo> schemas = new ConcurrentHashMap<String, SchemaInfo>(4);
+ List<SchemaInfo> schemas = new ArrayList<SchemaInfo>(4);
public TypeInfo(ServiceInfo serv) {
service = serv;
@@ -44,32 +39,22 @@
return service;
}
- public SchemaInfo addSchema(String namespaceURI) {
- if (namespaceURI == null) {
- throw new NullPointerException(new Message("NAMESPACE.URI.NOT.NULL", LOG).toString());
- }
- if (schemas.containsKey(namespaceURI)) {
- throw new IllegalArgumentException(
- new Message("DUPLICATED.NAMESPACE", LOG, new Object[]{namespaceURI}).toString());
- }
- SchemaInfo schemaInfo = new SchemaInfo(this, namespaceURI);
- addSchema(schemaInfo);
- return schemaInfo;
- }
-
-
public void addSchema(SchemaInfo schemaInfo) {
- schemas.put(schemaInfo.getNamespaceURI(), schemaInfo);
+ schemas.add(schemaInfo);
}
public SchemaInfo getSchema(String namespaceURI) {
- return schemas.get(namespaceURI);
+ for (SchemaInfo s : schemas) {
+ if (s.getNamespaceURI().equals(namespaceURI)) {
+ return s;
+ }
+ }
+ return null;
}
-
public Collection<SchemaInfo> getSchemas() {
- return Collections.unmodifiableCollection(schemas.values());
+ return Collections.unmodifiableCollection(schemas);
}
}
Modified: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/MessagePartInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/MessagePartInfoTest.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/MessagePartInfoTest.java (original)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/MessagePartInfoTest.java Tue Oct 10 12:58:46 2006
@@ -33,7 +33,7 @@
messagePartInfo = new MessagePartInfo(new QName(
"http://apache.org/hello_world_soap_http", "testMessagePart"), null);
- messagePartInfo.setIsElement(true);
+ messagePartInfo.setElement(true);
}
public void tearDown() throws Exception {
Modified: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/TypeInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/TypeInfoTest.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/TypeInfoTest.java (original)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/service/model/TypeInfoTest.java Tue Oct 10 12:58:46 2006
@@ -39,9 +39,10 @@
public void testSchema() throws Exception {
assertEquals(typeInfo.getSchemas().size(), 0);
- typeInfo.addSchema("http://schema1");
+ SchemaInfo schemaInfo = new SchemaInfo(typeInfo, "http://schema1");
+ typeInfo.addSchema(schemaInfo);
assertEquals(typeInfo.getSchemas().size(), 1);
- SchemaInfo schemaInfo = typeInfo.getSchema("dummySchema");
+ schemaInfo = typeInfo.getSchema("dummySchema");
assertNull(schemaInfo);
schemaInfo = typeInfo.getSchema("http://schema1");
assertNotNull(schemaInfo);
@@ -51,34 +52,5 @@
typeInfo.addSchema(schemaInfo);
assertEquals(typeInfo.getSchemas().size(), 2);
assertEquals(typeInfo.getSchema("http://schema2").getNamespaceURI(), "http://schema2");
- }
-
- public void testSchemaTnsNull() throws Exception {
- boolean isNull = false;
- try {
- String tns = null;
- typeInfo.addSchema(tns);
- } catch (NullPointerException e) {
- assertEquals(e.getMessage(), "Namespace URI cannot be null.");
- isNull = true;
- }
- if (!isNull) {
- fail("should get NullPointerException");
- }
-
- boolean duplicatedTns = false;
- try {
- String tns = "http://schema";
- typeInfo.addSchema(tns);
- typeInfo.addSchema(tns);
- } catch (IllegalArgumentException e) {
- assertEquals(e.getMessage(),
- "An schema with namespaceURI [http://schema] already exists in this service");
- duplicatedTns = true;
- }
-
- if (!duplicatedTns) {
- fail("should get IllegalArgumentException");
- }
}
}
Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Tue Oct 10 12:58:46 2006
@@ -36,6 +36,7 @@
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
+import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
@@ -315,5 +316,42 @@
} catch (ParserConfigurationException e) {
throw new RuntimeException("Couldn't find a DOM parser.", e);
}
+ }
+
+ public static String getUniquePrefix(Element el, String ns) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public static String getPrefixRecursive(Element el, String ns) {
+ String prefix = getPrefix(el, ns);
+ if (prefix == null && el.getParentNode() instanceof Element) {
+ prefix = getPrefixRecursive((Element) el.getParentNode(), ns);
+ }
+ return prefix;
+ }
+
+ public static String getPrefix(Element el, String ns) {
+ NamedNodeMap atts = el.getAttributes();
+ for (int i = 0; i < atts.getLength(); i++) {
+ Node node = atts.item(i);
+ String name = node.getNodeName();
+ if (ns.equals(node.getNodeValue())
+ && (name != null && ("xmlns".equals(name) || name.startsWith("xmlns:")))) {
+ return node.getPrefix();
+ }
+ }
+ return null;
+ }
+
+ public static String createNamespace(Element el, String ns) {
+ String p = "ns1";
+ int i = 1;
+ while (getPrefix(el, ns) != null) {
+ p = "ns" + i;
+ i++;
+ }
+ el.setAttribute("xmlns:" + p, ns);
+ return p;
}
}
Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties (original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/Messages.properties Tue Oct 10 12:58:46 2006
@@ -6,4 +6,4 @@
NO_DATAREADER=No DataReader is available for Service: {0}
NO_DATAWRITER=No DataWriter is available for Service: {0}
COULD_NOT_UNRWAP=Could not unrwap message parts.
-REQ_NOT_UNDERSTOOD=Could not read request. Operation is unknown.
\ No newline at end of file
+REQ_NOT_UNDERSTOOD=Could not read request. Operation {0} is unknown.
Modified: incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java (original)
+++ incubator/cxf/trunk/rt/bindings/xml/src/main/java/org/apache/cxf/binding/xml/interceptor/XMLMessageInInterceptor.java Tue Oct 10 12:58:46 2006
@@ -59,7 +59,6 @@
}
public void handleMessage(Message message) throws Fault {
-
XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);
Endpoint ep = message.getExchange().get(Endpoint.class);
@@ -115,7 +114,7 @@
}
}
- throw new Fault(new org.apache.cxf.common.i18n.Message("REQ_NOT_UNDERSTOOD", BUNDLE));
+ throw new Fault(new org.apache.cxf.common.i18n.Message("REQ_NOT_UNDERSTOOD", BUNDLE, startQName));
}
}
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/ServiceWSDLBuilder.java Tue Oct 10 12:58:46 2006
@@ -45,6 +45,7 @@
import javax.wsdl.extensions.ElementExtensible;
import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.factory.WSDLFactory;
+import javax.xml.namespace.QName;
import com.ibm.wsdl.extensions.schema.SchemaImpl;
@@ -66,6 +67,8 @@
public final class ServiceWSDLBuilder {
+ private static final QName SCHEMA_QNAME = new QName("http://www.w3.org/2001/XMLSchema", "schema");
+
private Map<String, String> prefix2ns;
private Map<String, String> ns2prefix;
private Definition definition;
@@ -85,7 +88,10 @@
}
if (definition == null) {
definition = WSDLFactory.newInstance().newDefinition();
-
+ definition.getExtensionRegistry().registerSerializer(Types.class,
+ SCHEMA_QNAME,
+ new SchemaSerializer());
+
addNamespace("wsdlsoap", "http://schemas.xmlsoap.org/wsdl/soap/");
addNamespace("soap", "http://schemas.xmlsoap.org/soap/");
addNamespace("xsd", "http://www.w3.org/2001/XMLSchema");
@@ -133,6 +139,8 @@
Types types = definition.createTypes();
for (SchemaInfo schemaInfo : typeInfo.getSchemas()) {
SchemaImpl schemaImpl = new SchemaImpl();
+ schemaImpl.setRequired(true);
+ schemaImpl.setElementType(SCHEMA_QNAME);
schemaImpl.setElement(schemaInfo.getElement());
types.addExtensibilityElement(schemaImpl);
}
Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/wsdl11/WSDLServiceBuilder.java Tue Oct 10 12:58:46 2006
@@ -486,10 +486,10 @@
MessagePartInfo pi = minfo.addMessagePart(part.getName());
if (part.getTypeName() != null) {
pi.setTypeQName(part.getTypeName());
- pi.setIsElement(false);
+ pi.setElement(false);
} else {
pi.setElementQName(part.getElementName());
- pi.setIsElement(true);
+ pi.setElement(true);
}
}
for (Part part : cast(msg.getParts().values(), Part.class)) {
@@ -497,10 +497,10 @@
MessagePartInfo pi = minfo.addMessagePart(part.getName());
if (part.getTypeName() != null) {
pi.setTypeQName(part.getTypeName());
- pi.setIsElement(false);
+ pi.setElement(false);
} else {
pi.setElementQName(part.getElementName());
- pi.setIsElement(true);
+ pi.setElement(true);
}
}
}
Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Tue Oct 10 12:58:46 2006
@@ -20,6 +20,7 @@
package org.apache.cxf.jaxb;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -30,7 +31,10 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
+import javax.xml.bind.SchemaOutputResolver;
import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.dom.DOMResult;
import org.w3c.dom.Document;
@@ -45,8 +49,10 @@
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.resource.URIResolver;
+import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.service.model.TypeInfo;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
@@ -155,7 +161,50 @@
public void initialize(ServiceInfo serviceInfo) {
JAXBServiceModelInitializer initializer = new JAXBServiceModelInitializer(serviceInfo);
initializer.walk();
+
+ try {
+ TypeInfo typeInfo = serviceInfo.getTypeInfo();
+ if (typeInfo == null) {
+ typeInfo = new TypeInfo(serviceInfo);
+ serviceInfo.setTypeInfo(typeInfo);
+ }
+
+ for (DOMResult r : generateJaxbSchemas()) {
+ Document d = (Document) r.getNode();
+ String ns = d.getDocumentElement().getAttribute("targetNamespace");
+ if (ns == null) {
+ ns = "";
+ }
+
+ // Don't include WS-Addressing bits
+ if ("http://www.w3.org/2005/08/addressing/wsdl".equals(ns)) {
+ continue;
+ }
+
+ SchemaInfo schema = new SchemaInfo(typeInfo, ns);
+ schema.setElement(d.getDocumentElement());
+ }
+ } catch (IOException e) {
+ throw new ServiceConstructionException(new Message("SCHEMA_GEN_EXC", BUNDLE), e);
+ }
}
-
+
+ private List<DOMResult> generateJaxbSchemas() throws IOException {
+ final List<DOMResult> results = new ArrayList<DOMResult>();
+
+ context.generateSchema(new SchemaOutputResolver() {
+ @Override
+ public Result createOutput(String ns, String file) throws IOException {
+ DOMResult result = new DOMResult();
+ result.setSystemId(file);
+
+ results.add(result);
+
+ return result;
+ }
+ });
+
+ return results;
+ }
}
Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBServiceModelInitializer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBServiceModelInitializer.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBServiceModelInitializer.java (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBServiceModelInitializer.java Tue Oct 10 12:58:46 2006
@@ -64,7 +64,7 @@
boolean isElement = typeInfo instanceof ElementInfo;
- part.setIsElement(isElement);
+ part.setElement(isElement);
if (isElement) {
part.setElementQName(typeName);
} else {
Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Messages.properties?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Messages.properties (original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/Messages.properties Tue Oct 10 12:58:46 2006
@@ -3,4 +3,5 @@
UNKNOWN_SOURCE = Marshalling Error, unrecognized source {0}.
MARSHAL_ERROR = Marshalling Error.
UNKNOWN_ELEMENT_NAME = Could not determine the element name for {0}.
-UNKNOWN_PACKAGE_NS = No package info found for class {0}. Cannot lookup default schema namespace.
\ No newline at end of file
+UNKNOWN_PACKAGE_NS = No package info found for class {0}. Cannot lookup default schema namespace.
+SCHEMA_GEN_EXC = Could not generate schemas.
\ No newline at end of file
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java Tue Oct 10 12:58:46 2006
@@ -24,6 +24,7 @@
import java.util.concurrent.Executor;
import java.util.logging.Logger;
+import javax.xml.bind.JAXBException;
import javax.xml.transform.Source;
import javax.xml.validation.Schema;
import javax.xml.ws.Binding;
@@ -37,6 +38,7 @@
import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.jaxb.JAXBDataBinding;
import org.apache.cxf.jaxb.JAXBDataReaderFactory;
import org.apache.cxf.jaxb.JAXBDataWriterFactory;
import org.apache.cxf.jaxws.context.WebContextResourceResolver;
@@ -77,6 +79,11 @@
serviceFactory = new ProviderServiceFactoryBean(implInfo);
} else {
serviceFactory = new JaxWsServiceFactoryBean(implInfo);
+ try {
+ serviceFactory.setDataBinding(new JAXBDataBinding(implInfo.getImplementorClass()));
+ } catch (JAXBException e) {
+ throw new WebServiceException("Could not create databinding.", e);
+ }
}
serviceFactory.setBus(bus);
service = serviceFactory.create();
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ProviderServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ProviderServiceFactoryBean.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ProviderServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/ProviderServiceFactoryBean.java Tue Oct 10 12:58:46 2006
@@ -51,6 +51,7 @@
this.bindingURI = implInfo.getBindingType();
getServiceConfigurations().add(0, new WebServiceProviderConfiguration());
setServiceClass(implInfo.getImplementorClass());
+ setWrapped(false);
}
@Override
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java Tue Oct 10 12:58:46 2006
@@ -27,6 +27,7 @@
import org.w3c.dom.Node;
import org.apache.cxf.Bus;
+import org.apache.cxf.jaxb.JAXBDataBinding;
import org.apache.cxf.jaxws.service.Hello;
import org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean;
import org.apache.cxf.service.Service;
@@ -39,13 +40,50 @@
public class CodeFirstTest extends AbstractJaxWsTest {
String address = "http://localhost:9000/Hello";
- public void testModel() throws Exception {
+ public void testDocLitModel() throws Exception {
+ Definition d = createService(false);
+
+ Document wsdl = WSDLFactory.newInstance().newWSDLWriter().getDocument(d);
+
+ addNamespace("svc", "http://service.jaxws.cxf.apache.org");
+
+ assertValid("/wsdl:definitions/wsdl:service[@name='Hello']", wsdl);
+ assertValid("//wsdl:port/wsdlsoap:address[@location='" + address + "']", wsdl);
+ assertValid("//wsdl:portType[@name='HelloPortType']", wsdl);
+ assertValid("/wsdl:definitions/wsdl:message[@name='sayHi']"
+ + "/wsdl:part[@type='xsd:string'][@name='text']",
+ wsdl);
+ }
+
+ public void testWrappedModel() throws Exception {
+ Definition d = createService(true);
+
+ Document wsdl = WSDLFactory.newInstance().newWSDLWriter().getDocument(d);
+
+ addNamespace("svc", "http://service.jaxws.cxf.apache.org");
+
+ assertValid("/wsdl:definitions/wsdl:service[@name='Hello']", wsdl);
+ assertValid("//wsdl:port/wsdlsoap:address[@location='" + address + "']", wsdl);
+ assertValid("//wsdl:portType[@name='HelloPortType']", wsdl);
+ assertValid("/wsdl:definitions/wsdl:message[@name='sayHi']"
+ + "/wsdl:part[@element='ns1:sayHi'][@name='sayHi']",
+ wsdl);
+ assertValid("/wsdl:definitions/wsdl:message[@name='sayHiResponse']"
+ + "/wsdl:part[@element='ns1:sayHiResponse'][@name='sayHiResponse']",
+ wsdl);
+ assertValid("//xsd:element[@name='sayHi']/xsd:complexType"
+ + "/xsd:sequence/xsd:element[@name='text']",
+ wsdl);
+ }
+
+ private Definition createService(boolean wrapped) throws Exception {
JaxWsServiceFactoryBean bean = new JaxWsServiceFactoryBean();
Bus bus = getBus();
bean.setBus(bus);
bean.setServiceClass(Hello.class);
- bean.setWrapped(false);
+ bean.setWrapped(wrapped);
+ bean.setDataBinding(new JAXBDataBinding(Hello.class));
Service service = bean.create();
@@ -65,17 +103,7 @@
ServiceWSDLBuilder wsdlBuilder =
new ServiceWSDLBuilder(service.getServiceInfo());
Definition d = wsdlBuilder.build();
-
- Document wsdl = WSDLFactory.newInstance().newWSDLWriter().getDocument(d);
-
- addNamespace("svc", "http://service.jaxws.cxf.apache.org");
-
- assertValid("/wsdl:definitions/wsdl:service[@name='Hello']", wsdl);
- assertValid("//wsdl:port/wsdlsoap:address[@location='" + address + "']", wsdl);
- assertValid("//wsdl:portType[@name='HelloPortType']", wsdl);
- assertValid("/wsdl:definitions/wsdl:message[@name='sayHi']"
- + "/wsdl:part[@type='xsd:string'][@name='text']",
- wsdl);
+ return d;
}
public void testEndpoint() throws Exception {
Modified: incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/main/java/org/apache/cxf/service/factory/ReflectionServiceFactoryBean.java Tue Oct 10 12:58:46 2006
@@ -32,11 +32,15 @@
import javax.xml.namespace.QName;
import javax.xml.ws.handler.MessageContext;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.endpoint.EndpointException;
import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.helpers.MethodComparator;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.service.Service;
@@ -51,7 +55,9 @@
import org.apache.cxf.service.model.MessageInfo;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.service.model.TypeInfo;
import org.apache.cxf.service.model.UnwrappedOperationInfo;
import org.apache.cxf.wsdl11.WSDLServiceFactory;
@@ -65,7 +71,8 @@
private static final Logger LOG = Logger.getLogger(ReflectionServiceFactoryBean.class.getName());
private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ReflectionServiceFactoryBean.class);
-
+ private static final String XSD_NS = "http://www.w3.org/2001/XMLSchema";
+
protected URL wsdlURL;
protected Class<?> serviceClass;
@@ -167,10 +174,18 @@
createInterface(serviceInfo);
+ if (wrappedStyle) {
+ initializeWrappedElementNames(serviceInfo);
+ }
+
if (getDataBinding() != null) {
getDataBinding().initialize(serviceInfo);
}
+ if (wrappedStyle) {
+ initializeWrappedSchema(serviceInfo);
+ }
+
setService(service);
}
}
@@ -274,6 +289,93 @@
methodDispatcher.bind(op, m);
return op;
+ }
+
+ private void initializeWrappedElementNames(ServiceInfo serviceInfo) {
+ for (OperationInfo op : serviceInfo.getInterface().getOperations()) {
+ if (op.hasInput()) {
+ setElementNameOnPart(op.getInput());
+ }
+ if (op.hasOutput()) {
+ setElementNameOnPart(op.getOutput());
+ }
+ }
+ }
+
+ private void setElementNameOnPart(MessageInfo m) {
+ List<MessagePartInfo> parts = m.getMessageParts();
+ if (parts.size() == 1) {
+ MessagePartInfo p = parts.get(0);
+ p.setElement(true);
+ p.setElementQName(m.getName());
+ }
+ }
+
+ protected void initializeWrappedSchema(ServiceInfo serviceInfo) {
+ Document d = DOMUtils.createDocument();
+
+ Element schema = d.createElementNS(XSD_NS, "xsd:schema");
+ d.appendChild(schema);
+ schema.setAttribute("targetNamespace", getServiceNamespace());
+
+ for (OperationInfo op : serviceInfo.getInterface().getOperations()) {
+ if (op.hasInput()) {
+ createWrappedMessage(op.getInput(), op.getUnwrappedOperation().getInput(), d, schema);
+ }
+ if (op.hasOutput()) {
+ createWrappedMessage(op.getOutput(), op.getUnwrappedOperation().getOutput(), d, schema);
+ }
+ }
+
+ TypeInfo typeInfo = serviceInfo.getTypeInfo();
+ if (typeInfo == null) {
+ typeInfo = new TypeInfo(serviceInfo);
+ serviceInfo.setTypeInfo(typeInfo);
+ }
+
+ SchemaInfo schemaInfo = new SchemaInfo(typeInfo, getServiceNamespace());
+ schemaInfo.setElement(schema);
+ typeInfo.addSchema(schemaInfo);
+ }
+
+ private void createWrappedMessage(MessageInfo wrappedMessage,
+ MessageInfo unwrappedMessage,
+ Document d,
+ Element schema) {
+ Element el = d.createElementNS(XSD_NS, "xsd:element");
+ el.setAttribute("name", wrappedMessage.getName().getLocalPart());
+ schema.appendChild(el);
+
+ Element ct = d.createElementNS(XSD_NS, "xsd:complexType");
+ el.appendChild(ct);
+
+ Element seq = d.createElementNS(XSD_NS, "xsd:sequence");
+ ct.appendChild(seq);
+
+
+ for (MessagePartInfo mpi : unwrappedMessage.getMessageParts()) {
+ el = d.createElementNS(XSD_NS, "xsd:element");
+ el.setAttribute("name", mpi.getName().getLocalPart());
+ el.setAttribute("minOccurs", "1");
+ el.setAttribute("maxOccurs", "1");
+
+ if (mpi.isElement()) {
+ String ns = mpi.getElementQName().getNamespaceURI();
+ String prefix = DOMUtils.getPrefixRecursive(el, ns);
+ if (prefix == null) {
+ prefix = DOMUtils.createNamespace(schema, ns);
+ }
+ el.setAttribute("ref", prefix + ":" + mpi.getElementQName().getLocalPart());
+ } else {
+ String ns = mpi.getTypeQName().getNamespaceURI();
+ String prefix = DOMUtils.getPrefixRecursive(el, ns);
+ if (prefix == null) {
+ prefix = DOMUtils.createNamespace(schema, ns);
+ }
+ el.setAttribute("type", prefix + ":" + mpi.getTypeQName().getLocalPart());
+ }
+ seq.appendChild(el);
+ }
}
protected void createMessageParts(InterfaceInfo intf, OperationInfo op, Method method) {
Modified: incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java?view=diff&rev=462535&r1=462534&r2=462535
==============================================================================
--- incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/ReflectionServiceFactoryTest.java Tue Oct 10 12:58:46 2006
@@ -75,8 +75,35 @@
extension.registerConduitInitiator("http://schemas.xmlsoap.org/soap/http", localTransport);
}
- public void testReflectionBuild() throws Exception {
- Service service = createService();
+ public void testUnwrappedBuild() throws Exception {
+ Service service = createService(false);
+
+ ServiceInfo si = service.getServiceInfo();
+ InterfaceInfo intf = si.getInterface();
+
+ assertEquals(3, intf.getOperations().size());
+
+ String ns = si.getName().getNamespaceURI();
+ OperationInfo sayHelloOp = intf.getOperation(new QName(ns, "sayHello"));
+ assertNotNull(sayHelloOp);
+
+ assertEquals("sayHello", sayHelloOp.getInput().getName().getLocalPart());
+
+ List<MessagePartInfo> messageParts = sayHelloOp.getInput().getMessageParts();
+ assertEquals(0, messageParts.size());
+
+ // test output
+ messageParts = sayHelloOp.getOutput().getMessageParts();
+ assertEquals(1, messageParts.size());
+ assertEquals("sayHelloResponse", sayHelloOp.getOutput().getName().getLocalPart());
+
+ MessagePartInfo mpi = messageParts.get(0);
+ assertEquals("out", mpi.getName().getLocalPart());
+ assertEquals(String.class, mpi.getProperty(Class.class.getName()));
+ }
+
+ public void testWrappedBuild() throws Exception {
+ Service service = createService(true);
ServiceInfo si = service.getServiceInfo();
InterfaceInfo intf = si.getInterface();
@@ -114,17 +141,18 @@
assertEquals(String.class, mpi.getProperty(Class.class.getName()));
}
- private Service createService() throws JAXBException {
+ private Service createService(boolean wrapped) throws JAXBException {
serviceFactory = new ReflectionServiceFactoryBean();
serviceFactory.setDataBinding(new JAXBDataBinding(HelloService.class));
serviceFactory.setBus(getBus());
serviceFactory.setServiceClass(HelloService.class);
+ serviceFactory.setWrapped(wrapped);
return serviceFactory.create();
}
public void testServerFactoryBean() throws Exception {
- Service service = createService();
+ Service service = createService(true);
ServerFactoryBean svrBean = new ServerFactoryBean();
svrBean.setAddress("http://localhost/Hello");