I am new to the Fuse-camel,cxf.
i wan to invoke third party webservice. i don't want to use wsld2java or serviceclass. I have a wsdl.
Here is the requirement to make generic webservice call
json request data-->generate soap request --> cxf:endpoint in PAYLOAD format-->soap response -->json response data to client.
1 . how do i convert json to soaprequest(xml) and vice-versa ( Marshall-format-soapjxab is expecting jaxb annotated classes)
2.how do I call in soap in payload mode..
any help (link/example) is greatly appreciated.
Thanks,
Narendra
You can use Camel CXFRS to set up rest endpoints.
On parsing the JSON, set the values to JAXB annotated POJO's.
Then use ProducerTemplate to send SOAP request to third party service.
On receiving the response you can unmarshal it, either using JAXB unmarshaller in java code or incase of DSL use Camel JAXB DataFormat
Route the response to the client by setting the content in camel exchange.
Related
currently, for a server to server communication, we have our own authentication method which will expect a random key in the HTTP request header.is there a way I can extend the camle HTTP to add the header for all the HTTP request call. Note we have 4 camel context XML and each camel context have 10 routes which make the HTTP request
You could also use Camel interceptors in order to add your custom header to (all or some) "http:*"-like endpoints.
Have a look at:
http://camel.apache.org/intercept.html
I have an Apache camel application which talks with a web service. This is purely a integration(mediation) application. We take REST request and transform it to a SOAP message (using VM templates) and call the web service. Receive response from web service, transform it to JSON and send back to our client.
REST ---->transform to SOAP req (Velocity template) ---->call WS ---->receive response---->transform into JSON---->return response to caller.
We are using servlet endpoint to receive request from our client. We can obtain HttpSession object from exchange before calling web service as follows :
HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
HttpSession session = req.getSession();
However, the problem is that I cannot obtain HTTPSession from exchange after receiving response from web service. If I check the Exchange object in debug mode, the Exchange.getIn() is of type DefaultMessage rather than HttpMessage. That is the reason I think I loose Request and response objects.
I tried setting the exchange pattern to InOut but that doesn’t help.
The only solution I could find is to store the original body of the in message in a header or a property and retrieve it at the end. But I think there must be a better solution that this.
Could anybody help please?
Note: We need HttpSession so that we can store corresponding session information like session id created on WS for the session created by our request. We cannot pass session information created on WS to our callers, and need a place on our application to hold this mapping info. HttpSession serves this requirement. Is there any better way?
You can store the http session as an exchange property, camel copy these properties across the exchanges, so you can access it in the route when you need.
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..
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");
How to Send POST method with multipart request using CAMEL
I have an application with camel setup and i need to attach documents and send and HTTP POST request.
How can i do this,
You can always write some java code with the apache httpcompenents library. see http://hc.apache.org/
It is not difficult to use
I am routing my webservice request to a bean which sends the response back to the service.
<camel:from uri="cxf:bean:authTest" />
<camel:to uri="bean:routeExitResponseProcessor"/>
Now in the bean class I have to implement Processor interface, access the Exchange object , call the implementation method and then send the response back to the client by setting the response object to exchange's body.
Can I get rid of all the Camel specific java code and configure everything in my applicationContext.xml?
If you use the bean component you do not have to implement the Processor interface.
If your class simply has one public method then it will be called and camel will try to convert the incoming body to your parameter and process the return as new body.
Try with a method like:
WebServiceResult myMethod(WebServiceInput input) {...}
Where the Parameters are those generated from the wsdl.
Christian