use of org.apache.camel.Processor in project camel by apache.
the class CamelEndpointSpringConfigureTest method testCreateDestinationFromSpring.
@Test
public void testCreateDestinationFromSpring() throws Exception {
CxfEndpoint cxfEndpoint = context.getEndpoint("cxf:bean:serviceEndpoint", CxfEndpoint.class);
CxfProducer producer = (CxfProducer) cxfEndpoint.createProducer();
assertNotNull("The producer should not be null", producer);
producer.start();
CamelConduit conduit = (CamelConduit) producer.getClient().getConduit();
assertTrue("we should get SpringCamelContext here", conduit.getCamelContext() instanceof SpringCamelContext);
assertEquals("The context id should be camel_conduit", "camel_conduit", conduit.getCamelContext().getName());
cxfEndpoint = context.getEndpoint("cxf:bean:routerEndpoint", CxfEndpoint.class);
CxfConsumer consumer = (CxfConsumer) cxfEndpoint.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
// do nothing here
}
});
assertNotNull("The consumer should not be null", consumer);
consumer.start();
CamelDestination destination = (CamelDestination) consumer.getServer().getDestination();
assertTrue("we should get SpringCamelContext here", destination.getCamelContext() instanceof SpringCamelContext);
assertEquals("The context id should be camel_destination", "camel_destination", destination.getCamelContext().getName());
}
use of org.apache.camel.Processor in project camel by apache.
the class CxfRawMessageRouterTest method testTheContentTypeOnTheWire.
@Test
public void testTheContentTypeOnTheWire() throws Exception {
Exchange exchange = template.send(getRouterAddress(), new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body><ns1:echo xmlns:ns1=\"http://cxf.component.camel.apache.org/\">" + "<arg0 xmlns=\"http://cxf.component.camel.apache.org/\">hello world</arg0>" + "</ns1:echo></soap:Body></soap:Envelope>");
}
});
assertNotNull("We should get the Content-Type here", MessageHelper.getContentType(exchange.getOut()));
assertTrue("Get wrong content type", MessageHelper.getContentType(exchange.getOut()).startsWith("text/xml"));
assertNotNull("We should get the content-type here", exchange.getOut().getHeader("content-type"));
String response = exchange.getOut().getBody(String.class);
assertNotNull("Response should not be null", response);
assertTrue("We should get right return result", response.indexOf("echo hello world") > 0);
}
use of org.apache.camel.Processor in project camel by apache.
the class CxfMessageStreamExceptionTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// START SNIPPET: onException
from("direct:start").onException(SoapFault.class).maximumRedeliveries(0).handled(true).process(new Processor() {
public void process(Exchange exchange) throws Exception {
SoapFault fault = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, SoapFault.class);
exchange.getOut().setFault(true);
exchange.getOut().setBody(fault);
}
}).end().to(serviceURI);
// END SNIPPET: onException
// START SNIPPET: MessageStreamFault
from(routerEndpointURI).process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message out = exchange.getOut();
// Set the message body with the
out.setBody(this.getClass().getResourceAsStream("SoapFaultMessage.xml"));
// Set the response code here
out.setHeader(org.apache.cxf.message.Message.RESPONSE_CODE, new Integer(500));
}
});
// END SNIPPET: MessageStreamFault
}
};
}
use of org.apache.camel.Processor 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.Processor 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);
}
};
}
Aggregations