use of org.apache.camel.http.common.HttpCommonComponent in project camel by apache.
the class AhcProduceJavaBodyTest method testHttpSendStringAndReceiveJavaBody.
@Test
public void testHttpSendStringAndReceiveJavaBody() throws Exception {
HttpCommonComponent jetty = context.getComponent("jetty", HttpCommonComponent.class);
jetty.setAllowJavaSerializedObject(true);
AhcComponent ahc = context.getComponent("ahc", AhcComponent.class);
ahc.setAllowJavaSerializedObject(true);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(getTestServerEndpointUri()).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, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
}
});
}
});
context.start();
MyCoolBean reply = template.requestBody(getAhcEndpointUri(), "Hello World", MyCoolBean.class);
assertEquals(456, reply.getId());
assertEquals("Camel rocks", reply.getName());
}
use of org.apache.camel.http.common.HttpCommonComponent in project camel by apache.
the class AhcProduceJavaBodyTest method testNotAllowedReceive.
@Test
public void testNotAllowedReceive() throws Exception {
HttpCommonComponent jetty = context.getComponent("jetty", HttpCommonComponent.class);
jetty.setAllowJavaSerializedObject(true);
AhcComponent ahc = context.getComponent("ahc", AhcComponent.class);
ahc.setAllowJavaSerializedObject(false);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(getTestServerEndpointUri()).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, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
}
});
}
});
context.start();
Object reply = template.requestBody(getAhcEndpointUri(), "Hello World", Object.class);
MyCoolBean bean = context.getTypeConverter().convertTo(MyCoolBean.class, reply);
assertNull(bean);
}
use of org.apache.camel.http.common.HttpCommonComponent in project camel by apache.
the class AhcProduceJavaBodyTest method testHttpSendJavaBodyAndReceiveJavaBody.
@Test
public void testHttpSendJavaBodyAndReceiveJavaBody() throws Exception {
HttpCommonComponent jetty = context.getComponent("jetty", HttpCommonComponent.class);
jetty.setAllowJavaSerializedObject(true);
AhcComponent ahc = context.getComponent("ahc", AhcComponent.class);
ahc.setAllowJavaSerializedObject(true);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(getTestServerEndpointUri()).process(new Processor() {
public void process(Exchange exchange) throws Exception {
MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class);
assertNotNull(cool);
assertEquals(123, cool.getId());
assertEquals("Camel", cool.getName());
MyCoolBean reply = new MyCoolBean(456, "Camel rocks");
exchange.getOut().setBody(reply);
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
}
});
}
});
context.start();
MyCoolBean cool = new MyCoolBean(123, "Camel");
MyCoolBean reply = template.requestBodyAndHeader(getAhcEndpointUri(), cool, Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class);
assertEquals(456, reply.getId());
assertEquals("Camel rocks", reply.getName());
}
use of org.apache.camel.http.common.HttpCommonComponent in project camel by apache.
the class HttpJavaBodyTest method testNotAllowedReceive.
@Test
public void testNotAllowedReceive() 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 {
onException(Exception.class).to("mock:error");
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();
try {
template.requestBody("http://localhost:{{port}}/myapp/myservice", "Hello World", MyCoolBean.class);
fail("Should fail");
} catch (Exception e) {
// expected
}
}
use of org.apache.camel.http.common.HttpCommonComponent in project camel by apache.
the class HttpJavaBodyTest method testHttpSendJavaBodyAndReceiveJavaBody.
@Test
public void testHttpSendJavaBodyAndReceiveJavaBody() throws Exception {
HttpCommonComponent jetty = context.getComponent("jetty", HttpCommonComponent.class);
jetty.setAllowJavaSerializedObject(true);
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 {
MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class);
assertNotNull(cool);
assertEquals(123, cool.getId());
assertEquals("Camel", cool.getName());
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");
MyCoolBean reply = template.requestBodyAndHeader("http://localhost:{{port}}/myapp/myservice", cool, Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class);
assertEquals(456, reply.getId());
assertEquals("Camel rocks", reply.getName());
}
Aggregations