cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject [1/2] cxf git commit: [CXF-6089] Reworking the fix to avoid regressions and adding an additional testcase from Rebecca
Date Wed, 12 Nov 2014 11:14:38 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes bb5df0b76 -> 96ba1a16e


[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/a931d1ce
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a931d1ce
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a931d1ce

Branch: refs/heads/2.7.x-fixes
Commit: a931d1ce27f041ddeb84e94ddd36d50968fc904b
Parents: bb5df0b
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Wed Nov 12 10:57:00 2014 +0100
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Wed Nov 12 11:59:01 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/a931d1ce/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 c5d7df5..328f03d 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/a931d1ce/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/a931d1ce/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/a931d1ce/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/a931d1ce/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/a931d1ce/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 425a8ed..325a70c 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");


Mime
View raw message