Search in sources :

Example 6 with HttpMessage

use of org.apache.camel.http.common.HttpMessage in project camel by apache.

the class RestletProducerSessionTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() {
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").to(url).to(url).to("mock:result");
            from("direct:instance").to(url + "&cookieHandler=#instanceCookieHandler").to(url + "&cookieHandler=#instanceCookieHandler").to("mock:result");
            from("direct:exchange").to(url + "&cookieHandler=#exchangeCookieHandler").to(url + "&cookieHandler=#exchangeCookieHandler").to("mock:result");
            from("jetty://http://127.0.0.1:" + portNum + "/session?sessionSupport=true").process(new Processor() {

                public void process(Exchange exchange) throws Exception {
                    HttpMessage message = exchange.getIn(HttpMessage.class);
                    HttpSession session = message.getRequest().getSession();
                    String body = message.getBody(String.class);
                    if (body.length() > 2) {
                        body = body.substring(1, body.length() - 1);
                    }
                    if ("bar".equals(session.getAttribute("foo"))) {
                        body = "{Old " + body + "}";
                    } else {
                        session.setAttribute("foo", "bar");
                        body = "{New " + body + "}";
                    }
                    exchange.getOut().setBody(body);
                    exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json");
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpSession(javax.servlet.http.HttpSession) HttpMessage(org.apache.camel.http.common.HttpMessage)

Example 7 with HttpMessage

use of org.apache.camel.http.common.HttpMessage in project camel by apache.

the class Http4RouteTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    port1 = AvailablePortFinder.getNextAvailable(8000);
    port2 = AvailablePortFinder.getNextAvailable(9000);
    return new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("jetty:http://localhost:" + port1 + "/test").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    HttpMessage message = (HttpMessage) exchange.getIn();
                    assertNotNull(message.getRequest());
                    assertEquals("GET", message.getRequest().getMethod());
                    exchange.getOut().setBody(message.getRequest().getQueryString());
                }
            });
            from("jetty:http://localhost:" + port2 + "/test").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    HttpMessage message = (HttpMessage) exchange.getIn();
                    assertNotNull(message.getRequest());
                    assertEquals("GET", message.getRequest().getMethod());
                    exchange.getOut().setBody(message.getRequest().getQueryString() + "&2");
                }
            });
            from("direct:start1").to("http4://localhost:" + port1 + "/test");
            from("direct:start2").to("http4://localhost:" + port2 + "/test");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpMessage(org.apache.camel.http.common.HttpMessage)

Example 8 with HttpMessage

use of org.apache.camel.http.common.HttpMessage in project camel by apache.

the class NettyHttpProducerSessionTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").toF("netty4-http:http://127.0.0.1:%d/session", getPort()).toF("netty4-http:http://127.0.0.1:%d/session", getPort()).to("mock:result");
            from("direct:instance").toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#instanceCookieHandler", getPort()).toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#instanceCookieHandler", getPort()).to("mock:result");
            from("direct:exchange").toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#exchangeCookieHandler", getPort()).toF("netty4-http:http://127.0.0.1:%d/session?cookieHandler=#exchangeCookieHandler", getPort()).to("mock:result");
            fromF("jetty:http://127.0.0.1:%d/session?sessionSupport=true", getPort()).process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    HttpMessage message = exchange.getIn(HttpMessage.class);
                    HttpSession session = message.getRequest().getSession();
                    String body = message.getBody(String.class);
                    if ("bar".equals(session.getAttribute("foo"))) {
                        message.setBody("Old " + body);
                    } else {
                        session.setAttribute("foo", "bar");
                        message.setBody("New " + body);
                    }
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpSession(javax.servlet.http.HttpSession) HttpMessage(org.apache.camel.http.common.HttpMessage)

Example 9 with HttpMessage

use of org.apache.camel.http.common.HttpMessage in project camel by apache.

the class HttpConverterTest method testNulls.

@Test
public void testNulls() throws Exception {
    HttpMessage msg = null;
    assertNull(HttpConverter.toInputStream(msg, null));
    assertNull(HttpConverter.toServletInputStream(msg));
    assertNull(HttpConverter.toServletRequest(msg));
    assertNull(HttpConverter.toServletResponse(msg));
    HttpServletRequest req = null;
    assertNull(HttpConverter.toInputStream(req, null));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpMessage(org.apache.camel.http.common.HttpMessage) Test(org.junit.Test)

Example 10 with HttpMessage

use of org.apache.camel.http.common.HttpMessage in project camel by apache.

the class JettyHttpProducerSessionTest method createRouteBuilder.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").to("jetty://" + getTestServerEndpointSessionUrl()).to("jetty://" + getTestServerEndpointSessionUrl()).to("mock:result");
            from("direct:instance").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#instanceCookieHandler").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#instanceCookieHandler").to("mock:result");
            from("direct:exchange").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#exchangeCookieHandler").to("jetty://" + getTestServerEndpointSessionUrl() + "?cookieHandler=#exchangeCookieHandler").to("mock:result");
            from(getTestServerEndpointSessionUri()).process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    HttpMessage message = exchange.getIn(HttpMessage.class);
                    HttpSession session = message.getRequest().getSession();
                    String body = message.getBody(String.class);
                    if ("bar".equals(session.getAttribute("foo"))) {
                        message.setBody("Old " + body);
                    } else {
                        session.setAttribute("foo", "bar");
                        message.setBody("New " + body);
                    }
                }
            });
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpSession(javax.servlet.http.HttpSession) HttpMessage(org.apache.camel.http.common.HttpMessage)

Aggregations

HttpMessage (org.apache.camel.http.common.HttpMessage)14 Exchange (org.apache.camel.Exchange)13 Processor (org.apache.camel.Processor)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)8 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 HttpSession (javax.servlet.http.HttpSession)5 IOException (java.io.IOException)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ServletException (javax.servlet.ServletException)2 ServletInputStream (javax.servlet.ServletInputStream)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpConsumer (org.apache.camel.http.common.HttpConsumer)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 TimeoutException (java.util.concurrent.TimeoutException)1 AsyncCallback (org.apache.camel.AsyncCallback)1 Message (org.apache.camel.Message)1 Route (org.apache.camel.Route)1 InputStreamCache (org.apache.camel.converter.stream.InputStreamCache)1