0 Replies Latest reply on Mar 11, 2015 12:13 PM by szarekar

    How to invoke a rest service from Camel routes

    szarekar

      Thanks Grzegorz

      This is what i am trying to achieve

       

      1) REST UI http://localhost:9090/route/customerservice/customers/GOOG

       

      2) Calls :http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=RHT   FROM camel endpoint ) But it throws error

       

      MY CONFIGURATION and class files are :

       

      1 )Call http://localhost:9090/route/customerservice/customers/GOOG from REST UI

       

      2) This invokes my Route

       

      public class CustomerServiceRoute extends RouteBuilder {

          @Override

          public void configure() throws Exception {

              getContext().setTracing(true);

              from("cxfrs://http://localhost:9090/route?resourceClasses=com.fusesource.samples.CustomerServiceResource")    

                      .to("cxfrs://http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=GOOG")

                      .to("file:target/goog");

          }

      }

       

       

      Class CustomerServiceResource

       

      @Path("/customerservice/")

      public class CustomerServiceResource {

          @Context

          private UriInfo uriInfo;

       

          public CustomerServiceResource() {

          }

          @GET

          @Path("/customers/{id}/")

          @Produces("text/xml")

          public Customer getCustomer(@PathParam("id") String id) {

              return null;

          }

       

      }

       

      CAMEL.XML

       

      <cxf:rsServer id="rsServer" address="http://localhost:9090/route"

                        serviceClass="com.fusesource.samples.CustomerServiceResource"/>

          <bean id="customerServProcessor" class="com.fusesource.samples.CustomerServiceProcessor"/>

       

          <bean id="routeBuilder" class="com.fusesource.samples.CustomerServiceRoute"/>

          <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

              <routeBuilder ref="routeBuilder"/>

          </camelContext>

       

       

           #############################Getting error on REST UI CLIENT########################

       

      System.InvalidOperationException: GetQuote/customerservice/customers/GOOG Web Service method name is not valid.

         at System.Web.Services.Protocols.HttpServerProtocol.Initialize()

         at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)

       

      ################################ ERROR ON JBOSS DEVELOPMENT STUDIO CONSOLE##############

       

      qtp453346759-15 ERROR [org.apache.camel.processor.DefaultErrorHandler] - Failed delivery for (MessageId: ID-BMC4000LJVCNP12-57546-1426087062332-0-1 on ExchangeId: ID-BMC4000LJVCNP12-57546-1426087062332-0-2). Exhausted after delivery attempt: 1 caught: javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error

       

       

      Message History

      ---------------------------------------------------------------------------------------------------------------------------------------

      RouteId              ProcessorId          Processor                                                                        Elapsed (ms)

      [route1            ] [route1            ] [cxfrs://http://localhost:9090/route?resourceClasses=com.fusesource.samples.Cus] [       591]

      [route1            ] [setHeader1        ] [setHeader[CamelFileName]                                                      ] [        19]

      [route1            ] [to1               ] [cxfrs://http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=GOOG       ] [       569]

       

       

      Stacktrace

      ---------------------------------------------------------------------------------------------------------------------------------------

      javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructo