Forum Home » Fuse Distributions » Fuse ESB

Thread: XPath on CXF payload

 

Permlink Replies: 1 - Last Post: Aug 22, 2011 1:05 PM Last Post By: njiang
dhoyt

Posts: 32
Registered: 03/03/11
XPath on CXF payload
Posted: Aug 19, 2011 10:09 PM
  Click to reply to this thread Reply
I have a CXF route which we are using a dataformat of PAYLOAD. When I get the response back, I want to try to match the XML and decide where the request should then be posted to. The problem is that I can not seem to be able to get to the XML from the PAYLOAD without first unwrapping it with a custom processor. Below is my route and custom processor. Is this the right way to to do it, or is there a better way (perhaps using the Simple Language). I tried using .setBody(simple("${property.MyRequest.body}")), but that did not help. Any thoughts are appreciated.

public void configure() throws Exception
{
String routeIdentifier = this.getClass().getName();
String toWebServiceURL = RouteHelper.getProperty("mainURL");
String listenerPort = RouteHelper.getProperty("webservice.inbound.port");
String listenerAddress = "http://0.0.0.0:" + listenerPort + "/MyService";

// Listen on the following URL
from("cxf://" + listenerAddress + //
"?portName=" + My_SERVICE_PORT + //
"&serviceName=" + My_SERVICE_NAME + //
"&wsdlURL=" + My_WSDL + //
"&dataFormat=PAYLOAD") //

// Name the route so the UI displays something useful
.routeId(routeIdentifier) //

// Save the Client Request in a property for later use
.setProperty("MyRequest", simple("${in.body}")) //

// Send the Client Request
.to("cxf://" + toWebServiceURL + //
"?portName=" + My_SERVICE_PORT + //
"&serviceName=" + My_SERVICE_NAME + //
"&wsdlURL=" + My_WSDL + //
"&dataFormat=PAYLOAD") //

// Save the My Response in a property for later comparison
.setProperty("MyResponse", simple("${in.body}")) //

// Unwrap the payload
.process(new CxfPayloadUnwrapper()) //

// If the response contains a ResponseCode element with a value of 0, send it to the topic
.choice().when(xpath("/*/*My:ResponseCode = 0 and not(My:Error)").namespace("My", My_TARGET_NAME_SPACE)) //

// Set the body back to the request so we can post it to the topic
.setBody(property("MyRequest")) //

// Unwrap the payload
.process(new CxfPayloadUnwrapper()) //

// We need to make the MEP in-only since there is no response from the topic.
.inOnly() //
// Posting to the topic
.to(RouteHelper.buildTopicPublisherEndPoint(TOPIC_My_REQUEST))
// Setting the MEP back to in-out so we can return the response back to the caller
.inOut() //

// Set the body back to the response so we can return it to the caller
.setBody(property("MyResponse"));
}

public void process(Exchange exchange) throws Exception
{
if (exchange.getIn().getBody() instanceof CxfPayload)
{
@SuppressWarnings("rawtypes")
CxfPayload payload = (CxfPayload) exchange.getIn().getBody();

// Grab the first CxfPayload body
// and make it the Exchange body.
for (Object o : payload.getBody())
{
exchange.getIn().setBody(o);
break;
}
}
}

njiang

Posts: 572
Registered: 09/17/07
Re: XPath on CXF payload
Posted: Aug 22, 2011 1:05 PM   in response to: dhoyt in response to: dhoyt
  Click to reply to this thread Reply
Before you call simple("${property.MyRequest.body}", you need to store the payload element into the exchange property. I'm not sure if you already did that.