Search in sources :

Example 6 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class UndertowIntegrationTest method testUndertowConsumer.

@Test
public void testUndertowConsumer() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("undertow:http://localhost/myapp").setBody(simple("Hello ${header.name} from /"));
            from("undertow:http://localhost/myapp/a").setBody(simple("Hello ${header.name} from /a"));
            from("undertow:http://localhost/myapp/a/b").setBody(simple("Hello ${header.name} from /a/b"));
            from("undertow:http://localhost/myapp/a/b/c").setBody(simple("Hello ${header.name} from /a/b/c"));
            from("undertow:http://localhost/myapp/b").setBody(simple("Hello ${header.name} from /b"));
            from("undertow:http://localhost/myapp/c").setBody(simple("Hello ${header.name} from /c"));
        }
    });
    camelctx.start();
    try {
        HttpResponse response = HttpRequest.get("http://localhost:8080/myapp?name=Kermit").getResponse();
        Assert.assertEquals(HTTP_OK, response.getStatusCode());
        Assert.assertEquals("Hello Kermit from /", response.getBody());
        response = HttpRequest.get("http://localhost:8080/myapp/a?name=Kermit").getResponse();
        Assert.assertEquals(HTTP_OK, response.getStatusCode());
        Assert.assertEquals("Hello Kermit from /a", response.getBody());
        response = HttpRequest.get("http://localhost:8080/myapp/a/b?name=Kermit").getResponse();
        Assert.assertEquals(HTTP_OK, response.getStatusCode());
        Assert.assertEquals("Hello Kermit from /a/b", response.getBody());
        response = HttpRequest.get("http://localhost:8080/myapp/a/b/c?name=Kermit").getResponse();
        Assert.assertEquals(HTTP_OK, response.getStatusCode());
        Assert.assertEquals("Hello Kermit from /a/b/c", response.getBody());
        response = HttpRequest.get("http://localhost:8080/myapp/b?name=Kermit").getResponse();
        Assert.assertEquals(HTTP_OK, response.getStatusCode());
        Assert.assertEquals("Hello Kermit from /b", response.getBody());
        response = HttpRequest.get("http://localhost:8080/myapp/c?name=Kermit").getResponse();
        Assert.assertEquals(HTTP_OK, response.getStatusCode());
        Assert.assertEquals("Hello Kermit from /c", response.getBody());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ExpectedException(org.junit.rules.ExpectedException) Test(org.junit.Test)

Example 7 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class CXFRSSecureConsumerIntegrationTest method testCXFSecureConsumer.

@Test
public void testCXFSecureConsumer() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("cxfrs-secure-undertow");
    Assert.assertNotNull("Expected cxfrs-secure-undertow to not be null", camelctx);
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        // The JAXRS Client API needs to see resteasy
        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
        // Force WildFly to generate a self-signed SSL cert & keystore
        HttpRequest.get("https://localhost:8443").throwExceptionOnFailure(false).getResponse();
        // Use the generated keystore
        String keystorePath = System.getProperty("jboss.server.config.dir") + "/application.keystore";
        System.setProperty("javax.net.ssl.trustStorePassword", "password");
        System.setProperty("javax.net.ssl.trustStore", keystorePath);
        Client client = ClientBuilder.newClient();
        Object result = client.target(SECURE_RS_ENDPOINT).request(MediaType.APPLICATION_JSON).get(String.class);
        Assert.assertEquals("Hello Kermit", result);
        // Verify that if we attempt to use HTTP, we get a 302 redirect to the HTTPS endpoint URL
        HttpResponse response = HttpRequest.get(INSECURE_RS_ENDPOINT).throwExceptionOnFailure(false).getResponse();
        Assert.assertEquals(302, response.getStatusCode());
        Assert.assertEquals(response.getHeader("Location"), SECURE_RS_ENDPOINT);
    } finally {
        System.clearProperty("javax.net.ssl.trustStorePassword");
        System.clearProperty("javax.net.ssl.trustStore");
        Thread.currentThread().setContextClassLoader(tccl);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) Client(javax.ws.rs.client.Client) Test(org.junit.Test)

Example 8 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class UndertowHandlerTest method testHttpEndpoint.

@Test
public void testHttpEndpoint() throws Exception {
    ServiceContainer container = ServiceLocator.getRequiredService(ServiceContainer.class);
    ServiceName hostServiceName = UndertowService.virtualHostName("default-server", "default-host");
    Host host = (Host) container.getRequiredService(hostServiceName).getValue();
    final StringBuilder result = new StringBuilder();
    host.registerHandler("/myapp/myservice", new HttpHandler() {

        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            String name = exchange.getQueryParameters().get("name").getFirst();
            result.append("Hello " + name);
        }
    });
    HttpResponse response = HttpRequest.get("http://localhost:8080/myapp/myservice?name=Kermit").getResponse();
    Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getStatusCode());
    Assert.assertEquals("Hello Kermit", result.toString());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) ServiceContainer(org.jboss.msc.service.ServiceContainer) ServiceName(org.jboss.msc.service.ServiceName) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) Host(org.wildfly.extension.undertow.Host) Test(org.junit.Test)

Example 9 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class SpringContextBindingJaxRsTest method testJaxRsServiceCamelJndiBindingsInjectable.

@Test
public void testJaxRsServiceCamelJndiBindingsInjectable() throws Exception {
    try {
        deployer.deploy(SIMPLE_WAR);
        CamelContext camelctx = contextRegistry.getCamelContext("jndi-delayed-binding-spring-context");
        Assert.assertNotNull("Expected jndi-delayed-binding-spring-context to not be null", camelctx);
        Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
        HttpResponse response = HttpRequest.get("http://localhost:8080/simple/rest/context").getResponse();
        Assert.assertEquals("camelctxA,camelctxB,camelctxC", response.getBody());
    } finally {
        deployer.undeploy(SIMPLE_WAR);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) Test(org.junit.Test)

Example 10 with HttpResponse

use of org.wildfly.camel.test.common.http.HttpRequest.HttpResponse in project wildfly-camel by wildfly-extras.

the class ServletIntegrationTest method testServletRoute.

@Test
public void testServletRoute() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("servlet://hello?servletName=CamelServletTest&matchOnUriPrefix=true").process(new Processor() {

                @Override
                public void process(Exchange exchange) throws Exception {
                    exchange.getOut().setBody("Hello Kermit");
                }
            });
        }
    });
    camelctx.start();
    try {
        HttpResponse result = HttpRequest.get("http://localhost:8080/camel/services/hello").getResponse();
        Assert.assertEquals("Hello Kermit", result.getBody());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

HttpResponse (org.wildfly.camel.test.common.http.HttpRequest.HttpResponse)10 CamelContext (org.apache.camel.CamelContext)8 Test (org.junit.Test)8 RouteBuilder (org.apache.camel.builder.RouteBuilder)5 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)5 HttpHandler (io.undertow.server.HttpHandler)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 Client (javax.ws.rs.client.Client)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 CxfComponent (org.apache.camel.component.cxf.CxfComponent)1 CxfEndpoint (org.apache.camel.component.cxf.CxfEndpoint)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 ServiceContainer (org.jboss.msc.service.ServiceContainer)1 ServiceName (org.jboss.msc.service.ServiceName)1 ExpectedException (org.junit.rules.ExpectedException)1 Host (org.wildfly.extension.undertow.Host)1