You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/12/18 16:00:50 UTC
svn commit: r892267 - in /camel/trunk/camel-core/src:
main/java/org/apache/camel/ main/java/org/apache/camel/impl/
test/java/org/apache/camel/component/bean/ test/java/org/apache/camel/impl/
Author: davsclaus
Date: Fri Dec 18 15:00:46 2009
New Revision: 892267
URL: http://svn.apache.org/viewvc?rev=892267&view=rev
Log:
CAMEL-2302: Added additional requestBody method to ProducerTemplate when using a default endpoint, which can be done using @EndpointInject etc.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanNoTypeConvertionPossibleWhenHeaderTest.java
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java?rev=892267&r1=892266&r2=892267&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/ProducerTemplate.java Fri Dec 18 15:00:46 2009
@@ -543,6 +543,21 @@
<T> T requestBody(String endpointUri, Object body, Class<T> type);
/**
+ * Sends the body to the default endpoint and returns the result content
+ * Uses an {@link ExchangePattern#InOut} message exchange pattern.
+ * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
+ * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
+ * the caused exception wrapped.
+ *
+ * @param body the payload
+ * @param header the header name
+ * @param headerValue the header value
+ * @return the result (see class javadoc)
+ * @throws CamelExecutionException if the processing of the exchange failed
+ */
+ Object requestBodyAndHeader(Object body, String header, Object headerValue);
+
+ /**
* Send the body to an endpoint returning any result output body.
* Uses an {@link ExchangePattern#InOut} message exchange pattern.
* <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
@@ -655,6 +670,20 @@
Object requestBodyAndHeaders(Endpoint endpoint, Object body, Map<String, Object> headers);
/**
+ * Sends the body to the default endpoint and returns the result content
+ * Uses an {@link ExchangePattern#InOut} message exchange pattern.
+ * <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
+ * it is thrown from this method as a {@link org.apache.camel.CamelExecutionException} with
+ * the caused exception wrapped.
+ *
+ * @param body the payload to send
+ * @param headers headers
+ * @return the result (see class javadoc)
+ * @throws CamelExecutionException if the processing of the exchange failed
+ */
+ Object requestBodyAndHeaders(Object body, Map<String, Object> headers);
+
+ /**
* Sends the body to an endpoint with the specified headers and header values.
* Uses an {@link ExchangePattern#InOut} message exchange pattern.
* <p/><b>Notice:</b> that if the processing of the exchange failed with an Exception
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java?rev=892267&r1=892266&r2=892267&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultProducerTemplate.java Fri Dec 18 15:00:46 2009
@@ -255,6 +255,10 @@
return sendBody(endpoint, ExchangePattern.InOut, body);
}
+ public Object requestBodyAndHeader(Object body, String header, Object headerValue) {
+ return sendBodyAndHeader(getMandatoryDefaultEndpoint(), ExchangePattern.InOut, body, header, headerValue);
+ }
+
public Object requestBodyAndHeader(Endpoint endpoint, Object body, String header, Object headerValue) {
return sendBodyAndHeader(endpoint, ExchangePattern.InOut, body, header, headerValue);
}
@@ -279,6 +283,10 @@
return sendBodyAndHeaders(endpoint, ExchangePattern.InOut, body, headers);
}
+ public Object requestBodyAndHeaders(final Object body, final Map<String, Object> headers) {
+ return sendBodyAndHeaders(getDefaultEndpoint(), ExchangePattern.InOut, body, headers);
+ }
+
public <T> T requestBody(Object body, Class<T> type) {
Object answer = requestBody(body);
return context.getTypeConverter().convertTo(type, answer);
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanNoTypeConvertionPossibleWhenHeaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanNoTypeConvertionPossibleWhenHeaderTest.java?rev=892267&r1=892266&r2=892267&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanNoTypeConvertionPossibleWhenHeaderTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/component/bean/BeanNoTypeConvertionPossibleWhenHeaderTest.java Fri Dec 18 15:00:46 2009
@@ -63,7 +63,7 @@
mock.expectedBodiesReceived("Hello World");
mock.message(0).header("foo").isNull();
- template.requestBodyAndHeader("direct:start", "Hello World", "foo", null);
+ template.requestBodyAndHeader("direct:start", "Hello World", "foo", (Object) null);
assertMockEndpointsSatisfied();
}
Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java?rev=892267&r1=892266&r2=892267&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultProducerTemplateTest.java Fri Dec 18 15:00:46 2009
@@ -23,6 +23,7 @@
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
@@ -105,6 +106,33 @@
assertEquals(new Integer(123), out);
}
+ public void testRequestUsingDefaultEndpoint() throws Exception {
+ ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:out"));
+
+ Object out = producer.requestBody("Hello");
+ assertEquals("Bye Bye World", out);
+
+ out = producer.requestBodyAndHeader("Hello", "foo", 123);
+ assertEquals("Bye Bye World", out);
+
+ Map<String, Object> headers = new HashMap<String, Object>();
+ out = producer.requestBodyAndHeaders("Hello", headers);
+ assertEquals("Bye Bye World", out);
+ }
+
+ public void testSendUsingDefaultEndpoint() throws Exception {
+ ProducerTemplate producer = new DefaultProducerTemplate(context, context.getEndpoint("direct:in"));
+
+ getMockEndpoint("mock:result").expectedMessageCount(3);
+
+ producer.sendBody("Hello");
+ producer.sendBodyAndHeader("Hello", "foo", 123);
+ Map<String, Object> headers = new HashMap<String, Object>();
+ producer.sendBodyAndHeaders("Hello", headers);
+
+ assertMockEndpointsSatisfied();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {