use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class JettyHttpProderReturnFaultTest method testHttpFault.
@Test
public void testHttpFault() throws Exception {
// these tests does not run well on Windows
if (isPlatform("windows")) {
return;
}
// give Jetty time to startup properly
Thread.sleep(1000);
Exchange exchange = template.request("jetty://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 JettyAsyncContinuationTimeoutTest 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 3-4 sec.
assertTrue("Timeout should occur faster than " + taken, taken < 4500);
}
assertMockEndpointsSatisfied();
}
use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class JettyHttpProducerSuspendResumeTest method testJettySuspendResume.
@Test
public void testJettySuspendResume() throws Exception {
// these tests does not run well on Windows
if (isPlatform("windows")) {
return;
}
context.getShutdownStrategy().setTimeout(50);
String reply = template.requestBody(serverUri, "World", String.class);
assertEquals("Bye World", reply);
// now suspend jetty
HttpConsumer consumer = (HttpConsumer) context.getRoute("route1").getConsumer();
assertNotNull(consumer);
// suspend
consumer.suspend();
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();
// and send request which should be processed
reply = template.requestBody(serverUri, "Moon", String.class);
assertEquals("Bye Moon", reply);
}
use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class JettyHttpProducerSuspendTest method testJettySuspend.
@Test
public void testJettySuspend() throws Exception {
// these tests does not run well on Windows
if (isPlatform("windows")) {
return;
}
context.getShutdownStrategy().setTimeout(50);
String reply = template.requestBody(serverUri, "World", String.class);
assertEquals("Bye World", reply);
// now suspend jetty
HttpConsumer consumer = (HttpConsumer) context.getRoute("route1").getConsumer();
assertNotNull(consumer);
// suspend
consumer.suspend();
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());
}
}
use of org.apache.camel.http.common.HttpOperationFailedException in project camel by apache.
the class HttpJavaBodyTest method testNotAllowed.
@Test
public void testNotAllowed() throws Exception {
HttpCommonComponent jetty = context.getComponent("jetty", HttpCommonComponent.class);
jetty.setAllowJavaSerializedObject(false);
HttpComponent http = context.getComponent("http", HttpComponent.class);
http.setAllowJavaSerializedObject(true);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jetty:http://localhost:{{port}}/myapp/myservice").process(new Processor() {
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
assertNotNull(body);
assertEquals("Hello World", body);
MyCoolBean reply = new MyCoolBean(456, "Camel rocks");
exchange.getOut().setBody(reply);
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
}
});
}
});
context.start();
MyCoolBean cool = new MyCoolBean(123, "Camel");
try {
template.requestBodyAndHeader("http://localhost:{{port}}/myapp/myservice", cool, Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class);
fail("Should fail");
} catch (CamelExecutionException e) {
HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
assertEquals(415, cause.getStatusCode());
}
}
Aggregations