camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-8723) Add desired message type to ProducerTemplate.sendBody methods
Date Fri, 01 May 2015 06:46:06 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-8723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14522840#comment-14522840
] 

Claus Ibsen commented on CAMEL-8723:
------------------------------------

I think its maybe time we have a producer template that uses the builder pattern? The template
itself has 

{code}
ProducerTemplateBuider template = ...

template.withBodyAs(body, String.class).addHeader("foo", 123).addHeader("bar", 456).send();
template.withBodyAs(body, String.class).addHeader("foo", 123).addHeader("bar", 456).to("jms:queue:bla").send();

template.withBodyAs(body, String.class).addHeader("foo", 123).addHeader("bar", 456).withPattern(ExchangePattern.InOnly).send();
Exchange out = template.withBodyAs(body, String.class).addHeader("foo", 123).addHeader("bar",
456).request();
Object reply = template.withBodyAs(body, String.class).addHeader("foo", 123).addHeader("bar",
456).requestBody();
String reply = template.withBodyAs(body, String.class).addHeader("foo", 123).addHeader("bar",
456).requestBodyAs(String.class);
{code}

And you can get the builder from the existing producer template
{code}
ProducerTemplateBuilder builder = template.builder();
...
{code}

And it would also work with the existing @Produce annotations so you can IoC inject it

{code}
@Produce(uri = "jms:queue:foo")
private ProducerTemplateBuilder template;
{code}

> Add desired message type to ProducerTemplate.sendBody methods
> -------------------------------------------------------------
>
>                 Key: CAMEL-8723
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8723
>             Project: Camel
>          Issue Type: New Feature
>          Components: camel-core
>    Affects Versions: 2.15.1
>            Reporter: Geert Schuring
>              Labels: pojo, type-converter
>             Fix For: 2.16.0
>
>         Attachments: camel-8723.patch
>
>
> Using Pojo Messaging annotations, Camel automatically uses the Type Converter system
to unmarshall XML messages to JAXB objects in the following scenario:
> {code:java}
> public class CamelPojoDemo {
> 	
>     @Produce(uri = "amq:camelpojodemo.reply")
>     private ProducerTemplate producer;
> 	
>     @Consume(uri = "amq:camelpojodemo.request")
>     public void trigger(UpdateMarketDataMessage message) {
>     	String result = "Processed prices: " + message.getMarketData().getPrices().size();
>     	producer.sendBody(result);
>     }
> }
> {code}
> However, handing the producer a JAXB object and expecting it to marshall it to XML before
sending it does not seem possible in the current API.
> I would like to propose to add the following method to the ProducerTemplate:
> {code}
>   /**
>      * Sends the body to the default endpoint after converting it to the given type
>      * <br/><br/>
>      * <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 type the type which the body should be converted to before sending
>      * @throws CamelExecutionException if the processing of the exchange failed
>      */
>     void sendBody(Object body, Class type) throws CamelExecutionException;
> {code}
> This would allow users to send a JAXB object and instruct Camel to use its Type Converter
system to marshall the object to XML:
> {code}
> producer.sendBody(jaxbObject, String.class);
> {code}
> Note: The sendBody, sendBodyAndHeader and sendBodyAndProperty methods are all overloaded
several times which could mean quite a number of new methods. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message