Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0581FF60D for ; Wed, 3 Apr 2013 00:31:54 +0000 (UTC) Received: (qmail 37187 invoked by uid 500); 3 Apr 2013 00:31:53 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 37151 invoked by uid 500); 3 Apr 2013 00:31:53 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 37144 invoked by uid 99); 3 Apr 2013 00:31:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Apr 2013 00:31:53 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 03 Apr 2013 00:31:50 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id ABD0D23888EA; Wed, 3 Apr 2013 00:31:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1463799 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/reply/ test/java/org/apache/camel/component/jms/ Date: Wed, 03 Apr 2013 00:31:28 -0000 To: commits@camel.apache.org From: raulk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130403003128.ABD0D23888EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: raulk Date: Wed Apr 3 00:31:28 2013 New Revision: 1463799 URL: http://svn.apache.org/r1463799 Log: CAMEL-6218 camel-jms: transferExchange option now works as expected, trasferring body, headers and properties back and forth in request/reply scenarios Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTransferExchangeTest.java camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableRequestDto.java camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableResponseDto.java Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java?rev=1463799&r1=1463798&r2=1463799&view=diff ============================================================================== --- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java (original) +++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/ReplyManagerSupport.java Wed Apr 3 00:31:28 2013 @@ -133,17 +133,19 @@ public abstract class ReplyManagerSuppor exchange.setException(new ExchangeTimedOutException(exchange, holder.getRequestTimeout(), msg)); } else { JmsMessage response = new JmsMessage(message, endpoint.getBinding()); + // the JmsBinding is designed to be "pull-based": it will populate the Camel message on demand + // therefore, we link Exchange and OUT message before continuing, so that the JmsBinding has full access + // to everything it may need, and can populate headers, properties, etc. accordingly (solves CAMEL-6218). + exchange.setOut(response); Object body = response.getBody(); if (endpoint.isTransferException() && body instanceof Exception) { - log.debug("Reply received. Setting reply as an Exception: {}", body); + log.debug("Reply was an Exception. Setting the Exception on the Exchange: {}", body); // we got an exception back and endpoint was configured to transfer exception // therefore set response as exception exchange.setException((Exception) body); } else { - log.debug("Reply received. Setting reply as OUT message: {}", body); - // regular response - exchange.setOut(response); + log.debug("Reply received. OUT message body set to reply payload: {}", body); } // restore correlation id in case the remote server messed with it Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTransferExchangeTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTransferExchangeTest.java?rev=1463799&view=auto ============================================================================== --- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTransferExchangeTest.java (added) +++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsInOutTransferExchangeTest.java Wed Apr 3 00:31:28 2013 @@ -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.jms; + +import java.util.HashMap; +import java.util.Map; + +import javax.jms.ConnectionFactory; + +import org.apache.camel.CamelContext; +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Message; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge; + +public class JmsInOutTransferExchangeTest extends CamelTestSupport { + + @EndpointInject(uri = "mock:transfer") + protected MockEndpoint transfer; + + @EndpointInject(uri = "mock:result") + protected MockEndpoint result; + + @Override + protected CamelContext createCamelContext() throws Exception { + CamelContext camelContext = super.createCamelContext(); + ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); + camelContext.addComponent("activemq", jmsComponentAutoAcknowledge(connectionFactory)); + return camelContext; + } + + @Test + public void testTransferExchangeInOut() throws Exception { + transfer.expectedMessageCount(1); + result.expectedMessageCount(1); + + template.send("direct:start", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody(new SerializableRequestDto("Restless Camel")); + + Map map = new HashMap(); + map.put("boolean", Boolean.TRUE); + map.put("string", "hello"); + map.put("long", new Long(123)); + map.put("double", new Double(1.23)); + map.put("requestObject", new SerializableRequestDto("Restless Camel")); + + exchange.getIn().setHeaders(map); + exchange.setProperty("requestObjectProperty", new SerializableRequestDto("Restless Camel")); + } + }); + + assertMockEndpointsSatisfied(); + + Exchange transferExchange = transfer.getExchanges().get(0); + Message transferMessage = transferExchange.getIn(); + assertNotNull(transferMessage.getBody(SerializableRequestDto.class)); + assertNotNull(transferMessage.getHeader("requestObject", SerializableRequestDto.class)); + assertEquals(Boolean.TRUE, transferMessage.getHeader("boolean", Boolean.class)); + assertEquals((Long) 123l, transferMessage.getHeader("long", Long.class)); + assertEquals((Double) 1.23, transferMessage.getHeader("double", Double.class)); + assertEquals("hello", transferMessage.getHeader("string", String.class)); + assertNotNull(transferExchange.getProperty("requestObjectProperty", SerializableRequestDto.class)); + + Exchange resultExchange = result.getExchanges().get(0); + Message resultMessage = result.getExchanges().get(0).getIn(); + assertNotNull(resultMessage.getBody(SerializableResponseDto.class)); + assertNotNull(resultMessage.getHeader("requestObject", SerializableRequestDto.class)); + assertEquals(Boolean.TRUE, resultMessage.getHeader("boolean", Boolean.class)); + assertEquals((Long) 123l, resultMessage.getHeader("long", Long.class)); + assertEquals((Double) 1.23, resultMessage.getHeader("double", Double.class)); + assertEquals("hello", resultMessage.getHeader("string", String.class)); + assertNotNull(resultMessage.getHeader("responseHeader", SerializableResponseDto.class)); + assertNotNull(resultExchange.getProperty("responseObjectProperty", SerializableResponseDto.class)); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("direct:start") + .inOut("activemq:responseGenerator?transferExchange=true") + .to("mock:result"); + + from("activemq:responseGenerator?transferExchange=true") + .to("mock:transfer") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody(new SerializableResponseDto(true)); + exchange.getIn().setHeader("responseHeader", new SerializableResponseDto(true)); + exchange.setProperty("responseObjectProperty", new SerializableResponseDto(true)); + } + }); + } + }; + } + + + +} Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableRequestDto.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableRequestDto.java?rev=1463799&view=auto ============================================================================== --- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableRequestDto.java (added) +++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableRequestDto.java Wed Apr 3 00:31:28 2013 @@ -0,0 +1,32 @@ +/** + * 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.jms; + +import java.io.Serializable; + +public class SerializableRequestDto implements Serializable { + private static final long serialVersionUID = 1L; + public String customerName; + + public SerializableRequestDto() { + customerName = "Default"; + } + + public SerializableRequestDto(String customerName) { + this.customerName = customerName; + } +} \ No newline at end of file Added: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableResponseDto.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableResponseDto.java?rev=1463799&view=auto ============================================================================== --- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableResponseDto.java (added) +++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/SerializableResponseDto.java Wed Apr 3 00:31:28 2013 @@ -0,0 +1,33 @@ +/** + * 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.jms; + +import java.io.Serializable; + +public class SerializableResponseDto implements Serializable { + private static final long serialVersionUID = 1L; + public boolean success; + + public SerializableResponseDto() { + + } + + public SerializableResponseDto(boolean success) { + this.success = success; + } + +} \ No newline at end of file