camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1403990 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/ test/java/org/apache/camel/component/cxf/ test/resources/org/apache/camel/component/cxf/
Date Wed, 31 Oct 2012 05:41:53 GMT
Author: ningjiang
Date: Wed Oct 31 05:41:53 2012
New Revision: 1403990

URL: http://svn.apache.org/viewvc?rev=1403990&view=rev
Log:
CAMEL-5755 make cxf exceptionMessageCauseEnabled option work within camel-cxf with thanks
to Aki

Added:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadFaultCauseEnabledTest.java
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfConsumerFaultCauseEnabledBeans.xml
Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java?rev=1403990&r1=1403989&r2=1403990&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
Wed Oct 31 05:41:53 2012
@@ -33,6 +33,7 @@ import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.ServerFactoryBean;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.FaultMode;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.invoker.Invoker;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -174,23 +175,25 @@ public class CxfConsumer extends Default
                 CxfEndpoint endpoint = (CxfEndpoint)getEndpoint();
                 CxfBinding binding = endpoint.getCxfBinding();                
                 
-                checkFailure(camelExchange);
+                checkFailure(camelExchange, cxfExchange);
                 
                 binding.populateCxfResponseFromExchange(camelExchange, cxfExchange);
                 
                 // check failure again as fault could be discovered by converter
-                checkFailure(camelExchange);
+                checkFailure(camelExchange, cxfExchange);
 
                 // copy the headers javax.xml.ws header back
                 binding.copyJaxWsContext(cxfExchange, (Map<String, Object>)camelExchange.getProperty(CxfConstants.JAXWS_CONTEXT));
             }
 
-            private void checkFailure(org.apache.camel.Exchange camelExchange) throws Fault
{
+            private void checkFailure(org.apache.camel.Exchange camelExchange, Exchange cxfExchange)
throws Fault {
                 final Throwable t;
                 if (camelExchange.isFailed()) {
                     t = (camelExchange.hasOut() && camelExchange.getOut().isFault())
? camelExchange.getOut()
                         .getBody(Throwable.class) : camelExchange.getException();
+                    cxfExchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
                     if (t instanceof Fault) {
+                        cxfExchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT);
                         throw (Fault)t;
                     } else if (t != null) {                        
                         // This is not a CXF Fault. Build the CXF Fault manuallly.

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadFaultCauseEnabledTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadFaultCauseEnabledTest.java?rev=1403990&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadFaultCauseEnabledTest.java
(added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfConsumerPayloadFaultCauseEnabledTest.java
Wed Oct 31 05:41:53 2012
@@ -0,0 +1,121 @@
+/**
+ * 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.camel.component.cxf;
+
+
+import java.io.StringReader;
+import java.net.URL;
+import java.util.ResourceBundle;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPFault;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Holder;
+import javax.xml.ws.soap.SOAPFaultException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.wsdl_first.Person;
+import org.apache.camel.wsdl_first.PersonService;
+import org.apache.camel.wsdl_first.UnknownPersonFault;
+import org.apache.cxf.binding.soap.SoapFault;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.message.Message;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+
+
+/**
+ * Unit test to verify CxfConsumer to generate SOAP fault in PAYLOAD mode with the exception
cause returned
+ * 
+ * @version 
+ */
+public class CxfConsumerPayloadFaultCauseEnabledTest extends CamelTestSupport {
+    protected static final QName SERVICE_QNAME = new QName("http://camel.apache.org/wsdl-first",
"PersonService");
+    protected final String serviceAddress = "http://localhost:" + CXFTestSupport.getPort1()

+        + "/" + getClass().getSimpleName() + "/PersonService";
+    protected AbstractXmlApplicationContext applicationContext;
+
+    @Before
+    public void setUp() throws Exception {
+        CXFTestSupport.getPort1();
+        applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/cxf/CxfConsumerFaultCauseEnabledBeans.xml");
+        super.setUp();
+        assertNotNull("Should have created a valid spring context", applicationContext);
+    }
+    
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            public void configure() {
+                from("cxf:bean:consumerEndpoint").process(new Processor() {
+                    public void process(final Exchange exchange) throws Exception {
+                        Throwable cause = new IllegalArgumentException("Homer");
+                        Fault fault = new Fault("Someone messed up the service.", (ResourceBundle)null,
cause);
+                        exchange.setException(fault);
+                    }
+                });
+            }
+        };
+    }
+
+    @Test
+    public void testInvokingFromCxfClient() throws Exception {
+        this.getCamelContextService();
+        URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
+        PersonService ss = new PersonService(wsdlURL, SERVICE_QNAME);
+        
+        Person client = ss.getSoap();
+        
+        Client c = ClientProxy.getClient(client);
+        c.getInInterceptors().add(new LoggingInInterceptor());
+        c.getOutInterceptors().add(new LoggingOutInterceptor());
+        ((BindingProvider)client).getRequestContext()
+            .put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceAddress);
+        
+        Holder<String> personId = new Holder<String>();
+        personId.value = "";
+        Holder<String> ssn = new Holder<String>();
+        Holder<String> name = new Holder<String>();
+        try {
+            client.getPerson(personId, ssn, name);
+            fail("SOAPFault expected!");
+        } catch (Exception e) {
+            assertTrue(e instanceof SOAPFaultException);
+            SOAPFault fault = ((SOAPFaultException)e).getFault();
+            assertEquals("Someone messed up the service. Caused by: Homer", fault.getFaultString());
+        }
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+}

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfConsumerFaultCauseEnabledBeans.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfConsumerFaultCauseEnabledBeans.xml?rev=1403990&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfConsumerFaultCauseEnabledBeans.xml
(added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/CxfConsumerFaultCauseEnabledBeans.xml
Wed Oct 31 05:41:53 2012
@@ -0,0 +1,39 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/cxf"
+ xmlns:s="http://camel.apache.org/wsdl-first"
+ xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+  <cxf:cxfEndpoint id="consumerEndpoint" 
+    address="http://localhost:${CXFTestSupport.port1}/CxfConsumerPayloadFaultCauseEnabledTest/PersonService"
+    endpointName="s:soap"
+    serviceName="s:PersonService"
+    wsdlURL="classpath:person.wsdl">
+    <cxf:properties>
+      <entry key="dataFormat" value="PAYLOAD"/>
+      <entry key="exceptionMessageCauseEnabled" value="true"/>
+    </cxf:properties>
+  </cxf:cxfEndpoint>
+
+  </beans>



Mime
View raw message