Search in sources :

Example 26 with Message

use of org.apache.camel.Message in project camel by apache.

the class NettyHttpBridgeRouteUsingHttpClientTest method createRouteBuilder.

protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() {
            port1 = getPort();
            port2 = getNextPort();
            errorHandler(noErrorHandler());
            Processor serviceProc = new Processor() {

                public void process(Exchange exchange) throws Exception {
                    // get the request URL and copy it to the request body
                    String uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class);
                    exchange.getOut().setBody(uri);
                }
            };
            from("netty4-http:http://localhost:" + port2 + "/test/hello").to("http://localhost:" + port1 + "?throwExceptionOnFailure=false&bridgeEndpoint=true");
            from("netty4-http:http://localhost:" + port1 + "?matchOnUriPrefix=true").process(serviceProc);
            // check the from request
            from("netty4-http:http://localhost:" + port2 + "/form?bridgeEndpoint=true").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    // just take out the message body and send it back
                    Message in = exchange.getIn();
                    String request = in.getBody(String.class);
                    exchange.getOut().setBody(request);
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) Message(org.apache.camel.Message) RuntimeCamelException(org.apache.camel.RuntimeCamelException)

Example 27 with Message

use of org.apache.camel.Message in project camel by apache.

the class NettyHttpConvertPayloadToInputStreamTest method testConvertPayloadToInputStream.

@Test
public void testConvertPayloadToInputStream() throws Exception {
    MockEndpoint mockEndpoint = getMockEndpoint("mock:result");
    mockEndpoint.expectedMessageCount(1);
    template.requestBodyAndHeader("netty4-http:http://localhost:{{port}}/test", expectedBody, "Content-Type", "application/xml");
    mockEndpoint.assertIsSatisfied();
    List<Exchange> list = mockEndpoint.getReceivedExchanges();
    Exchange exchange = list.get(0);
    assertNotNull("exchange", exchange);
    Message in = exchange.getIn();
    assertNotNull("in", in);
    Object actual = in.getBody();
    InputStream value = assertIsInstanceOf(InputStream.class, actual);
    assertNotNull("InputStream", value);
}
Also used : Exchange(org.apache.camel.Exchange) Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 28 with Message

use of org.apache.camel.Message in project camel by apache.

the class PortProducer method doGet.

private void doGet(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(NeutronConstants.PORT_ID, String.class), String.class);
    ObjectHelper.notEmpty(id, "Port ID");
    final Port result = os.networking().port().get(id);
    msg.setBody(result);
}
Also used : Message(org.apache.camel.Message) Port(org.openstack4j.model.network.Port)

Example 29 with Message

use of org.apache.camel.Message in project camel by apache.

the class PortProducer method doUpdate.

private void doUpdate(Exchange exchange) {
    final Message msg = exchange.getIn();
    final Port port = messageToPort(msg);
    final Port updatedPort = os.networking().port().update(port);
    msg.setBody(updatedPort);
}
Also used : Message(org.apache.camel.Message) Port(org.openstack4j.model.network.Port)

Example 30 with Message

use of org.apache.camel.Message in project camel by apache.

the class RouterProducer method doGet.

private void doGet(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String id = msg.getHeader(OpenstackConstants.ID, msg.getHeader(NeutronConstants.ROUTER_ID, String.class), String.class);
    ObjectHelper.notEmpty(id, "Router ID");
    final Router result = os.networking().router().get(id);
    msg.setBody(result);
}
Also used : Message(org.apache.camel.Message) Router(org.openstack4j.model.network.Router)

Aggregations

Message (org.apache.camel.Message)810 Exchange (org.apache.camel.Exchange)379 Test (org.junit.Test)262 Processor (org.apache.camel.Processor)120 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)109 DefaultMessage (org.apache.camel.impl.DefaultMessage)67 DefaultExchange (org.apache.camel.impl.DefaultExchange)50 Endpoint (org.apache.camel.Endpoint)46 HashMap (java.util.HashMap)41 InputStream (java.io.InputStream)39 Response (javax.ws.rs.core.Response)38 ArrayList (java.util.ArrayList)33 RouteBuilder (org.apache.camel.builder.RouteBuilder)33 Map (java.util.Map)27 Producer (org.apache.camel.Producer)27 Customer (org.apache.camel.component.cxf.jaxrs.testbean.Customer)25 ActionResponse (org.openstack4j.model.common.ActionResponse)25 IOException (java.io.IOException)24 List (java.util.List)23 CamelContext (org.apache.camel.CamelContext)23