Search in sources :

Example 21 with RouteBuilder

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
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder)

Example 22 with RouteBuilder

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");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) UnknownPersonFault(org.apache.camel.wsdl_first.UnknownPersonFault)

Example 23 with RouteBuilder

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();
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(org.apache.camel.Message) List(java.util.List)

Example 24 with RouteBuilder

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);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Bus(org.apache.cxf.Bus) RouteBuilder(org.apache.camel.builder.RouteBuilder) JettyHTTPServerEngine(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngine) JettyHTTPServerEngineFactory(org.apache.cxf.transport.http_jetty.JettyHTTPServerEngineFactory) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 25 with RouteBuilder

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
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) SoapFault(org.apache.cxf.binding.soap.SoapFault) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(org.apache.camel.Message)

Aggregations

RouteBuilder (org.apache.camel.builder.RouteBuilder)1744 Exchange (org.apache.camel.Exchange)624 Processor (org.apache.camel.Processor)542 Test (org.junit.Test)470 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)338 CamelExecutionException (org.apache.camel.CamelExecutionException)135 FailedToCreateRouteException (org.apache.camel.FailedToCreateRouteException)119 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)100 File (java.io.File)65 IOException (java.io.IOException)61 CamelContext (org.apache.camel.CamelContext)61 ResolveEndpointFailedException (org.apache.camel.ResolveEndpointFailedException)42 HashMap (java.util.HashMap)34 Path (org.apache.hadoop.fs.Path)34 CountDownLatch (java.util.concurrent.CountDownLatch)32 Configuration (org.apache.hadoop.conf.Configuration)32 ArrayFile (org.apache.hadoop.io.ArrayFile)30 SequenceFile (org.apache.hadoop.io.SequenceFile)30 Endpoint (org.apache.camel.Endpoint)27 RuntimeCamelException (org.apache.camel.RuntimeCamelException)26