Author: dkulp Date: Wed Nov 4 18:07:28 2009 New Revision: 832823 URL: http://svn.apache.org/viewvc?rev=832823&view=rev Log: Merged revisions 831409 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.2.x-fixes
................ r831409 | dkulp | 2009-10-30 14:12:28 -0400 (Fri, 30 Oct 2009) | 9 lines Merged revisions 831408 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r831408 | dkulp | 2009-10-30 14:05:54 -0400 (Fri, 30 Oct 2009) | 1 line [CXF-2510] Port XmlBeans namespace hack thing from XFire ........ ................ Modified: cxf/branches/2.1.x-fixes/ (props changed) cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java Propchange: cxf/branches/2.1.x-fixes/ ('svn:mergeinfo' removed) Propchange: cxf/branches/2.1.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java?rev=832823&r1=832822&r2=832823&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java (original) +++ cxf/branches/2.1.x-fixes/api/src/main/java/org/apache/cxf/interceptor/Fault.java Wed Nov 4 18:07:28 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/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java?rev=832823&r1=832822&r2=832823&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java (original) +++ cxf/branches/2.1.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/AbstractOutDatabindingInterceptor.java Wed Nov 4 18:07:28 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/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=832823&r1=832822&r2=832823&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java (original) +++ cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java Wed Nov 4 18:07:28 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/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java?rev=832823&r1=832822&r2=832823&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java (original) +++ cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansDataBinding.java Wed Nov 4 18:07:28 2009 @@ -51,6 +51,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/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java?rev=832823&r1=832822&r2=832823&view=diff ============================================================================== --- cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java (original) +++ cxf/branches/2.1.x-fixes/rt/databinding/xmlbeans/src/test/java/org/apache/cxf/xmlbeans/DocumentStyleTest.java Wed Nov 4 18:07:28 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");
