use of org.apache.camel.component.http.HttpComponent in project camel by apache.
the class HttpJavaBodyTest method testHttpSendJavaBodyAndReceiveString.
@Test
public void testHttpSendJavaBodyAndReceiveString() 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());
// we send back plain test
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain");
exchange.getOut().setBody("OK");
}
});
}
});
context.start();
MyCoolBean cool = new MyCoolBean(123, "Camel");
String reply = template.requestBodyAndHeader("http://localhost:{{port}}/myapp/myservice", cool, Exchange.CONTENT_TYPE, HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, String.class);
assertEquals("OK", reply);
}
use of org.apache.camel.component.http.HttpComponent in project camel by apache.
the class HttpBasicAuthComponentConfiguredTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
HttpConfiguration config = new HttpConfiguration();
config.setAuthMethod("Basic");
config.setAuthUsername("donald");
config.setAuthPassword("duck");
HttpComponent http = context.getComponent("http", HttpComponent.class);
http.setHttpConfiguration(config);
from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler").process(new Processor() {
public void process(Exchange exchange) throws Exception {
HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class);
assertNotNull(req);
Principal user = req.getUserPrincipal();
assertNotNull(user);
assertEquals("donald", user.getName());
}
}).transform(constant("Bye World"));
from("jetty://http://localhost:{{port}}/anotherTest?handlers=myAuthHandler").transform(constant("See you later"));
}
};
}
Aggregations