You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ri...@apache.org on 2011/06/18 00:30:13 UTC

svn commit: r1137057 - in /camel/trunk/components/camel-spring-ws: ./ src/main/java/org/apache/camel/component/spring/ws/ src/test/java/org/apache/camel/component/spring/ws/ src/test/resources/org/apache/camel/component/spring/ws/

Author: rickette
Date: Fri Jun 17 22:30:13 2011
New Revision: 1137057

URL: http://svn.apache.org/viewvc?rev=1137057&view=rev
Log:
CAMEL-4116: Consumer now propagates exceptions back to Spring-WS. This allows for exception handling by Spring-WS EndpointExceptionResolver's

Added:
    camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest.java
    camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest-context.xml
Modified:
    camel/trunk/components/camel-spring-ws/pom.xml
    camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java

Modified: camel/trunk/components/camel-spring-ws/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/pom.xml?rev=1137057&r1=1137056&r2=1137057&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-ws/pom.xml (original)
+++ camel/trunk/components/camel-spring-ws/pom.xml Fri Jun 17 22:30:13 2011
@@ -71,6 +71,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.springframework.ws</groupId>
+            <artifactId>spring-ws-test</artifactId>
+            <version>${spring-ws-version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-test</artifactId>
             <scope>test</scope>

Modified: camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java?rev=1137057&r1=1137056&r2=1137057&view=diff
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java (original)
+++ camel/trunk/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java Fri Jun 17 22:30:13 2011
@@ -58,8 +58,9 @@ public class SpringWebserviceConsumer ex
         // start message processing
         getProcessor().process(exchange);
 
-        // create webservice response from output body
-        if (exchange.getPattern().isOutCapable()) {
+        if (exchange.getException() != null) {
+            throw exchange.getException();
+        } else if (exchange.getPattern().isOutCapable()) {
             Message responseMessage = exchange.getOut(Message.class);
             if (responseMessage != null) {
                 Source responseBody = responseMessage.getBody(Source.class);

Added: camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest.java?rev=1137057&view=auto
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest.java (added)
+++ camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest.java Fri Jun 17 22:30:13 2011
@@ -0,0 +1,88 @@
+/**
+ * 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.spring.ws;
+
+import java.io.StringReader;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.spring.ws.bean.CamelEndpointMapping;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.ws.test.server.MockWebServiceClient;
+
+import static org.springframework.ws.test.server.RequestCreators.withPayload;
+import static org.springframework.ws.test.server.ResponseMatchers.serverOrReceiverFault;
+
+@ContextConfiguration
+@RunWith(SpringJUnit4ClassRunner.class)
+public class ConsumerExceptionPropagationRouteTest extends CamelTestSupport {
+
+    private final String xmlRequestForGoogleStockQuote = "<GetQuote xmlns=\"http://www.webserviceX.NET/\"><symbol>GOOG</symbol></GetQuote>";
+
+    @Autowired
+    private CamelEndpointMapping endpointMapping;
+
+    @Autowired
+    private ApplicationContext applicationContext;
+
+    private MockWebServiceClient mockClient;
+
+    @Before
+    public void createClient() {
+        mockClient = MockWebServiceClient.createClient(applicationContext);
+    }
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        context.setTracing(true);
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("endpointMapping", this.endpointMapping);
+        return registry;
+    }
+
+    @Test
+    public void consumeWebserviceAndTestForSoapFault() throws Exception {
+        StreamSource source = new StreamSource(new StringReader(xmlRequestForGoogleStockQuote));
+        mockClient.sendRequest(withPayload(source)).andExpect(serverOrReceiverFault());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                from("spring-ws:rootqname:{http://www.webserviceX.NET/}GetQuote?endpointMapping=#endpointMapping")
+                        .throwException(new RuntimeException("this is a test exception!"));
+            }
+        };
+    }
+
+}
\ No newline at end of file

Added: camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest-context.xml?rev=1137057&view=auto
==============================================================================
--- camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest-context.xml (added)
+++ camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/ConsumerExceptionPropagationRouteTest-context.xml Fri Jun 17 22:30:13 2011
@@ -0,0 +1,27 @@
+<?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"
+       xsi:schemaLocation="
+         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <bean id="endpointMapping"
+          class="org.apache.camel.component.spring.ws.bean.CamelEndpointMapping"/>
+
+</beans>
\ No newline at end of file