use of org.apache.camel.component.cxf.CxfEndpoint in project camel by apache.
the class CxfEndpointBeansRouterTest method testCxfBeanWithCamelPropertiesHolder.
@Test
public void testCxfBeanWithCamelPropertiesHolder() throws Exception {
// get the camelContext from application context
CamelContext camelContext = ctx.getBean("camel", CamelContext.class);
CxfEndpoint testEndpoint = camelContext.getEndpoint("cxf:bean:testEndpoint", CxfEndpoint.class);
QName endpointName = QName.valueOf("{http://org.apache.camel.component.cxf}myEndpoint");
QName serviceName = QName.valueOf("{http://org.apache.camel.component.cxf}myService");
assertEquals("Got a wrong address", "http://localhost:9000/testEndpoint", testEndpoint.getAddress());
assertEquals("Got a wrong bindingId", "http://schemas.xmlsoap.org/wsdl/soap12/", testEndpoint.getBindingId());
assertEquals("Got a wrong transportId", "http://cxf.apache.org/transports/http", testEndpoint.getTransportId());
assertEquals("Got a wrong endpointName", endpointName, testEndpoint.getPortName());
assertEquals("Got a wrong WsdlURL", "wsdl/test.wsdl", testEndpoint.getWsdlURL());
assertEquals("Got a wrong serviceName", serviceName, testEndpoint.getServiceName());
}
use of org.apache.camel.component.cxf.CxfEndpoint in project wildfly-camel by wildfly-extras.
the class CXFWSSecureConsumerIntegrationTest method testCXFSecureConsumer.
@Test
public void testCXFSecureConsumer() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
CxfComponent cxfComponent = camelContext.getComponent("cxf", CxfComponent.class);
CxfEndpoint cxfProducer = createCxfEndpoint(SECURE_WS_ENDPOINT_URL, cxfComponent);
cxfProducer.setSslContextParameters(createSSLContextParameters());
CxfEndpoint cxfConsumer = createCxfEndpoint(SECURE_WS_ENDPOINT_URL, cxfComponent);
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to(cxfProducer);
from(cxfConsumer).transform(simple("Hello ${body}"));
}
});
try {
// Force WildFly to generate a self-signed SSL cert & keystore
HttpRequest.get("https://localhost:8443").throwExceptionOnFailure(false).getResponse();
camelContext.start();
ProducerTemplate template = camelContext.createProducerTemplate();
String result = template.requestBody("direct:start", "Kermit", 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_WS_ENDPOINT_URL + "?wsdl").throwExceptionOnFailure(false).getResponse();
Assert.assertEquals(302, response.getStatusCode());
Assert.assertEquals(response.getHeader("Location"), SECURE_WS_ENDPOINT_URL + "?wsdl");
} finally {
camelContext.stop();
}
}
use of org.apache.camel.component.cxf.CxfEndpoint in project wildfly-camel by wildfly-extras.
the class CXFWSJAASAuthenticationIntegrationTest method configureCamelContext.
private CamelContext configureCamelContext(String password) throws Exception {
CamelContext camelctx = new DefaultCamelContext();
CxfComponent component = new CxfComponent(camelctx);
CxfEndpoint consumerEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting", component);
consumerEndpoint.setServiceClass(Endpoint.class);
List<Interceptor<? extends Message>> inInterceptors = consumerEndpoint.getInInterceptors();
JAASLoginInterceptor interceptor = new JAASLoginInterceptor();
interceptor.setContextName("other");
inInterceptors.add(interceptor);
CxfEndpoint producerEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting", component);
producerEndpoint.setServiceClass(Endpoint.class);
producerEndpoint.setUsername("user1");
producerEndpoint.setPassword(password);
Map<String, Object> properties = producerEndpoint.getProperties();
if (properties == null) {
producerEndpoint.setProperties(new HashMap<>());
}
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to(producerEndpoint);
from(consumerEndpoint).process(exchange -> {
Object[] args = exchange.getIn().getBody(Object[].class);
exchange.getOut().setBody("Hello " + args[0]);
});
}
});
return camelctx;
}
use of org.apache.camel.component.cxf.CxfEndpoint in project wildfly-camel by wildfly-extras.
the class CXFWSInterceptorTest method testCXFInterceptor.
@Test
public void testCXFInterceptor() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
CamelContext camelctx = new DefaultCamelContext();
CxfComponent component = new CxfComponent(camelctx);
CxfEndpoint cxfEndpoint = new CxfEndpoint("http://localhost:8080/EndpointService/EndpointPort", component);
cxfEndpoint.setServiceClass(Endpoint.class);
List<Interceptor<? extends Message>> inInterceptors = cxfEndpoint.getInInterceptors();
inInterceptors.add(new CountDownInterceptor(latch));
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(cxfEndpoint).setBody(constant("Hello ${body}"));
}
});
camelctx.start();
try {
QName qname = new QName("http://wildfly.camel.test.cxf", "EndpointService");
Service service = Service.create(new URL("http://localhost:8080/EndpointService/EndpointPort?wsdl"), qname);
Endpoint endpoint = service.getPort(Endpoint.class);
endpoint.echo("Kermit");
Assert.assertTrue("Gave up waiting for CXF interceptor handleMessage", latch.await(5, TimeUnit.SECONDS));
} finally {
camelctx.stop();
}
}
use of org.apache.camel.component.cxf.CxfEndpoint in project camel by apache.
the class CamelCxfExample method main.
public static void main(String[] args) throws Exception {
// Set system properties for use with Camel property placeholders for running the examples.
System.setProperty("routerPort", "9001");
System.setProperty("servicePort", "9003");
// START SNIPPET: e1
CamelContext context = new DefaultCamelContext();
// END SNIPPET: e1
PropertiesComponent pc = new PropertiesComponent();
context.addComponent("properties", pc);
// Set up the JMS broker and the CXF SOAP over JMS server
// START SNIPPET: e2
JmsBroker broker = new JmsBroker();
Server server = new Server();
try {
broker.start();
server.start();
// END SNIPPET: e2
// Add some configuration by hand ...
// START SNIPPET: e3
context.addRoutes(new RouteBuilder() {
public void configure() {
CxfComponent cxfComponent = new CxfComponent(getContext());
CxfEndpoint serviceEndpoint = new CxfEndpoint(SERVICE_ADDRESS, cxfComponent);
serviceEndpoint.setServiceClass(Greeter.class);
// Here we just pass the exception back, don't need to use errorHandler
errorHandler(noErrorHandler());
from(ROUTER_ENDPOINT_URI).to(serviceEndpoint);
}
});
// END SNIPPET: e3
String address = ROUTER_ADDRESS.replace("{{routerPort}}", System.getProperty("routerPort"));
// Starting the routing context
// Using the CXF Client to kick off the invocations
// START SNIPPET: e4
context.start();
Client client = new Client(address + "?wsdl");
// END SNIPPET: e4
// Now everything is set up - let's start the context
client.invoke();
Thread.sleep(1000);
context.stop();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
server.stop();
broker.stop();
System.exit(0);
}
}
Aggregations