use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class JaxWSCamelConduitTest method createRouteBuilder.
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:start1").setBody(constant(ANSWER));
from("direct:start2").setBody(constant(ANSWER)).log("Force pipeline creation");
from("direct:start3").choice().when(header(Exchange.CONTENT_TYPE).isEqualTo("text/xml; charset=UTF-8")).process(new Processor() {
public void process(final Exchange exchange) {
exchange.getOut().setBody(ANSWER);
}
});
// otherwise you will get the request message back
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CxfConsumerFaultWithRouteTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
final String serviceURI = "cxf://" + serviceAddress + "?" + PORT_NAME_PROP + "&" + SERVICE_NAME_PROP + "&" + WSDL_URL_PROP + "&serviceClass=org.apache.camel.wsdl_first.Person";
return new RouteBuilder() {
public void configure() {
from(serviceURI).process(new Processor() {
public void process(final Exchange exchange) throws Exception {
// set the fault message here
org.apache.camel.wsdl_first.types.UnknownPersonFault faultDetail = new org.apache.camel.wsdl_first.types.UnknownPersonFault();
faultDetail.setPersonId("");
UnknownPersonFault fault = new UnknownPersonFault("Get the null value of person name", faultDetail);
throw fault;
}
}).to("log:myfaultlog");
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CxfConsumerWithTryCatchTest method createRouteBuilder.
// START SNIPPET: example
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(SIMPLE_ENDPOINT_URI).choice().when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_OPERATION)).process(new Processor() {
public void process(final Exchange exchange) {
Message in = exchange.getIn();
// Get the parameter list
List<?> parameter = in.getBody(List.class);
// Get the operation name
String operation = (String) in.getHeader(CxfConstants.OPERATION_NAME);
Object result = operation + " " + (String) parameter.get(0);
// Put the result back
exchange.getOut().setBody(result);
}
}).when(header(CxfConstants.OPERATION_NAME).isEqualTo(ECHO_BOOLEAN_OPERATION)).doTry().process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
throw new IllegalStateException();
}
}).doCatch(IllegalStateException.class).process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
// Get the parameter list
List<?> parameter = in.getBody(List.class);
// Put the result back
exchange.getOut().setBody(parameter.get(0));
}
}).end();
}
};
}
use of org.apache.camel.builder.RouteBuilder in project camel by apache.
the class CxfCustomerStartStopTest method startAndStopService.
@Test
public void startAndStopService() throws Exception {
CamelContext context = new DefaultCamelContext();
// start a server
context.addRoutes(new RouteBuilder() {
public void configure() {
from("cxf:http://localhost:" + PORT1 + "/test?serviceClass=org.apache.camel.component.cxf.HelloService").to("log:endpoint");
}
});
context.start();
Thread.sleep(300);
context.stop();
Bus bus = BusFactory.getDefaultBus();
JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
JettyHTTPServerEngine engine = factory.retrieveJettyHTTPServerEngine(PORT1);
assertNotNull("Jetty engine should be found there", engine);
// Need to call the bus shutdown ourselves.
String orig = System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", "false");
bus.shutdown(true);
System.setProperty("org.apache.cxf.transports.http_jetty.DontClosePort", orig == null ? "true" : "false");
engine = factory.retrieveJettyHTTPServerEngine(PORT1);
assertNull("Jetty engine should be removed", engine);
}
use of org.apache.camel.builder.RouteBuilder 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
}
};
}
Aggregations