Search in sources :

Example 6 with AhcComponent

use of org.apache.camel.component.ahc.AhcComponent in project camel by apache.

the class AhcProduceJavaBodyTest method testHttpSendJavaBodyAndReceiveString.

@Test
public void testHttpSendJavaBodyAndReceiveString() 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());
                    // 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(getAhcEndpointUri(), cool, Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, String.class);
    assertEquals("OK", reply);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpCommonComponent(org.apache.camel.http.common.HttpCommonComponent) AhcComponent(org.apache.camel.component.ahc.AhcComponent) BaseAhcTest(org.apache.camel.component.ahc.BaseAhcTest) Test(org.junit.Test)

Aggregations

AhcComponent (org.apache.camel.component.ahc.AhcComponent)6 Exchange (org.apache.camel.Exchange)5 Processor (org.apache.camel.Processor)5 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 BaseAhcTest (org.apache.camel.component.ahc.BaseAhcTest)5 Test (org.junit.Test)5 HttpCommonComponent (org.apache.camel.http.common.HttpCommonComponent)4 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JettyHttpComponent (org.apache.camel.component.jetty.JettyHttpComponent)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1