Author: gnodet
Date: Wed May 2 06:34:51 2007
New Revision: 534452
URL: http://svn.apache.org/viewvc?view=rev&rev=534452
Log:
SM-841: The servicemix-http provider endpoint does not properly handle web
services that return faults with multiple elements in the detail section.
Patch provided by Jeff Puro, thx !
Added:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml
(with props)
Modified:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java
Modified:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java?view=diff&rev=534452&r1=534451&r2=534452
==============================================================================
---
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
(original)
+++
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapMarshaler.java
Wed May 2 06:34:51 2007
@@ -72,6 +72,8 @@
protected boolean soap = true;
protected boolean useDom = false;
protected String soapUri = SOAP_12_URI;
+
+ public static final String MULTIPLE_DETAILS_NODE_WRAPPER =
"multiple-details";
public SoapMarshaler() {
}
Modified:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java?view=diff&rev=534452&r1=534451&r2=534452
==============================================================================
---
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
(original)
+++
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapReader.java
Wed May 2 06:34:51 2007
@@ -29,6 +29,7 @@
import javax.mail.internet.MimeMultipart;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamReader;
import javax.xml.transform.Source;
@@ -37,6 +38,7 @@
import org.apache.servicemix.jbi.jaxp.ExtendedXMLStreamReader;
import org.apache.servicemix.jbi.jaxp.FragmentStreamReader;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StaxSource;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.util.DOMUtil;
@@ -44,6 +46,7 @@
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
/**
*
@@ -232,14 +235,7 @@
}
// Fault details
if (SoapMarshaler.SOAP_11_FAULTDETAIL.equals(childname)) {
- Element subchild = DOMUtil.getFirstChildElement(child);
- if (subchild != null) {
- details = new DOMSource(subchild);
- subchild = DOMUtil.getNextSiblingElement(subchild);
- if (subchild != null) {
- throw new SoapFault(SoapFault.RECEIVER, "Multiple
elements are not supported in Detail");
- }
- }
+ details = getDetailsAsSource(child);
child = DOMUtil.getNextSiblingElement(child);
childname = DOMUtil.getQName(child);
}
@@ -300,14 +296,7 @@
}
// Fault details
if (SoapMarshaler.SOAP_12_FAULTDETAIL.equals(childname)) {
- subchild = DOMUtil.getFirstChildElement(child);
- if (subchild != null) {
- details = new DOMSource(subchild);
- subchild = DOMUtil.getNextSiblingElement(subchild);
- if (subchild != null) {
- throw new SoapFault(SoapFault.RECEIVER, "Multiple
elements are not supported in Detail");
- }
- }
+ details = getDetailsAsSource(child);
child = DOMUtil.getNextSiblingElement(child);
childname = DOMUtil.getQName(child);
}
@@ -318,6 +307,30 @@
}
SoapFault fault = new SoapFault(code, subcode, reason, node, role,
details);
return fault;
+ }
+
+ private Source getDetailsAsSource(Element parent) throws SoapFault {
+ Element main = DOMUtil.getFirstChildElement(parent);
+ Source details = null;
+ if (main != null && DOMUtil.getNextSiblingElement(main) == null) {
+ details = new DOMSource(main);
+ } else if (main != null) {
+ // Wrap nodes in a parent element
+ Document document = null;
+ try {
+ document = new SourceTransformer().createDocument();
+ } catch (ParserConfigurationException e) {
+ throw new SoapFault(e);
+ }
+ Element parentNode =
document.createElement(SoapMarshaler.MULTIPLE_DETAILS_NODE_WRAPPER);
+ NodeList nodes = parent.getChildNodes();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ parentNode.appendChild(document.importNode(nodes.item(i),
true));
+ }
+ document.appendChild(parentNode);
+ details = new DOMSource(document);
+ }
+ return details;
}
private SoapFault readFaultUsingStax(XMLStreamReader reader) throws
SoapFault {
Modified:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java?view=diff&rev=534452&r1=534451&r2=534452
==============================================================================
---
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
(original)
+++
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/marshalers/SoapWriter.java
Wed May 2 06:34:51 2007
@@ -36,18 +36,25 @@
import javax.mail.internet.MimeMultipart;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.W3CDOMStreamReader;
import org.apache.servicemix.jbi.jaxp.XMLStreamHelper;
import org.apache.servicemix.jbi.util.ByteArrayDataSource;
import org.apache.servicemix.soap.SoapFault;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
/**
*
@@ -96,7 +103,7 @@
private void writeSimpleMessage(OutputStream out) throws Exception {
if (message.getDocument() != null) {
- marshaler.sourceTransformer.toResult(new
DOMSource(message.getDocument()), new StreamResult(out));
+ marshaler.getSourceTransformer().toResult(new
DOMSource(message.getDocument()), new StreamResult(out));
return;
}
XMLStreamWriter writer =
marshaler.getOutputFactory().createXMLStreamWriter(out);
@@ -249,8 +256,7 @@
Source details = fault.getDetails();
if (details != null) {
XMLStreamHelper.writeStartElement(writer,
SoapMarshaler.SOAP_11_FAULTDETAIL);
- XMLStreamReader reader =
marshaler.getSourceTransformer().toXMLStreamReader(details);
- XMLStreamHelper.copy(reader, writer);
+ writeDetails(writer, details);
writer.writeEndElement();
}
@@ -311,12 +317,30 @@
Source details = fault.getDetails();
if (details != null) {
XMLStreamHelper.writeStartElement(writer,
SoapMarshaler.SOAP_12_FAULTDETAIL);
- XMLStreamReader reader =
marshaler.getSourceTransformer().toXMLStreamReader(details);
- XMLStreamHelper.copy(reader, writer);
+ writeDetails(writer, details);
writer.writeEndElement();
}
writer.writeEndElement();
+ }
+
+ private void writeDetails(XMLStreamWriter writer, Source details) throws
ParserConfigurationException, IOException, SAXException, TransformerException,
XMLStreamException {
+ SourceTransformer st = new SourceTransformer();
+ DOMSource domDetails = st.toDOMSource(details);
+ Node detailsNode = domDetails.getNode().getFirstChild();
+ if (
SoapMarshaler.MULTIPLE_DETAILS_NODE_WRAPPER.equals(detailsNode.getNodeName()) )
{
+ NodeList children = detailsNode.getChildNodes();
+ for ( int i = 0; i < children.getLength(); i++ ) {
+ Node node = children.item(i);
+ if ( node.getNodeType() == Node.ELEMENT_NODE ) {
+ XMLStreamReader reader =
marshaler.getSourceTransformer().toXMLStreamReader(new DOMSource(node));
+ XMLStreamHelper.copy(reader, writer);
+ }
+ }
+ } else {
+ XMLStreamReader reader =
marshaler.getSourceTransformer().toXMLStreamReader(details);
+ XMLStreamHelper.copy(reader, writer);
+ }
}
protected QName getEnvelopeName() {
Modified:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java
URL:
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java?view=diff&rev=534452&r1=534451&r2=534452
==============================================================================
---
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java
(original)
+++
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/java/org/apache/servicemix/soap/marshalers/FaultTest.java
Wed May 2 06:34:51 2007
@@ -49,6 +49,38 @@
}
}
+ protected SoapMessage testSoap11WithMultipleDetailElements(boolean useDom)
throws Exception {
+ SoapMarshaler marshaler = new SoapMarshaler(true, useDom);
+ try {
+ SoapMessage message =
marshaler.createReader().read(getClass().getResourceAsStream("fault-1.1-multiple-detail-elements.xml"));
+ return message;
+ } catch (SoapFault fault) {
+ assertEquals(SoapMarshaler.SOAP_11_CODE_SERVER, fault.getCode());
+ assertNull(fault.getSubcode());
+ assertEquals("Server Error", fault.getReason());
+ assertNotNull(fault.getDetails());
+ Node node = sourceTransformer.toDOMNode(fault.getDetails());
+ Element e = node instanceof Document ? ((Document)
node).getDocumentElement() : (Element) node;
+ assertEquals(new QName("Some-URI", "myfaultdetails"),
DOMUtil.getQName(e));
+ return null;
+ }
+ }
+
+ public void testReadSoap11WithMultipleElementsUsingDom() throws Exception {
+ testSoap11WithMultipleDetailElements(true);
+ }
+
+ public void testWriteSoap11WithMultipleElementsUsingDom() throws Exception
{
+ SoapMessage message = testSoap11WithMultipleDetailElements(true);
+ message.setDocument(null);
+ SoapMarshaler marshaler = new SoapMarshaler(true, true);
+ SoapWriter writer = marshaler.createWriter(message);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ writer.write(baos);
+
+ System.err.println("Resulting Fault: \n" + baos);
+ }
+
public void testReadSoap11UsingDom() throws Exception {
testSoap11(true);
}
Added:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml
URL:
http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml?view=auto&rev=534452
==============================================================================
---
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml
(added)
+++
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml
Wed May 2 06:34:51 2007
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<SOAP-ENV:Envelope
+ xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/
http://schemas.xmlsoap.org/soap/envelope/">
+ <SOAP-ENV:Body>
+ <SOAP-ENV:Fault>
+ <faultcode>SOAP-ENV:Server</faultcode>
+ <faultstring>Server Error</faultstring>
+ <detail>
+ <message>
+ <ErrorCode>10000</ErrorCode>
+ <ErrorDescription>Error occurred</ErrorDescription>
+ <ErrorSeverity>Critical</ErrorSeverity>
+ <ErrorSource>Validation</ErrorSource>
+ </message>
+ <message>
+ <ErrorCode>10001</ErrorCode>
+ <ErrorDescription>Error occurred</ErrorDescription>
+ <ErrorSeverity>Critical</ErrorSeverity>
+ <ErrorSource>Validation</ErrorSource>
+ </message>
+ </detail>
+ </SOAP-ENV:Fault>
+ </SOAP-ENV:Body>
+</SOAP-ENV:Envelope>
Propchange:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/test/resources/org/apache/servicemix/soap/marshalers/fault-1.1-multiple-detail-elements.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml