2
votes

I am new to camel, i am trying to use camel cxf component to create a soap webservice. I started with a samples from camel in action. I have configured a route using cxf component and added a processor to process the request. I received the request in the bean i used to process the service but i cant able to send the response back to the client. Thanks in advance

This is the route i used :

<route>
<from uri="cxf:bean:orderEndpoint" />
<setExchangePattern pattern="InOut"/>
<to uri="bean:productService" />
</route>

This is the cxf endpoint i have configured,

<cxf:cxfEndpoint id="orderEndpoint"
                   address="/"
                   serviceClass="camelws.ws.ProductService"/>

This is the bean i used:

   @Service("productService")
public class ProductServiceImpl {
    public Product getProducts(){
        System.out.println("Inside webservices method....");
        Product product = new Product();
        product.setName("test product");
        product.setPrice("3242");
        return product;
    }

}

Sysout statement is printed on the console but i am getting a soap response with empty body.

below is my response when i hit http://localhost:9080// from browser:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body/>
</soap:Envelope>
2

2 Answers

2
votes

You should implement a Processor, intercept and process your message using something like that :

public class MyProcessor implements Processor {
  public void process(Exchange exchange) throws Exception {
    ...
    // Set your response here
    exchange.getOut().setBody(product);
  }
}

Then reference your processor in your route.

0
votes

Your response is what you have in your route body after your rote ends, so you must create your massege response object before route ends.