Author: davsclaus
Date: Thu Dec 10 09:43:01 2009
New Revision: 889160
URL: http://svn.apache.org/viewvc?rev=889160&view=rev
Log:
CAMEL-2274: Fixed Camel Proxy not handling returned null as valid answer.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ProxyReturnNullIssueTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java?rev=889160&r1=889159&r2=889160&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/CamelInvocationHandler.java
Thu Dec 10 09:43:01 2009
@@ -83,6 +83,12 @@
return null;
}
+ // only convert if there is a body
+ if (!exchange.hasOut() || exchange.getOut().getBody() == null) {
+ // there is no body so return null
+ return null;
+ }
+
// use type converter so we can convert output in the desired type
defined by the method
// and let it be mandatory so we know wont return null if we cant
convert it to the defined type
Object answer = exchange.getOut().getMandatoryBody(to);
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ProxyReturnNullIssueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ProxyReturnNullIssueTest.java?rev=889160&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ProxyReturnNullIssueTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ProxyReturnNullIssueTest.java
Thu Dec 10 09:43:01 2009
@@ -0,0 +1,57 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.bean.ProxyHelper;
+
+/**
+ * @version $Revision$
+ */
+public class ProxyReturnNullIssueTest extends ContextTestSupport {
+
+ public void testEcho() throws Exception {
+ Echo service =
ProxyHelper.createProxy(context.getEndpoint("direct:echo"), Echo.class);
+ assertEquals("Hello World", service.echo("Hello World"));
+ }
+
+ public void testEchoNull() throws Exception {
+ Echo service =
ProxyHelper.createProxy(context.getEndpoint("direct:echo"), Echo.class);
+ assertEquals(null, service.echo(null));
+ }
+
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:echo").bean(new Echo() {
+ public String echo(String text) {
+ return text;
+ }
+ });
+ }
+ };
+ }
+
+ public static interface Echo {
+ String echo(String text);
+ }
+
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ProxyReturnNullIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/ProxyReturnNullIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date