Package org.apache.camel.component.http

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


    public void testHttpClientNoProxyException() throws Exception {
        try {
            template.requestBody("direct:cool", "Kaboom", String.class);
            fail("Should have thrown exception");
        } catch (CamelExecutionException e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(500, cause.getStatusCode());
            assertNotNull(cause.getResponseBody());
            assertTrue(cause.getResponseBody().contains("MyAppException"));
        }
    }
View Full Code Here


        MyCoolService proxy = new ProxyBuilder(context).endpoint("direct:cool").build(MyCoolService.class);
        try {
            proxy.hello("Kaboom");
            fail("Should have thrown exception");
        } catch (UndeclaredThrowableException e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(500, cause.getStatusCode());
            assertNotNull(cause.getResponseBody());
            assertTrue(cause.getResponseBody().contains("MyAppException"));
        }
    }
View Full Code Here

    public void testHttpRedirect() 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(301, cause.getStatusCode());
            assertEquals(true, cause.isRedirectError());
            assertEquals(true, cause.hasRedirectLocation());
            assertEquals("http://localhost:" + getPort() + "/newtest", cause.getRedirectLocation());
        }
    }
View Full Code Here

        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

    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

    public void testHttpJmsAsync() throws Exception {
        try {
            template.requestBody("http://0.0.0.0:9080/myservice", "Hello World", String.class);
            fail("Should have thrown exception");
        } catch (CamelExecutionException e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(503, cause.getStatusCode());
        }
    }
View Full Code Here

        // this one should fail
        try {
            template.requestBody("http://localhost:9002/test", "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

        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

    public void testHttpJmsAsync() throws Exception {
        try {
            template.requestBody("http://0.0.0.0:"  + getPort() + "/myservice", "Hello World", String.class);
            fail("Should have thrown exception");
        } catch (CamelExecutionException e) {
            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(503, cause.getStatusCode());
        }
    }
View Full Code Here

        } catch (CamelExecutionException e) {
            log.info("Timeout hit and client got reply with failure status code");

            long taken = watch.stop();

            HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
            assertEquals(503, cause.getStatusCode());

            // should be approx 30-34 sec.
            assertTrue("Timeout should occur faster than " + taken, taken < 34000);
        }
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.