Examples of HttpOperationFailedException


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

        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

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

        port = AvailablePortFinder.getNextAvailable(8000);
       
        // if its a 404 then regard it as handled
        onException(HttpOperationFailedException.class).onWhen(new Predicate() {
            public boolean matches(Exchange exchange) {
                HttpOperationFailedException e = exchange.getException(HttpOperationFailedException.class);
                return e != null && e.getStatusCode() == 404;
            }
        }).handled(true).to("mock:404").transform(constant(noAccess));

        from("activemq:queue:data")
            // must setup policy to indicate transacted route
View Full Code Here

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

    public void configure() throws Exception {
        // if its a 404 then regard it as handled
        onException(HttpOperationFailedException.class).onWhen(new Predicate() {
            public boolean matches(Exchange exchange) {
                HttpOperationFailedException e = exchange.getException(HttpOperationFailedException.class);
                return e != null && e.getStatusCode() == 404;
            }
        }).handled(true).to("mock:404").transform(constant(noAccess));

        from("activemq:queue:data")
            // must setup policy to indicate transacted route
View Full Code Here

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

        errorHandler(transactionErrorHandler(required));

        // if its a 404 then regard it as handled
        onException(HttpOperationFailedException.class).onWhen(new Predicate() {
            public boolean matches(Exchange exchange) {
                HttpOperationFailedException e = exchange.getException(HttpOperationFailedException.class);
                return e != null && e.getStatusCode() == 404;
            }
        }).handled(true).to("mock:404").transform(constant(noAccess));

        from("activemq:queue:data")
            // must setup policy to indicate transacted route
View Full Code Here

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

        // this one should fail
        try {
            template.requestBody(URL, "Tiger", String.class);
            Assert.fail("Should have thrown exception");
        } catch (Exception e) {
            HttpOperationFailedException hofe = (HttpOperationFailedException) e.getCause();
            Assert.assertEquals(503, hofe.getStatusCode());
        }

        // but the 2 first should still return valid replies
        Assert.assertEquals("Bye World", reply1.get(10, TimeUnit.SECONDS));
        Assert.assertEquals("Bye Camel", reply2.get(10, TimeUnit.SECONDS));
View Full Code Here

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

    @Test
    public void test404() throws Exception {
        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

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

    public void testHttpOperationsFailedExceptionUri() throws Exception {
        try {
            template.requestBodyAndHeader("http://localhost:9080/foo?bar=123", null, "foo", 123);
            fail("Should have thrown an exception");
        } catch (RuntimeCamelException e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(500, cause.getStatusCode());
            assertEquals("http://localhost:9080/foo?bar=123", cause.getUri());
        }
    }
View Full Code Here

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

    public void testResponseBodyWhenError() throws Exception {
        try {
            template.requestBody("http://localhost:9080/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

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

                        .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

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

        }
    }

    protected HttpOperationFailedException populateHttpOperationFailedException(Exchange exchange, JettyContentExchange httpExchange,
                                                                                int responseCode) throws IOException {
        HttpOperationFailedException exception;
        String uri = httpExchange.getUrl();
        Map<String, String> headers = httpExchange.getHeaders();
        String body = extractResponseBody(exchange, httpExchange);

        if (responseCode >= 300 && responseCode < 400) {
            String locationHeader = httpExchange.getResponseFields().getStringField("location");
            if (locationHeader != null) {
                exception = new HttpOperationFailedException(uri, responseCode, null, locationHeader, headers, body);
            } else {
                // no redirect location
                exception = new HttpOperationFailedException(uri, responseCode, null, null, headers, body);
            }
        } else {
            // internal server error (error code 500)
            exception = new HttpOperationFailedException(uri, responseCode, null, null, headers, body);
        }

        return exception;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.