Author: ema
Date: Thu Sep 29 07:32:52 2011
New Revision: 1177188
URL: http://svn.apache.org/viewvc?rev=1177188&view=rev
Log:
[CXF-1519]:Repspect @XmlType annotation in exceptoin class
Added:
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/Endpoint.java
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/EndpointImpl.java
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/UserException.java
Modified:
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Modified:
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=1177188&r1=1177187&r2=1177188&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
(original)
+++
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
Thu Sep 29 07:32:52 2011
@@ -34,6 +34,7 @@ import javax.xml.bind.JAXBContext;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlList;
+import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
@@ -448,8 +449,8 @@ class JAXBSchemaInitializer extends Serv
}
}
}
-
-
+
+
private void buildExceptionType(MessagePartInfo part, Class<?> cls) {
SchemaInfo schemaInfo = null;
for (SchemaInfo s : serviceInfo.getSchemas()) {
@@ -458,44 +459,53 @@ class JAXBSchemaInitializer extends Serv
break;
}
}
- XmlSchema schema;
+ XmlType xmlTypeAnno = cls.getAnnotation(XmlType.class);
+ boolean respectXmlTypeNS = false;
+ XmlSchema faultBeanSchema = null;
+ if (xmlTypeAnno != null && !xmlTypeAnno.namespace().isEmpty()
+ &&
!xmlTypeAnno.namespace().equals(part.getElementQName().getNamespaceURI())) {
+ respectXmlTypeNS = true;
+ NamespaceMap nsMap = new NamespaceMap();
+ nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX,
xmlTypeAnno.namespace());
+ nsMap.add(WSDLConstants.NP_SCHEMA_XSD,
WSDLConstants.NS_SCHEMA_XSD);
+
+ SchemaInfo faultBeanSchemaInfo =
createSchemaIfNeeded(xmlTypeAnno.namespace(), nsMap);
+ faultBeanSchema = faultBeanSchemaInfo.getSchema();
+ }
+
+ XmlSchema schema = null;
if (schemaInfo == null) {
- schema =
schemas.newXmlSchemaInCollection(part.getElementQName().getNamespaceURI());
-
- if (qualifiedSchemas) {
- schema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
- }
-
NamespaceMap nsMap = new NamespaceMap();
- nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX,
schema.getTargetNamespace());
+ nsMap.add(WSDLConstants.CONVENTIONAL_TNS_PREFIX,
part.getElementQName().getNamespaceURI());
nsMap.add(WSDLConstants.NP_SCHEMA_XSD,
WSDLConstants.NS_SCHEMA_XSD);
- schema.setNamespaceContext(nsMap);
+ schemaInfo =
createSchemaIfNeeded(part.getElementQName().getNamespaceURI(), nsMap);
-
- schemaInfo = new
SchemaInfo(part.getElementQName().getNamespaceURI());
- schemaInfo.setSchema(schema);
- serviceInfo.addSchema(schemaInfo);
- } else {
- schema = schemaInfo.getSchema();
- }
+ }
+ schema = schemaInfo.getSchema();
+
// Before updating everything, make sure we haven't added this
// type yet. Multiple methods that throw the same exception
// types will cause duplicates.
- String partLocalName = part.getElementQName().getLocalPart();
- XmlSchemaType existingType = schema.getTypeByName(partLocalName);
+ String faultTypeName = xmlTypeAnno != null &&
!xmlTypeAnno.name().isEmpty() ? xmlTypeAnno.name()
+ : part.getElementQName().getLocalPart();
+ XmlSchemaType existingType = schema.getTypeByName(faultTypeName);
if (existingType != null) {
return;
}
- XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
- ct.setName(partLocalName);
-
XmlSchemaElement el = new XmlSchemaElement(schema, true);
- el.setName(partLocalName);
+ el.setName(part.getElementQName().getLocalPart());
part.setXmlSchema(el);
-
schemaInfo.setElement(null);
+
+ if (respectXmlTypeNS) {
+ schema = faultBeanSchema; //create complexType in the new created
schema for xmlType
+ }
+
+ XmlSchemaComplexType ct = new XmlSchemaComplexType(schema, true);
+ ct.setName(faultTypeName);
+
el.setSchemaTypeName(ct.getQName());
XmlSchemaSequence seq = new XmlSchemaSequence();
@@ -542,6 +552,7 @@ class JAXBSchemaInitializer extends Serv
seq.getItems().add(exEle);
}
+ schemas.addCrossImports();
part.setProperty(JAXBDataBinding.class.getName() +
".CUSTOM_EXCEPTION", Boolean.TRUE);
}
@@ -591,7 +602,24 @@ class JAXBSchemaInitializer extends Serv
seq.getItems().add(el);
}
+
+ private SchemaInfo createSchemaIfNeeded(String namespace, NamespaceMap
nsMap) {
+ SchemaInfo schemaInfo = serviceInfo.getSchema(namespace);
+ if (schemaInfo == null) {
+ XmlSchema xmlSchema = schemas.newXmlSchemaInCollection(namespace);
+ if (qualifiedSchemas) {
+ xmlSchema.setElementFormDefault(XmlSchemaForm.QUALIFIED);
+ }
+
+ xmlSchema.setNamespaceContext(nsMap);
+
+ schemaInfo = new SchemaInfo(namespace);
+ schemaInfo.setSchema(xmlSchema);
+ serviceInfo.addSchema(schemaInfo);
+ }
+ return schemaInfo;
+ }
private boolean isExistSchemaElement(XmlSchema schema, QName qn) {
return schema.getElementByName(qn) != null;
Added:
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/Endpoint.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/Endpoint.java?rev=1177188&view=auto
==============================================================================
---
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/Endpoint.java
(added)
+++
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/Endpoint.java
Thu Sep 29 07:32:52 2011
@@ -0,0 +1,28 @@
+/**
+ * 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.cxf.tools.fortest.cxf1519;
+
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
+@WebService(name = "Endpoint", targetNamespace =
"http://cxf.apache.org/cxf1519")
+public interface Endpoint {
+ String echo(String input) throws UserException;
+}
Added:
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/EndpointImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/EndpointImpl.java?rev=1177188&view=auto
==============================================================================
---
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/EndpointImpl.java
(added)
+++
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/EndpointImpl.java
Thu Sep 29 07:32:52 2011
@@ -0,0 +1,33 @@
+/**
+ * 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.cxf.tools.fortest.cxf1519;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+
+@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
+@WebService(name = "Endpoint", serviceName = "EndpointService",
+ targetNamespace = "http://cxf.apache.org/cxf1519")
+public class EndpointImpl implements Endpoint {
+ @WebMethod
+ public String echo(String input) throws UserException {
+ return input;
+ }
+}
Added:
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/UserException.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/UserException.java?rev=1177188&view=auto
==============================================================================
---
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/UserException.java
(added)
+++
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/cxf1519/UserException.java
Thu Sep 29 07:32:52 2011
@@ -0,0 +1,39 @@
+/**
+ * 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.cxf.tools.fortest.cxf1519;
+
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.ws.WebFault;
+
+@WebFault(name = "UserExceptionFault", targetNamespace =
"http://cxf.apache.org/cxf1519/faults")
+@XmlType(name = "UserException",
+ namespace = "http://cxf.apache.org/cxf1519/exceptions",
+ propOrder = { "message" }
+)
+public class UserException extends Exception {
+ private String message;
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+}
Modified:
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java?rev=1177188&r1=1177187&r2=1177188&view=diff
==============================================================================
---
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
(original)
+++
cxf/trunk/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
Thu Sep 29 07:32:52 2011
@@ -654,4 +654,28 @@ public class JavaToProcessorTest extends
assertTrue(wsdlContent.indexOf("<soap:fault name=\"Exception\"
use=\"literal\"/>") != -1);
}
+
+ //CXF-1509
+ @Test
+ public void testWebFaultWithXmlType() throws Exception {
+ env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() +
"/cxf1519.wsdl");
+ env.put(ToolConstants.CFG_CLASSNAME,
"org.apache.cxf.tools.fortest.cxf1519.EndpointImpl");
+ env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+ try {
+ processor.setEnvironment(env);
+ processor.process();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ File wsdlFile = new File(output, "cxf1519.wsdl");
+ assertTrue(wsdlFile.exists());
+ // schema element
+ String wsdlContent = getStringFromFile(wsdlFile).replaceAll(" ", " ");
+
assertTrue(wsdlContent.indexOf("xmlns:tns=\"http://cxf.apache.org/cxf1519/exceptions\"")
!= -1);
+
assertTrue(wsdlContent.indexOf("xmlns:tns=\"http://cxf.apache.org/cxf1519/faults\"")
!= -1);
+ assertTrue(wsdlContent.indexOf("<xsd:complexType
name=\"UserException\">") != -1);
+ assertTrue(wsdlContent.indexOf("<xsd:element
name=\"UserExceptionFault\"") != -1);
+
+ }
}