cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject git commit: [CXF-5744] CHeck for XmlTransient annotation on Exception.getMessage methods
Date Fri, 01 Aug 2014 15:53:29 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 25671bd28 -> c0198033b


[CXF-5744] CHeck for XmlTransient annotation on Exception.getMessage methods


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

Branch: refs/heads/master
Commit: c0198033bda06efa135ae47bab65a427c3534cb1
Parents: 25671bd
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Aug 1 11:52:30 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Aug 1 11:53:02 2014 -0400

----------------------------------------------------------------------
 .../apache/cxf/jaxb/JAXBSchemaInitializer.java  | 24 ++++++--
 .../cxf/tools/fortest/exception/Echo4.java      | 26 +++++++++
 .../exception/TransientMessageException.java    | 60 ++++++++++++++++++++
 .../processor/JavaToProcessorTest.java          | 60 +++++++++++++++++++-
 4 files changed, 163 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c0198033/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 f48cc06..e413963 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;
@@ -583,12 +584,7 @@ class JAXBSchemaInitializer extends ServiceModelVisitor {
         }
         // Create element in xsd:sequence for Exception.class
         if (Exception.class.isAssignableFrom(cls)) {
-            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);
+            addExceptionMessage(cls, schema, seq);
         }
         
         if (propertyOrder != null) {
@@ -609,6 +605,22 @@ 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)) {
+                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/c0198033/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo4.java
----------------------------------------------------------------------
diff --git a/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo4.java
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo4.java
new file mode 100644
index 0000000..678f6f6
--- /dev/null
+++ b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/Echo4.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 Echo4 {
+    String echo(String request) throws TransientMessageException;
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/c0198033/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/TransientMessageException.java
----------------------------------------------------------------------
diff --git a/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/TransientMessageException.java
b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/TransientMessageException.java
new file mode 100644
index 0000000..c1204f6
--- /dev/null
+++ b/tools/javato/ws/src/test/java/org/apache/cxf/tools/fortest/exception/TransientMessageException.java
@@ -0,0 +1,60 @@
+/**
+ * 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.XmlTransient;
+
+/**
+ * 
+ */
+public class TransientMessageException extends Exception {
+    private static final long serialVersionUID = 1L;
+    int idCode;
+    
+    public TransientMessageException() {
+    }
+    public TransientMessageException(int i) {
+        idCode = i;
+    }
+    
+    public TransientMessageException(int i, String message) {
+        super(message);
+        idCode = i;
+    }
+
+    public TransientMessageException(Throwable cause) {
+        super(cause);
+    }
+
+    public TransientMessageException(String message, Throwable cause) {
+        super(message, cause);
+    }
+    @XmlTransient
+    public String getMessage() {
+        return super.getMessage();
+    }
+    
+    public int getIDCode() {
+        return idCode;
+    }
+    public void setIDCode(int i) {
+        idCode = i;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/c0198033/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 bcbe202..a08a158 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
@@ -21,6 +21,7 @@ package org.apache.cxf.tools.java2wsdl.processor;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.StringWriter;
 import java.net.URI;
 import java.util.HashMap;
 import java.util.List;
@@ -29,20 +30,28 @@ import java.util.Map;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
 import javax.wsdl.Service;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
-
 import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.XPathUtils;
+import org.apache.cxf.jaxb.JAXBEncoderDecoder;
+import org.apache.cxf.service.model.FaultInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.cxf.tools.common.ProcessorTestBase;
 import org.apache.cxf.tools.common.ToolConstants;
 import org.apache.cxf.tools.common.ToolContext;
+import org.apache.cxf.tools.fortest.exception.TransientMessageException;
 import org.apache.cxf.tools.java2ws.JavaToWS;
 import org.apache.cxf.tools.wsdlto.core.DataBindingProfile;
 import org.apache.cxf.tools.wsdlto.core.FrontEndProfile;
@@ -926,4 +935,53 @@ public class JavaToProcessorTest extends ProcessorTestBase {
         //if the test works, this won't throw an exception.  CXF-4877 generated bad XML at
this point
         StaxUtils.read(new FileInputStream(wsdlFile));
     }
+    
+    @Test
+    public void testTransientMessage() throws Exception {
+        //CXF-5744
+        env.put(ToolConstants.CFG_OUTPUTFILE, output.getPath() + "/transient_message.wsdl");
+        env.put(ToolConstants.CFG_CLASSNAME, "org.apache.cxf.tools.fortest.exception.Echo4");
+        env.put(ToolConstants.CFG_VERBOSE, ToolConstants.CFG_VERBOSE);
+        try {
+            processor.setEnvironment(env);
+            processor.process();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        
+        File wsdlFile = new File(output, "transient_message.wsdl");
+        assertTrue(wsdlFile.exists());
+        
+        Document doc = StaxUtils.read(wsdlFile);
+        //StaxUtils.print(doc);
+        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/");
+        map.put("tns", "http://cxf.apache.org/test/HelloService");
+        XPathUtils util = new XPathUtils(map);
+
+        String path = "//xsd:complexType[@name='TransientMessageException']//xsd:sequence/xsd:element[@name='message']";
+        Element nd = (Element)util.getValueNode(path, doc);
+        assertNull(nd);
+        
+        //ok, we didn't map it into the schema.  Make sure the runtime won't write it out.
+        List<ServiceInfo> sl = CastUtils.cast((List<?>)env.get("serviceList"));
+        FaultInfo mi = sl.get(0).getInterface().getOperation(new QName("http://cxf.apache.org/test/HelloService",
+                                                                       "echo"))
+            .getFault(new QName("http://cxf.apache.org/test/HelloService",
+                                "TransientMessageException"));
+        MessagePartInfo mpi = mi.getMessagePart(0);
+        JAXBContext ctx = JAXBContext.newInstance(String.class, Integer.TYPE);
+        StringWriter sw = new StringWriter();
+        XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(sw);
+        TransientMessageException tme = new TransientMessageException(12, "Exception Message");
+        Marshaller ms = ctx.createMarshaller();
+        ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
+        JAXBEncoderDecoder.marshallException(ms, tme, mpi, writer);
+        writer.flush();
+        writer.close();
+        assertEquals(-1, sw.getBuffer().indexOf("Exception Message"));
+    }
+    
 }


Mime
View raw message