You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2010/10/25 14:18:19 UTC
svn commit: r1027083 - in
/servicemix/smx4/features/trunk/camel/servicemix-camel/src:
main/java/org/apache/servicemix/camel/nmr/
test/java/org/apache/servicemix/camel/nmr/
Author: gertv
Date: Mon Oct 25 12:18:19 2010
New Revision: 1027083
URL: http://svn.apache.org/viewvc?rev=1027083&view=rev
Log:
SMX4-648: Camel NMR component does not propagate Exception when using InOnly MEP
Added:
servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/CamelTryCatchTest.java
Modified:
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixProducer.java
Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java?rev=1027083&r1=1027082&r2=1027083&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java (original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixEndpoint.java Mon Oct 25 12:18:19 2010
@@ -41,8 +41,8 @@ public class ServiceMixEndpoint extends
super(uri, component);
this.endpointName = endpointName;
}
- @Override
+ @Override
public void configureProperties(Map<String, Object> options) {
synchronous = Boolean.valueOf((String) options.remove(SYNCHRONOUS));
}
Modified: servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixProducer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixProducer.java?rev=1027083&r1=1027082&r2=1027083&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixProducer.java (original)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/main/java/org/apache/servicemix/camel/nmr/ServiceMixProducer.java Mon Oct 25 12:18:19 2010
@@ -117,24 +117,31 @@ public class ServiceMixProducer extends
* - finishing the NMR Exchange MEP
*/
private void handleResponse(Exchange exchange, Channel client, org.apache.servicemix.nmr.api.Exchange e) {
+ if (e.getError() != null) {
+ handleErrorResponse(exchange, client, e);
+ } else {
+ handleSuccessResponse(exchange, client, e);
+ }
+ }
+
+ private void handleSuccessResponse(Exchange exchange, Channel client, org.apache.servicemix.nmr.api.Exchange e) {
if (e.getPattern() != Pattern.InOnly) {
- if (e.getError() != null) {
- exchange.setException(e.getError());
+ exchange.getProperties().putAll(e.getProperties());
+ if (e.getFault().getBody() != null) {
+ exchange.getOut().setFault(true);
+ getEndpoint().getComponent().getBinding().copyNmrMessageToCamelMessage(e.getFault(), exchange.getOut());
} else {
- exchange.getProperties().putAll(e.getProperties());
- if (e.getFault().getBody() != null) {
- exchange.getOut().setFault(true);
- getEndpoint().getComponent().getBinding().copyNmrMessageToCamelMessage(e.getFault(), exchange.getOut());
- } else {
- getEndpoint().getComponent().getBinding().copyNmrMessageToCamelMessage(e.getOut(), exchange.getOut());
- }
- e.setStatus(Status.Done);
- channel.send(e);
+ getEndpoint().getComponent().getBinding().copyNmrMessageToCamelMessage(e.getOut(), exchange.getOut());
}
-
+ e.setStatus(Status.Done);
+ channel.send(e);
}
}
+ private void handleErrorResponse(Exchange camel, Channel client, org.apache.servicemix.nmr.api.Exchange nmr) {
+ camel.setException(nmr.getError());
+ }
+
@Override
protected void doStart() throws Exception {
nmr.getEndpointRegistry().register(this, createEndpointMap());
Added: servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/CamelTryCatchTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/CamelTryCatchTest.java?rev=1027083&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/CamelTryCatchTest.java (added)
+++ servicemix/smx4/features/trunk/camel/servicemix-camel/src/test/java/org/apache/servicemix/camel/nmr/CamelTryCatchTest.java Mon Oct 25 12:18:19 2010
@@ -0,0 +1,81 @@
+/*
+ * 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.camel.nmr;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * A very basic NMR test, just testing if the Exchange can flow through the NMR
+ * from one Camel route to the next one
+ */
+public class CamelTryCatchTest extends AbstractComponentTest {
+
+ private static final String REQUEST_MESSAGE = "Simple message body";
+
+ public void testInOnlyTryCatch() throws InterruptedException {
+ MockEndpoint mock = getMockEndpoint("mock:caught");
+ mock.expectedMessageCount(1);
+
+ template.sendBody("direct:inonly", REQUEST_MESSAGE);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testInOutTryCatch() throws InterruptedException {
+ MockEndpoint mock = getMockEndpoint("mock:caught");
+ mock.expectedMessageCount(1);
+
+ template.requestBody("direct:inout", REQUEST_MESSAGE);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+ from("direct:inonly")
+ .doTry()
+ .to("nmr:throwsException")
+ .doCatch(CustomBusinessException.class)
+ .to("mock:caught");
+
+ from("direct:inout")
+ .doTry()
+ .to("nmr:throwsException")
+ .doCatch(CustomBusinessException.class)
+ .to("mock:caught");
+
+ from("nmr:throwsException")
+ .errorHandler(noErrorHandler())
+ .throwException(new CustomBusinessException());
+ }
+ };
+ }
+
+ /*
+ * Custom business exception for testing purposes
+ */
+ private static final class CustomBusinessException extends Exception {
+
+ }
+}