Search in sources :

Example 1 with JettyHttpComponent

use of org.apache.camel.component.jetty.JettyHttpComponent in project camel by apache.

the class AhcProduceJavaBodyTest method testNotAllowed.

@Test
public void testNotAllowed() throws Exception {
    JettyHttpComponent jetty = context.getComponent("jetty", JettyHttpComponent.class);
    jetty.setAllowJavaSerializedObject(false);
    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();
    MyCoolBean cool = new MyCoolBean(123, "Camel");
    try {
        template.requestBodyAndHeader(getAhcEndpointUri(), cool, Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class);
        fail("Should fail");
    } catch (Exception e) {
        assertTrue(e.getCause().getMessage().startsWith("Content-type application/x-java-serialized-object is not allowed"));
    }
}
Also used : Exchange(org.apache.camel.Exchange) JettyHttpComponent(org.apache.camel.component.jetty.JettyHttpComponent) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) AhcComponent(org.apache.camel.component.ahc.AhcComponent) BaseAhcTest(org.apache.camel.component.ahc.BaseAhcTest) Test(org.junit.Test)

Example 2 with JettyHttpComponent

use of org.apache.camel.component.jetty.JettyHttpComponent in project camel by apache.

the class JettyHttpsProducerSslContextInUriTest method createRouteBuilder.

@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {

        public void configure() throws URISyntaxException {
            JettyHttpComponent componentJetty = (JettyHttpComponent) context.getComponent("jetty");
            componentJetty.setSslPassword(pwd);
            componentJetty.setSslKeyPassword(pwd);
            URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
            componentJetty.setKeystore(keyStoreUrl.toURI().getPath());
            from("jetty:https://localhost:" + port1 + "/test?sslContextParametersRef=sslContextParameters").to("mock:a");
            Processor proc = new Processor() {

                public void process(Exchange exchange) throws Exception {
                    exchange.getOut().setBody("<b>Hello World</b>");
                }
            };
            from("jetty:https://localhost:" + port1 + "/hello?sslContextParametersRef=sslContextParameters").process(proc);
            from("jetty:https://localhost:" + port2 + "/test?sslContextParametersRef=sslContextParameters").to("mock:b");
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) JettyHttpComponent(org.apache.camel.component.jetty.JettyHttpComponent) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) URL(java.net.URL)

Aggregations

Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 JettyHttpComponent (org.apache.camel.component.jetty.JettyHttpComponent)2 URL (java.net.URL)1 AhcComponent (org.apache.camel.component.ahc.AhcComponent)1 BaseAhcTest (org.apache.camel.component.ahc.BaseAhcTest)1 Test (org.junit.Test)1