Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 467a9d933 -> ea6778c36


[CXF-6089] Reworking the fix to avoid regressions and adding an additional 
testcase from Rebecca


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/17b3db58
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/17b3db58
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/17b3db58

Branch: refs/heads/3.0.x-fixes
Commit: 17b3db58966d22f46696c8b852ae510822639550
Parents: 467a9d9
Author: Alessio Soldano <asold...@redhat.com>
Authored: Wed Nov 12 10:57:00 2014 +0100
Committer: Alessio Soldano <asold...@redhat.com>
Committed: Wed Nov 12 11:24:35 2014 +0100

----------------------------------------------------------------------
 .../apache/cxf/jaxb/JAXBSchemaInitializer.java  | 24 ++++++++-
 .../cxf/tools/fortest/exception/Echo5.java      | 26 ++++++++++
 .../cxf/tools/fortest/exception/Echo5Impl.java  | 33 +++++++++++++
 .../tools/fortest/exception/MyException2.java   | 52 ++++++++++++++++++++
 .../exception/NonTransientMessageException.java | 44 +++++++++++++++++
 .../processor/JavaToProcessorTest.java          | 45 +++++++++++++++++
 6 files changed, 223 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/17b3db58/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
----------------------------------------------------------------------
diff --git 
a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
 
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
index 0e344d2..dbaefcf 100644
--- 
a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
+++ 
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
@@ -42,6 +42,7 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorOrder;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlList;
+import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -581,7 +582,11 @@ class JAXBSchemaInitializer extends ServiceModelVisitor {
                 }
             }
         }
