cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r831408 - in /cxf/trunk: api/src/main/java/org/apache/cxf/interceptor/ rt/core/src/main/java/org/apache/cxf/interceptor/ rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/ rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xml...
Date Fri, 30 Oct 2009 18:05:55 GMT
Author: dkulp
Date: Fri Oct 30 18:05:54 2009
New Revision: 831408

URL: http://svn.apache.org/viewvc?rev=831408&view=rev
Log:
[CXF-2510] Port XmlBeans namespace hack thing from XFire

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
    cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
    cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java
    cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java?rev=831408&r1=831407&r2=831408&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/interceptor/Fault.java Fri Oct 30 18:05:54
2009
@@ -66,6 +66,12 @@
     public Fault(String message, ResourceBundle b, Throwable t) {
         this(new Message(message, b), t);
     }
+    public Fault(String message, Logger log, Throwable t, Object ... params) {
+        this(new Message(message, log, params), t);
+    }
+    public Fault(String message, ResourceBundle b, Throwable t, Object ... params) {
+        this(new Message(message, b, params), t);
+    }
     
     public Fault(Throwable t) {
         super(t);

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java?rev=831408&r1=831407&r2=831408&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java
Fri Oct 30 18:05:54 2009
@@ -167,6 +167,7 @@
         
         writer.setAttachments(atts);
         writer.setProperty(DataWriter.ENDPOINT, message.getExchange().get(Endpoint.class));
+        writer.setProperty(Message.class.getName(), message);
         
         setSchemaOutMessage(service, message, writer);
         return writer;

Modified: cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=831408&r1=831407&r2=831408&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
(original)
+++ cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
Fri Oct 30 18:05:54 2009
@@ -29,12 +29,20 @@
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.validation.Schema;
 
-import org.apache.cxf.common.i18n.Message;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.databinding.DataWriter;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -48,6 +56,7 @@
 public class DataWriterImpl implements DataWriter<XMLStreamWriter> {
     private static final Logger LOG = LogUtils.getLogger(XmlBeansDataBinding.class);
     private Schema schema;
+    private Message message;
     
     public DataWriterImpl() {
     }
@@ -78,7 +87,7 @@
                             obj = meth.invoke(null, obj);
                             break;
                         } catch (Exception e) {
-                            throw new Fault(new Message("UNMARSHAL_ERROR", LOG, part.getTypeClass()),
e);
+                            throw new Fault("UNMARSHAL_ERROR", LOG, e, part.getTypeClass());
                         }
                     }
                 }
@@ -91,6 +100,40 @@
                 if (schema != null) {
                     options.setValidateOnSet();
                 }
+                if (message != null 
+                    && MessageUtils.getContextualBoolean(message, 
+                                                      XmlBeansDataBinding.XMLBEANS_NAMESPACE_HACK,

+                                                      false)) {
+                    Object dom;
+                    if (obj instanceof XmlObjectBase) {
+                        XmlObjectBase source = (XmlObjectBase)obj;
+                        dom = source.newDomNode(options);
+                    } else {
+                        XmlTokenSource source = (XmlTokenSource)obj;
+                        dom = source.newDomNode(options);
+                    }
+                    
+                    if (dom instanceof Document) {
+                        org.w3c.dom.Element e = ((Document)dom).getDocumentElement();
+                        StaxUtils.copy(e, output);
+                    } else if (dom instanceof DocumentFragment) {
+                        DocumentFragment frag = (DocumentFragment) dom;
+                        Node node = frag.getFirstChild();
+                        while (node != null) {
+                            if (node instanceof Element) {
+                                StaxUtils.copy((Element)node, output);
+                            } else if (node instanceof Comment) {
+                                output.writeComment(((Comment)node).getData());
+                            } else if (node instanceof Text) {
+                                output.writeCharacters(((Text)node).getData());
+                            }
+                            node = node.getNextSibling();
+                        }
+                    } else {
+                        throw new Fault("Invalid document type returned: " + dom.toString(),
LOG);
+                    }
+                }
+                
                 XMLStreamReader reader;
                 if (obj instanceof XmlObjectBase) {
                     XmlObjectBase source = (XmlObjectBase)obj;
@@ -129,7 +172,7 @@
                 output.writeEndElement();
             }
         } catch (XMLStreamException e) {
-            throw new Fault(new Message("MARSHAL_ERROR", LOG, obj), e);
+            throw new Fault("MARSHAL_ERROR", LOG, e, obj);
         }
     }
 
@@ -145,6 +188,9 @@
     }
 
     public void setProperty(String key, Object value) {
+        if (Message.class.getName().equals(key)) {
+            message = (Message)value;
+        }
     }
 
     public void setSchema(Schema schema) {

Modified: cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java?rev=831408&r1=831407&r2=831408&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java
(original)
+++ cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java
Fri Oct 30 18:05:54 2009
@@ -52,6 +52,10 @@
  * 
  */
 public class XmlBeansDataBinding extends AbstractDataBinding implements WrapperCapableDatabinding
{
+    public static final String XMLBEANS_NAMESPACE_HACK
+        = XmlBeansDataBinding.class.getName() + ".NamespaceHack";
+    
+    
     private static final Logger LOG = LogUtils.getLogger(XmlBeansDataBinding.class);
 
     private static final Class<?> SUPPORTED_READER_FORMATS[] = new Class<?>[]
{XMLStreamReader.class};

Modified: cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java?rev=831408&r1=831407&r2=831408&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java
(original)
+++ cxf/trunk/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java
Fri Oct 30 18:05:54 2009
@@ -24,6 +24,8 @@
 import org.w3c.dom.Node;
 
 import org.apache.cxf.common.util.SOAPConstants;
+import org.apache.cxf.endpoint.Server;
+
 import org.junit.Before;
 import org.junit.Test;
 
@@ -32,12 +34,15 @@
  */
 public class DocumentStyleTest extends AbstractXmlBeansTest {
     String ns = "urn:TestService";
+    Server server;
     
     @Before
     public void setUp() throws Exception {
         super.setUp();
 
-        createService(TestService.class, new TestService(), "TestService", new QName(ns,
"TestService"));
+        server = createService(TestService.class, new TestService(), 
+                               "TestService", 
+                               new QName(ns, "TestService"));
     }
 
     @Test
@@ -52,6 +57,18 @@
     }
 
     @Test
+    public void testInvokeWithHack() throws Exception {
+        server.getEndpoint().put(XmlBeansDataBinding.XMLBEANS_NAMESPACE_HACK, Boolean.TRUE);
+        Node response = invoke("TestService", "/org/apache/cxf/xmlbeans/DocumentStyleRequest.xml");
+
+        assertNotNull(response);
+
+        addNamespace("x", "http://cxf.apache.org/xmlbeans");
+        addNamespace("y", "urn:TestService");
+        assertValid("//s:Body/y:mixedRequestResponse/x:response/x:form", response);
+    }
+
+    @Test
     public void testWSDL() throws Exception {
         Document wsdl = getWSDLDocument("TestService");
 



Mime
View raw message