use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CxfMixedModeRouterTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
errorHandler(noErrorHandler());
from(routerEndpointURI).process(new Processor() {
// convert request message
public void process(Exchange exchange) throws Exception {
CxfPayload<?> message = exchange.getIn().getBody(CxfPayload.class);
List<String> params = new ArrayList<String>();
if (message != null) {
// convert CxfPayload to list of objects any way you like
Element element = new XmlConverter().toDOMElement(message.getBody().get(0));
params.add(element.getFirstChild().getTextContent());
}
// replace the body
exchange.getIn().setBody(params);
// if you need to change the operation name
//exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, GREET_ME_OPERATION);
}
}).to(serviceEndpointURI).process(new Processor() {
// convert response to CxfPayload
public void process(Exchange exchange) throws Exception {
List<?> list = exchange.getIn().getBody(List.class);
CxfPayload<SoapHeader> message = null;
if (list != null) {
// convert the list of objects to CxfPayload any way you like
String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<ns1:echoResponse xmlns:ns1=\"http://cxf.component.camel.apache.org/\">" + "<return xmlns=\"http://cxf.component.camel.apache.org/\">" + list.get(0) + "</return></ns1:echoResponse>";
List<Element> body = new ArrayList<Element>();
body.add(StaxUtils.read(new StringReader(s)).getDocumentElement());
message = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(), body);
}
exchange.getIn().setBody(message);
// we probably should be smarter in detecting data format based on message body
// but for now we need to explicitly reset the mode (see CAMEL-3420)
exchange.setProperty(CxfConstants.DATA_FORMAT_PROPERTY, DataFormat.PAYLOAD);
}
});
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CxfPayLoadMessageRouterAddressOverrideTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(routerEndpointURI).process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.DESTINATION_OVERRIDE_URL, getServiceAddress());
CxfPayload<?> payload = exchange.getIn().getBody(CxfPayload.class);
List<Source> elements = payload.getBodySources();
assertNotNull("We should get the elements here", elements);
assertEquals("Get the wrong elements size", elements.size(), 1);
Element el = new XmlConverter().toDOMElement(elements.get(0));
assertEquals("Get the wrong namespace URI", el.getNamespaceURI(), "http://cxf.component.camel.apache.org/");
}
}).to(serviceEndpointURI);
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CxfPayLoadMessageXmlBindingRouterTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from("cxf:bean:routerEndpoint?dataFormat=PAYLOAD").process(new Processor() {
public void process(Exchange exchange) throws Exception {
CxfPayload<?> payload = exchange.getIn().getBody(CxfPayload.class);
List<Source> elements = payload.getBodySources();
assertNotNull("We should get the elements here", elements);
assertEquals("Get the wrong elements size", elements.size(), 1);
Element el = new XmlConverter().toDOMElement(elements.get(0));
assertEquals("Get the wrong namespace URI", el.getNamespaceURI(), "http://cxf.component.camel.apache.org/");
}
}).to("cxf:bean:serviceEndpoint?dataFormat=PAYLOAD");
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CxfPayLoadSoapHeaderTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// START SNIPPET: payload
from(getRouterEndpointURI()).process(new Processor() {
@SuppressWarnings("unchecked")
public void process(Exchange exchange) throws Exception {
CxfPayload<SoapHeader> payload = exchange.getIn().getBody(CxfPayload.class);
List<Source> elements = payload.getBodySources();
assertNotNull("We should get the elements here", elements);
assertEquals("Get the wrong elements size", 1, elements.size());
Element el = new XmlConverter().toDOMElement(elements.get(0));
elements.set(0, new DOMSource(el));
assertEquals("Get the wrong namespace URI", "http://camel.apache.org/pizza/types", el.getNamespaceURI());
List<SoapHeader> headers = payload.getHeaders();
assertNotNull("We should get the headers here", headers);
assertEquals("Get the wrong headers size", headers.size(), 1);
assertEquals("Get the wrong namespace URI", ((Element) (headers.get(0).getObject())).getNamespaceURI(), "http://camel.apache.org/pizza/types");
// alternatively you can also get the SOAP header via the camel header:
headers = exchange.getIn().getHeader(Header.HEADER_LIST, List.class);
assertNotNull("We should get the headers here", headers);
assertEquals("Get the wrong headers size", headers.size(), 1);
assertEquals("Get the wrong namespace URI", ((Element) (headers.get(0).getObject())).getNamespaceURI(), "http://camel.apache.org/pizza/types");
}
}).to(getServiceEndpointURI());
// END SNIPPET: payload
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class LoadDistributorFeatureTest method startRoute.
private void startRoute(DefaultCamelContext ctx, final String proxy, final String real) throws Exception {
ctx.addRoutes(new RouteBuilder() {
public void configure() {
List<String> serviceList = new ArrayList<String>();
serviceList.add(SERVICE_ADDRESS_1);
serviceList.add(SERVICE_ADDRESS_2);
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(serviceList);
LoadDistributorFeature ldf = new LoadDistributorFeature();
ldf.setStrategy(strategy);
CxfEndpoint endpoint = (CxfEndpoint) (endpoint(real));
endpoint.getFeatures().add(ldf);
from(proxy).to(endpoint);
}
});
ctx.start();
}
Aggregations