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();
}
}
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);
}
}
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());
}
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);
}
}
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();
}
}
Aggregations