servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r794205 - in /servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src: main/java/org/apache/servicemix/cxfbc/ main/java/org/apache/servicemix/cxfbc/interceptors/ test/java/org/apache/servicemix/cxfbc/ tes...
Date Wed, 15 Jul 2009 09:24:38 GMT
Author: ffang
Date: Wed Jul 15 09:24:32 2009
New Revision: 794205

URL: http://svn.apache.org/viewvc?rev=794205&view=rev
Log:
[SMXCOMP-591]cxf bc provider should be able to send exception back when something wrong during
process soap fault message

Added:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/interceptors/InvalidSoapFaultInterceptor.java
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/invalid-soap-fault.xml
Modified:
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProviderMessageObserver.java
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java
    servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/cxf_provider_consumer_bridge.xml

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProviderMessageObserver.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProviderMessageObserver.java?rev=794205&r1=794204&r2=794205&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProviderMessageObserver.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/CxfBcProviderMessageObserver.java
Wed Jul 15 09:24:32 2009
@@ -24,6 +24,7 @@
 
 import javax.jbi.messaging.ExchangeStatus;
 import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.InOptionalOut;
 import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.MessageExchange;
@@ -124,6 +125,15 @@
             inChain.doIntercept(soapMessage);
             closeConnectionStream(soapMessage);
             if (soapMessage.getContent(Source.class) == null) {
+                Exception ex = soapMessage.getContent(Exception.class);
+                if (!(soapMessage.getExchange().get(MessageExchange.class) instanceof InOnly)
+                        && ex != null) {
+                    messageExchange.setStatus(ExchangeStatus.ERROR);
+                    messageExchange.setError(ex);
+                    providerEndpoint.getContext().getDeliveryChannel().send(
+                            messageExchange);
+                }
+
                 return;
             }
           

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java?rev=794205&r1=794204&r2=794205&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiInWsdl1Interceptor.java
Wed Jul 15 09:24:32 2009
@@ -223,57 +223,75 @@
     }
 
     void handleJBIFault(SoapMessage message, Element soapFault) {
-        Document doc = DomUtil.createDocument();
-        Element jbiFault = DomUtil.createElement(doc, new QName(
-                JBIConstants.NS_JBI_BINDING, JBIFault.JBI_FAULT_ROOT));
-        Node jbiFaultDetail = null;
-        if (message.getVersion() instanceof Soap11) {
-            NodeList nodeList = soapFault.getElementsByTagName("faultcode");
-            String faultCode = nodeList.item(0).getFirstChild().getTextContent();
-            String prefix = faultCode.substring(0, faultCode.indexOf(":"));
-            String localName = faultCode.substring(faultCode.indexOf(":") + 1);
-            message.put("faultcode", new QName(prefix, localName));
-            nodeList = soapFault.getElementsByTagName("faultstring");
-            message.put("faultstring", nodeList.item(0).getFirstChild().getTextContent());
-            nodeList = soapFault.getElementsByTagName("detail");
-            if (nodeList != null && nodeList.getLength() > 0 
-                    && DomUtil.getFirstChildElement(nodeList.item(0)) != null) {
-                jbiFaultDetail = doc.importNode(DomUtil.getFirstChildElement(nodeList.item(0)),
true);
-            } else {
-                message.put("hasdetail", false);
+        try {
+            Document doc = DomUtil.createDocument();
+            Element jbiFault = DomUtil.createElement(doc, new QName(
+                    JBIConstants.NS_JBI_BINDING, JBIFault.JBI_FAULT_ROOT));
+            Node jbiFaultDetail = null;
+            if (message.getVersion() instanceof Soap11) {
+                NodeList nodeList = soapFault.getElementsByTagName("faultcode");
+                String faultCode = nodeList.item(0).getFirstChild()
+                        .getTextContent();
+                String prefix = faultCode.substring(0, faultCode.indexOf(":"));
+                String localName = faultCode
+                        .substring(faultCode.indexOf(":") + 1);
+                message.put("faultcode", new QName(prefix, localName));
                 nodeList = soapFault.getElementsByTagName("faultstring");
-                jbiFaultDetail = doc.importNode(nodeList.item(0).getFirstChild(), true);
-            }
-            
-        } else {
-            NodeList nodeList = soapFault.getElementsByTagName("soap:Code");
-            String faultCode = DomUtil.getFirstChildElement(nodeList.item(0)).getTextContent();
-            String prefix = faultCode.substring(0, faultCode.indexOf(":"));
-            String localName = faultCode.substring(faultCode.indexOf(":") + 1);
-            message.put("faultcode", new QName(prefix, localName));
-            nodeList = soapFault.getElementsByTagName("soap:Reason");
-            message.put("faultstring", DomUtil.getFirstChildElement(nodeList.item(0)).getTextContent());
-            nodeList = soapFault.getElementsByTagName("soap:Detail");
-            if (nodeList != null && nodeList.getLength() > 0
-                    && DomUtil.getFirstChildElement(nodeList.item(0)) != null) {
-                jbiFaultDetail = doc.importNode(DomUtil.getFirstChildElement(nodeList.item(0)),
true);
+                message.put("faultstring", nodeList.item(0).getFirstChild()
+                        .getTextContent());
+                nodeList = soapFault.getElementsByTagName("detail");
+                if (nodeList != null
+                        && nodeList.getLength() > 0
+                        && DomUtil.getFirstChildElement(nodeList.item(0)) != null)
{
+                    jbiFaultDetail = doc.importNode(DomUtil
+                            .getFirstChildElement(nodeList.item(0)), true);
+                } else {
+                    message.put("hasdetail", false);
+                    nodeList = soapFault.getElementsByTagName("faultstring");
+                    jbiFaultDetail = doc.importNode(nodeList.item(0)
+                            .getFirstChild(), true);
+                }
+
             } else {
-                message.put("hasdetail", false);
-                nodeList = soapFault.getElementsByTagName("faultstring");
-                jbiFaultDetail = doc.importNode(DomUtil.getFirstChildElement(nodeList.item(0)),
true);
+                NodeList nodeList = soapFault.getElementsByTagName("soap:Code");
+                String faultCode = DomUtil.getFirstChildElement(
+                        nodeList.item(0)).getTextContent();
+                String prefix = faultCode.substring(0, faultCode.indexOf(":"));
+                String localName = faultCode
+                        .substring(faultCode.indexOf(":") + 1);
+                message.put("faultcode", new QName(prefix, localName));
+                nodeList = soapFault.getElementsByTagName("soap:Reason");
+                message.put("faultstring", DomUtil.getFirstChildElement(
+                        nodeList.item(0)).getTextContent());
+                nodeList = soapFault.getElementsByTagName("soap:Detail");
+                if (nodeList != null
+                        && nodeList.getLength() > 0
+                        && DomUtil.getFirstChildElement(nodeList.item(0)) != null)
{
+                    jbiFaultDetail = doc.importNode(DomUtil
+                            .getFirstChildElement(nodeList.item(0)), true);
+                } else {
+                    message.put("hasdetail", false);
+                    nodeList = soapFault.getElementsByTagName("faultstring");
+                    jbiFaultDetail = doc.importNode(DomUtil
+                            .getFirstChildElement(nodeList.item(0)), true);
+                }
+
             }
-            
+            SchemaInfo schemaInfo = getOperation(message).getBinding()
+                    .getService().getSchema(jbiFaultDetail.getNamespaceURI());
+            if (schemaInfo != null && !schemaInfo.isElementFormQualified()) {
+                // that's unquailied fault
+                jbiFaultDetail = addEmptyDefaultTns((Element) jbiFaultDetail);
+
+            }
+            jbiFault.appendChild(jbiFaultDetail);
+            message.setContent(Source.class, new DOMSource(doc));
+            message.put("jbiFault", true);
+        } catch (Exception e) {
+            throw new RuntimeException("the fault message can't be parsed:"
+                    + e.getMessage());
+
         }
-        SchemaInfo schemaInfo = 
-            getOperation(message).getBinding().getService().getSchema(jbiFaultDetail.getNamespaceURI());
-        if (schemaInfo != null && !schemaInfo.isElementFormQualified()) {
-            //that's unquailied fault
-            jbiFaultDetail = addEmptyDefaultTns((Element)jbiFaultDetail);
-            
-        }
-        jbiFault.appendChild(jbiFaultDetail);
-        message.setContent(Source.class, new DOMSource(doc));
-        message.put("jbiFault", true);
     }
 
     private Element addEmptyDefaultTns(Element ret) {

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java?rev=794205&r1=794204&r2=794205&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/CxfBcProviderConsumerTest.java
Wed Jul 15 09:24:32 2009
@@ -21,7 +21,6 @@
 import javax.xml.namespace.QName;
 import javax.xml.ws.soap.SOAPBinding;
 
-import org.apache.cxf.calculator.AddNumbersFault;
 import org.apache.cxf.calculator.CalculatorImpl;
 import org.apache.cxf.calculator.CalculatorPortType;
 import org.apache.cxf.calculator.CalculatorService;
@@ -66,8 +65,8 @@
         try {
             port.add(1, -2);
             fail("should get exception");
-        } catch (AddNumbersFault e) {
-            assertEquals(e.getFaultInfo().getMessage(), "Negative number cant be added!");
+        } catch (Exception e) {
+            assertEquals(e.getMessage(), "the fault message can't be parsed:String index
out of range: -1");
         }
 
     }

Added: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/interceptors/InvalidSoapFaultInterceptor.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/interceptors/InvalidSoapFaultInterceptor.java?rev=794205&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/interceptors/InvalidSoapFaultInterceptor.java
(added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/java/org/apache/servicemix/cxfbc/interceptors/InvalidSoapFaultInterceptor.java
Wed Jul 15 09:24:32 2009
@@ -0,0 +1,63 @@
+/*
+ * 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.servicemix.cxfbc.interceptors;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class InvalidSoapFaultInterceptor extends AbstractPhaseInterceptor<Message>
{
+
+    public InvalidSoapFaultInterceptor() {
+        super(Phase.RECEIVE);
+        addAfter(LoggingInInterceptor.class.getName());
+    }
+
+    public void handleMessage(Message message) throws Fault {
+        InputStream is = message.getContent(InputStream.class);
+        if (is != null) {
+            CachedOutputStream bos = new CachedOutputStream();
+            try {
+                IOUtils.copy(is, bos);
+
+                bos.flush();
+                is.close();
+                message.setContent(InputStream.class, bos.getInputStream());
+                bos.close();
+                String soapMessage = new String(bos.getBytes());
+                if (soapMessage.indexOf("Negative number cant be added!") >= 0) {
+                    is = getClass().getClassLoader().getResourceAsStream(
+                            "org/apache/servicemix/cxfbc/invalid-soap-fault.xml");
+                    if (is != null) {
+                        message.setContent(InputStream.class, is);
+                    }
+                }
+            } catch (IOException e) {
+                throw new Fault(e);
+            }
+        }
+
+    }
+
+}

Modified: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/cxf_provider_consumer_bridge.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/cxf_provider_consumer_bridge.xml?rev=794205&r1=794204&r2=794205&view=diff
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/cxf_provider_consumer_bridge.xml
(original)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/cxf_provider_consumer_bridge.xml
Wed Jul 15 09:24:32 2009
@@ -53,6 +53,7 @@
                      >
           <cxfbc:inInterceptors>
             <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+            <bean class="org.apache.servicemix.cxfbc.interceptors.InvalidSoapFaultInterceptor"/>
           </cxfbc:inInterceptors>
           <cxfbc:outInterceptors>
             <bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>

Added: servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/invalid-soap-fault.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/invalid-soap-fault.xml?rev=794205&view=auto
==============================================================================
--- servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/invalid-soap-fault.xml
(added)
+++ servicemix/smx3/branches/servicemix-3.2/deployables/bindingcomponents/servicemix-cxf-bc/src/test/resources/org/apache/servicemix/cxfbc/invalid-soap-fault.xml
Wed Jul 15 09:24:32 2009
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
+	<soap:Body>
+		<soap:Fault>
+			<soap:Code>
+				<soap:Value>Receiver</soap:Value>
+			</soap:Code>
+			<soap:Reason>
+				<soap:Text xml:lang ="en">Negative number cant be added!</soap:Text>
+			</soap:Reason>
+			<soap:Detail>
+				<CalculatorFault xmlns="http://apache.org/cxf/calculator/types">
+					<faultInfo>Numbers: 1, -1</faultInfo>
+					<message>Negative number cant be added!</message>
+				</CalculatorFault>
+			</soap:Detail>
+		</soap:Fault>
+	</soap:Body>
+</soap:Envelope>



Mime
View raw message