-
+        // Create element in xsd:sequence for Exception.class
+        if (Exception.class.isAssignableFrom(cls)) {
+            addExceptionMessage(cls, schema, seq);
+        }
+        
         if (propertyOrder != null) {
             if (propertyOrder.length == seq.getItems().size()) {
                 sortItems(seq, propertyOrder);
@@ -600,6 +605,23 @@ class JAXBSchemaInitializer extends ServiceModelVisitor {
         schemas.addCrossImports();
         part.setProperty(JAXBDataBinding.class.getName() + 
".CUSTOM_EXCEPTION", Boolean.TRUE);
     }
+    private void addExceptionMessage(Class<?> cls, XmlSchema schema, 
XmlSchemaSequence seq) {
+        try {
+            //a subclass could mark the message method as transient
+            Method m = cls.getMethod("getMessage");
+            if (!m.isAnnotationPresent(XmlTransient.class)
+                && m.getDeclaringClass().equals(Throwable.class)) {
+                JAXBBeanInfo beanInfo = getBeanInfo(java.lang.String.class);
+                XmlSchemaElement exEle = new XmlSchemaElement(schema, false);
+                exEle.setName("message");
+                exEle.setSchemaTypeName(getTypeName(beanInfo));
+                exEle.setMinOccurs(0);
+                seq.getItems().add(exEle);
+            }
+        } catch (Exception e) {
+            //ignore, just won't have the message element
+        }
+    }
     
     private boolean generateGenericType(Type type) {
         if (type instanceof ParameterizedType) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/17b3db58/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5.java
----------------------------------------------------------------------
diff --git 
a/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5.java
 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5.java
new file mode 100644
index 0000000..424d043
--- /dev/null
+++ 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5.java
@@ -0,0 +1,26 @@
+/**
+ * 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.exception;
+
+import javax.jws.WebService;
+
+@WebService(targetNamespace = "http://cxf.apache.org/test/HelloService";, name 
= "HelloService")
+public interface Echo5 {
+    String echo(String request) throws MyException2;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/17b3db58/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5Impl.java
----------------------------------------------------------------------
diff --git 
a/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5Impl.java
 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5Impl.java
new file mode 100644
index 0000000..ba05ae7
--- /dev/null
+++ 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo5Impl.java
@@ -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.exception;
+
+import javax.jws.WebService;
+
+@WebService(serviceName = "HelloService",
+    portName = "HelloPort",
+    endpointInterface = "org.apache.cxf.tools.fortest.exception.Echo5",
+    targetNamespace = "http://cxf.apache.org/test/HelloService";)
+public class Echo5Impl {
+    public String echo(String request) throws MyException2 {
+        return "Response";
+
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/17b3db58/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException2.java
----------------------------------------------------------------------
diff --git 
a/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException2.java
 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException2.java
new file mode 100644
index 0000000..a47ca5e
--- /dev/null
+++ 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/MyException2.java
@@ -0,0 +1,52 @@
+/**
+ * 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.exception;
+
+import javax.xml.bind.annotation.XmlType;
+
+@javax.xml.ws.WebFault
+@XmlType(namespace = "http://cxf.apache.org/test/HelloService";,
+    name = "MyException2",
+    propOrder = { "summary", "from", "id", "message" })
+public class MyException2 extends NonTransientMessageException {
+    private static final long serialVersionUID = 8575109064272599936L;
+    private String summary;
+    private String from;
+
+    public MyException2(String message) {
+        super(message);
+    }
+
+    public void setSummary(String summary) {
+        this.summary = summary;
+    }
+
+    public void setFrom(String from) {
+        this.from = from;
+    }
+
+    public String getSummary() {
+        return summary;
+    }
+
+    public String getFrom() {
+        return from;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/17b3db58/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/NonTransientMessageException.java
----------------------------------------------------------------------
diff --git 
a/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/NonTransientMessageException.java
 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/NonTransientMessageException.java
new file mode 100644
index 0000000..41f4526
--- /dev/null
+++ 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/NonTransientMessageException.java
@@ -0,0 +1,44 @@
+/**
+ * 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.exception;
+
+/**
+ *
+ */
+public class NonTransientMessageException extends Exception {
+    private static final long serialVersionUID = 1L;
+    private int id;
+
+    public NonTransientMessageException(String message) {
+        super(message);
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public String getMessage() {
+        return super.getMessage();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cxf/blob/17b3db58/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
----------------------------------------------------------------------
diff --git 
a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
index a08a158..6f25a64 100644
--- 
a/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
+++ 
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/java2wsdl/processor/JavaToProcessorTest.java
@@ -783,6 +783,51 @@ public class JavaToProcessorTest extends ProcessorTestBase 
{
     }
     
     @Test
+    public void testPropOrderInException2() throws Exception {
+        env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + 
"/exception_prop_order2.wsdl");
+        //env.put(ToolConstants.CFG_OUTPUTFILE, 
"/x1/tmp/exception_prop_order.wsdl");
+        env.put(ToolConstants.CFG_CLASSNAME, 
"org.apache.cxf.tools.fortest.exception.Echo5Impl");
+        env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+        try {
+            processor.setEnvironment(env);
+            processor.process();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        File wsdlFile = new File(output, "exception_prop_order2.wsdl");
+        assertTrue(wsdlFile.exists());
+
+        Document doc = StaxUtils.read(wsdlFile);
+        Map<String, String> map = new HashMap<String, String>();
+        map.put("xsd", "http://www.w3.org/2001/XMLSchema";);
+        map.put("wsdl", "http://schemas.xmlsoap.org/wsdl/";);
+        map.put("soap", "http://schemas.xmlsoap.org/wsdl/soap/";);
+        XPathUtils util = new XPathUtils(map);
+
+        Element summary = 
(Element)util.getValueNode("//xsd:element[@name='summary']", doc);
+        Element from = 
(Element)util.getValueNode("//xsd:element[@name='from']", doc);
+        Element id = (Element)util.getValueNode("//xsd:element[@name='id']", 
doc);
+        assertNotNull(summary);
+        assertNotNull(from);
+        assertNotNull(id);
+
+        Node nd = summary.getNextSibling();
+        while (nd != null) {
+            if (nd == from) {
+                from = null;
+            } else if (nd == id) {
+                if (from != null) {
+                    fail("id before from");
+                }
+                id = null;
+            }
+            nd = nd.getNextSibling();
+        }
+        assertNull(id);
+        assertNull(from);
+    }
+
+    @Test
     public void testXmlAccessorOrderInException() throws Exception {
         env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + 
"/exception_order.wsdl");
         env.put(ToolConstants.CFG_CLASSNAME, 
"org.apache.cxf.tools.fortest.exception.OrderEchoImpl");

Reply via email to