Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-8723

Add desired message type to ProducerTemplate.sendBody methods

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Major
    • Resolution: Resolved
    • 2.15.1
    • 2.18.0
    • camel-core
    • Moderate

    Description

      Using Pojo Messaging annotations, Camel automatically uses the Type Converter system to unmarshall XML messages to JAXB objects in the following scenario:

      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);
          }
      }
      

      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:

        /**
           * 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;
      
      

      This would allow users to send a JAXB object and instruct Camel to use its Type Converter system to marshall the object to XML:

      producer.sendBody(jaxbObject, String.class);
      

      Note: The sendBody, sendBodyAndHeader and sendBodyAndProperty methods are all overloaded several times which could mean quite a number of new methods.

      Attachments

        1. camel-8723.patch
          12 kB
          Geert Schuring

        Issue Links

          Activity

            People

              lb Luca Burgazzoli
              cathodion Geert Schuring
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: