Package org.apache.camel.component.http

Examples of org.apache.camel.component.http.HttpMessage


            @Override
            public void configure() throws Exception {
                from("jetty://http://localhost:9080/test").
                        process(new Processor() {
                            public void process(Exchange exchange) throws Exception {
                                HttpMessage msg = exchange.getIn(HttpMessage.class);

                                InputStream sis = msg.getBody(InputStream.class);
                                assertNotNull(sis);
                                String s = exchange.getContext().getTypeConverter().convertTo(String.class, sis);

                                assertEquals("Hello World", s);
                            }
View Full Code Here


        assertEquals("Bye World", out);
    }

    @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));
View Full Code Here

        };
    }

    private class MyParamsProcessor implements Processor {
        public void process(Exchange exchange) throws Exception {
            HttpMessage message = (HttpMessage)exchange.getIn();
            Assert.assertNotNull(message.getRequest());
            Assert.assertEquals("uno", message.getRequest().getParameter("one"));
            Assert.assertEquals("dos", message.getRequest().getParameter("two"));

            exchange.getOut().setBody("Bye World");
            exchange.getOut().setHeader("one", "eins");
            exchange.getOut().setHeader("two", "zwei");
        }
View Full Code Here

                from("jetty:http://localhost:9280/test").to("mock:a");

                Processor proc = new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        try {
                            HttpMessage message = (HttpMessage)exchange.getIn();
                            HttpSession session = message.getRequest().getSession();
                            assertNotNull("we should get session here", session);
                        } catch (Exception e) {
                            exchange.getOut().setFault(true);
                            exchange.getOut().setBody(e);
                        }
View Full Code Here

               
                from("jetty:http://localhost:" + port + "/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());
                       
                    }
                   
                });
                  
View Full Code Here

                from("jetty:http://localhost:9080/test").to("mock:a");

                Processor proc = new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        try {
                            HttpMessage message = (HttpMessage)exchange.getIn();
                            HttpSession session = message.getRequest().getSession();
                            assertNotNull("we should get session here", session);
                        } catch (Exception e) {
                            exchange.getFault().setBody(e);
                        }
                        exchange.getOut().setBody("<b>Hello World</b>");
View Full Code Here

   
    @Test
    public void testReadRequest() {
        exchange.setFromEndpoint(endpoint);
        MockHttpServletRequest request = new MockHttpServletRequest();
        HttpMessage message = new HttpMessage(exchange, request, null);
        request.addHeader(GTaskBinding.GAE_QUEUE_NAME, "a");
        request.addHeader(GTaskBinding.GAE_TASK_NAME, "b");
        request.addHeader(GTaskBinding.GAE_RETRY_COUNT, "1");
        // test invocation of inbound binding via dynamic proxy
        endpoint.getBinding().readRequest(request, message);
        assertEquals("a", message.getHeader(GTaskBinding.GTASK_QUEUE_NAME));
        assertEquals("b", message.getHeader(GTaskBinding.GTASK_TASK_NAME));
        assertEquals(1, message.getHeader(GTaskBinding.GTASK_RETRY_COUNT));
        assertFalse(message.getHeaders().containsKey(GTaskBinding.GAE_QUEUE_NAME));
        assertFalse(message.getHeaders().containsKey(GTaskBinding.GAE_TASK_NAME));
        assertFalse(message.getHeaders().containsKey(GTaskBinding.GAE_RETRY_COUNT));
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = method.invoke(httpBinding, args); // updates args
        if (method.getName().equals("readRequest") && (args.length == 2)) {
            HttpMessage message = (HttpMessage)args[1];
            // prepare exchange for further inbound binding operations
            message.getExchange().setIn(message);
            // delegate further binding operations to inbound binding
            inboundBinding.readRequest(endpoint, message.getExchange(), (S)args[0]);
        }
        return result;
    }
View Full Code Here

            // we have access to the HttpServletResponse here and we can grab it if we need it
            HttpServletResponse res = exchange.getIn().getBody(HttpServletResponse.class);
            assertNotNull(res);

            // and they should also be on HttpMessage
            HttpMessage msg = (HttpMessage) exchange.getIn();
            assertNotNull(msg.getRequest());
            assertNotNull(msg.getResponse());

            // and we can use servlet response to write to output stream also
            res.getOutputStream().print("Written by servlet response");

            // for unit testing
View Full Code Here

   
    @Test
    public void testReadRequest() {
        exchange.setFromEndpoint(endpoint);
        MockHttpServletRequest request = new MockHttpServletRequest();
        HttpMessage message = new HttpMessage(exchange, request, null);
        request.addHeader(GTaskBinding.GAE_QUEUE_NAME, "a");
        request.addHeader(GTaskBinding.GAE_TASK_NAME, "b");
        request.addHeader(GTaskBinding.GAE_RETRY_COUNT, "1");
        // test invocation of inbound binding via dynamic proxy
        endpoint.getBinding().readRequest(request, message);
        assertEquals("a", message.getHeader(GTaskBinding.GTASK_QUEUE_NAME));
        assertEquals("b", message.getHeader(GTaskBinding.GTASK_TASK_NAME));
        assertEquals(1, message.getHeader(GTaskBinding.GTASK_RETRY_COUNT));
        assertFalse(message.getHeaders().containsKey(GTaskBinding.GAE_QUEUE_NAME));
        assertFalse(message.getHeaders().containsKey(GTaskBinding.GAE_TASK_NAME));
        assertFalse(message.getHeaders().containsKey(GTaskBinding.GAE_RETRY_COUNT));
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.component.http.HttpMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.