Package org.apache.camel.component.http

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


    public void testResponseBodyWhenError() throws Exception {
        try {
            template.requestBody("http://localhost:{{port}}/myapp/myservice", "bookid=123");
            fail("Should have thrown an exception");
        } catch (RuntimeCamelException e) {
            HttpOperationFailedException cause = (HttpOperationFailedException) e.getCause();
            assertEquals(500, cause.getStatusCode());
            String body = context.getTypeConverter().convertTo(String.class, cause.getResponseBody());
            assertTrue(body.indexOf("Damm") > -1);
            assertTrue(body.indexOf("IllegalArgumentException") > -1);
            assertNotNull(cause.getResponseHeaders());
            String type = cause.getResponseHeaders().get(Exchange.CONTENT_TYPE);
            assertTrue(type.startsWith("text/plain"));
        }
    }
View Full Code Here


                exchange.getIn().setBody("Hello World!");
            }
           
        });
        assertTrue(exchange.isFailed());
        HttpOperationFailedException exception = exchange.getException(HttpOperationFailedException.class);
        assertNotNull(exception);
        assertEquals("This is a fault", exception.getResponseBody());
        assertEquals(500, exception.getStatusCode());
    }
View Full Code Here

    public void testHttpRedirectNoLocation() throws Exception {
        try {
            template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class);
            fail("Should have thrown an exception");
        } catch (RuntimeCamelException e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(302, cause.getStatusCode());
            assertEquals(true, cause.isRedirectError());
            assertEquals(false, cause.hasRedirectLocation());
            assertEquals(null, cause.getRedirectLocation());
        }
    }
View Full Code Here

        try {
            template.requestBody(serverUri, "Moon", String.class);
            fail("Should throw exception");
        } catch (Exception e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(503, cause.getStatusCode());
        }

        // resume
        consumer.resume();
View Full Code Here

        try {
            reply2.get(20, TimeUnit.SECONDS);
            fail("Should throw exception");
        } catch (Exception e) {
            RuntimeCamelException rce = assertIsInstanceOf(RuntimeCamelException.class, e.getCause());
            HttpOperationFailedException hofe = assertIsInstanceOf(HttpOperationFailedException.class, rce.getCause());
            assertEquals(503, hofe.getStatusCode());
        }
    }
View Full Code Here

        try {
            template.sendBody(url, null);
            fail("Should have thrown exception");
        } catch (Exception e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(404, cause.getStatusCode());
            assertEquals("http//0.0.0.0:" + getPort() + "/bar", cause.getUri());
            assertEquals("Page not found", cause.getResponseBody());
            assertNotNull(cause.getResponseHeaders());
        }
    }
View Full Code Here

                exchange.getIn().setBody("Hello World!");
            }
           
        });
        assertTrue(exchange.isFailed());
        HttpOperationFailedException exception = exchange.getException(HttpOperationFailedException.class);
        assertNotNull(exception);
        assertEquals("This is a fault", exception.getResponseBody());
        assertEquals(500, exception.getStatusCode());
    }
View Full Code Here

        try {
            template.requestBody(serverUri, "Moon", String.class);
            fail("Should throw exception");
        } catch (Exception e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(503, cause.getStatusCode());
        }
    }
View Full Code Here

        Thread.sleep(1000);

        try {
            template.request(url, null);
        } catch (Exception e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(404, cause.getStatusCode());
            assertEquals("http//0.0.0.0:9123/bar", cause.getUri());
            assertEquals("Page not found", cause.getResponseBody());
            assertNotNull(cause.getResponseHeaders());
        }
    }
View Full Code Here

                        .doCatch(HttpOperationFailedException.class)
                            .process(new Processor() {
                                public void process(Exchange exchange) {
                                    // copy the caused exception values to the exchange as we want the response in the regular exchange
                                    // instead as an exception that will get thrown and thus the route breaks
                                    HttpOperationFailedException cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class);
                                    exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, cause.getStatusCode());
                                    exchange.getOut().setBody(cause.getResponseBody());
                                }
                            })
                        .end();

View Full Code Here

TOP

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

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.