Shockwave
Shockwave

Reputation: 1

Invoking a rest service passing dynamic key value parameters using cxf-rs components

I have to create a Fuse service which would in-turn invoke a REST service exposed by an external service provider. Fuse service will be receiving request in XML format and converting to a query string before invoking the REST service.

Sample request XML for Fuse service -

<CustomerDetails>
<CustomerName>ABC</CustomerName>
<CustomerAge>28</CustomerAge>
<CustomerName>DEF</CustomerName>
<CustomerAge>54</CustomerAge>
<CustomerDetails>

The REST service consumes request in key value params and responds back in XML format.

sample URL:

https://www.customer.com/cust/api/v1/store/abc.xml?Customername=ABC&Customerage=28&Customername=DEF&customerage=54)

I have tried searching a lot but couldn't find any tutorial in the net.

Can someone please provide suggestions on how to implement the fuse service using cxf-rs components (preferably Spring DSL camel configuration )

Thanks in advance..

Upvotes: 0

Views: 1339

Answers (1)

Willem Jiang
Willem Jiang

Reputation: 3291

If you just want to turn the XML request to the url parameter, you can just use jaxb data format to unmarshal the request and use a bean object to setup the URI request parameters. You don't need to use camel-cxf component.

from("direct:start").unmarshal(jaxb).process(new Processor() {
      public void process(Exchange exchange) throws Exception {
          // get the request object
          CustomerDetail request = exchange.getIn().getBody();
          // Just mapping the request object into a query parameters.
          String query = requestToParameter(request);
          exchange.getIn().setHeader(Exchange.HTTP_QUERY, query);
          // to remove the body, so http endpoint can send the request with Get Method 
          exchange.getIn().setBody(null);
     }).to("https://www.customer.com/cust/api/v1/store/abc.xml");

Upvotes: 0

Related Questions