use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class HttpThrowExceptionOnFailureTest method httpGetWhichReturnsHttp501ShouldThrowAnException.
@Test
public void httpGetWhichReturnsHttp501ShouldThrowAnException() throws Exception {
Exchange reply = template.request("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/XXX?throwExceptionOnFailure=true", new Processor() {
public void process(Exchange exchange) throws Exception {
}
});
Exception e = reply.getException();
assertNotNull("Should have thrown an exception", e);
HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e);
assertEquals(501, cause.getStatusCode());
}
use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class HttpRedirectTest method httpRedirect.
@Test
public void httpRedirect() throws Exception {
String uri = "http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/test?httpClient.redirectsEnabled=false&httpClient.socketTimeout=60000&httpClient.connectTimeout=60000" + "&httpClient.staleConnectionCheckEnabled=false";
Exchange out = template.request(uri, new Processor() {
public void process(Exchange exchange) throws Exception {
// no data
}
});
assertNotNull(out);
HttpOperationFailedException cause = out.getException(HttpOperationFailedException.class);
assertNotNull(cause);
assertEquals(HttpStatus.SC_MOVED_PERMANENTLY, cause.getStatusCode());
assertEquals("http4://" + localServer.getInetAddress().getHostName() + ":" + localServer.getLocalPort() + "/someplaceelse", cause.getRedirectLocation());
}
use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class HttpRedirectTest method testHttpRedirectFromCamelRoute.
@Test
public void testHttpRedirectFromCamelRoute() throws Exception {
MockEndpoint errorEndpoint = context.getEndpoint("mock:error", MockEndpoint.class);
errorEndpoint.expectedMessageCount(1);
MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedMessageCount(0);
try {
template.requestBody("direct:start", "Hello World", String.class);
fail("Should have thrown an exception");
} catch (RuntimeCamelException e) {
HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
assertEquals(302, cause.getStatusCode());
}
errorEndpoint.assertIsSatisfied();
resultEndpoint.assertIsSatisfied();
}
use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class HttpReturnFaultTest method testHttpFault.
@Test
public void testHttpFault() throws Exception {
Exchange exchange = template.request("http://localhost:{{port}}/test", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
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());
}
use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class JettyAsyncDefaultContinuationTimeoutTest method testJettyAsyncTimeout.
@Test
public void testJettyAsyncTimeout() throws Exception {
getMockEndpoint("mock:result").expectedBodiesReceived("Bye World");
StopWatch watch = new StopWatch();
try {
template.requestBody("http://localhost:{{port}}/myservice", null, String.class);
fail("Should have thrown an exception");
} 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(504, cause.getStatusCode());
// should be approx 30-34 sec.
assertTrue("Timeout should occur faster than " + taken, taken < 34000);
}
assertMockEndpointsSatisfied(2, TimeUnit.MINUTES);
}
Aggregations