6 Replies Latest reply on Sep 29, 2010 2:53 AM by Claus Ibsen

    Exposing REST interface using Camel and SMX

    Ramesh Ramakrishnan Newbie

      Hello All,


      I have a beginner's question in integrating REST service with Camel. My requirement is to expose a REST service as http endpoint (takes both JSON and XML) and transform the input request to output by following a route sequence.


      I used cxf:rs server element to expose my REST as http endpoint and here is my sample route.


      from("cxfrs://bean://orderService") // STEP 1

          .convertBodyTo(CustomOrderPojo.class)  // STEP 2

          .to("xslt:convertCustomOrder.xsl)  // STEP 3

          .to("jbi:servce:WSDL_LOCATION?mep=In-OUT")  // STEP 4

          .to("xslt:convertSOAPResponseToCustomOrder.xml")  // STEP 5

          .convertBodyTo(CustomOrderPojo.class)  // STEP 6


      STEP 1: Receive a JSON or XML when client involes REST Soap

      STEP 2: Convert incoming XML or JSON to the object as expected by REST method

      STEP 3:Convert POJO to xml which will act as Payload (soap:body) for JBI soap call

      STEP 4: Invoke SOAP service using jbi:service endpoint

      STEP 5: TRansform the result of SOAP call back to Custom Order pojo with populated values

      STEP 6: Unmarshal it back to POJO.


      My understanding is, once the last part of chain is reached, the BODY is sent back to the original sender i.e. the person calling the Service.


      Is this the right approach?


      Problems am facing.


      1. With ConverBody at step 2, its throwing

      Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: java.lang.Object[] to the required type: CustomOrderPojo.class


      2. If i remove the convertBodyTo and feed the input XML/JSON to the xsl, am getting the following exception

      org.apache.camel.ExpectedBodyTypeException: Could not extract IN message body as type: interface javax.xml.transform.Source body is: [Ljava.lang.Object;@54c90c7


      Can anyone pointme to a working example which performs this logic?