@Named("cxfProducerEndpoint") @Produces public CxfEndpoint createCxfProducerEndpoint() { CxfComponent cxfProducerComponent = new CxfComponent(this.camelContext); CxfEndpoint cxfProducerEndpoint = new CxfEndpoint(CXF_PRODUCER_ENDPOINT_ADDRESS, cxfProducerComponent); cxfProducerEndpoint.setBeanId("cxfProducerEndpoint"); cxfProducerEndpoint.setServiceClass(org.wildfly.camel.examples.cxf.jaxws.GreetingService.class); SSLContextParameters producerSslContextParameters = this.createProducerSSLContextParameters(); cxfProducerEndpoint.setSslContextParameters(producerSslContextParameters); // Not for use in production HostnameVerifier hostnameVerifier = new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }; cxfProducerEndpoint.setHostnameVerifier(hostnameVerifier); return cxfProducerEndpoint; }
@Named("cxfConsumerEndpoint") @Produces public CxfEndpoint createCxfConsumerEndpoint() { CxfComponent cxfConsumerComponent = new CxfComponent(this.camelContext); CxfEndpoint cxfConsumerEndpoint = new CxfEndpoint(CXF_CONSUMER_ENDPOINT_ADDRESS, cxfConsumerComponent); cxfConsumerEndpoint.setBeanId("cxfConsumerEndpoint"); cxfConsumerEndpoint.setServiceClass(org.wildfly.camel.examples.cxf.jaxws.GreetingService.class); SSLContextParameters consumerSslContextParameters = this.createConsumerSSLContextParameters(); cxfConsumerEndpoint.setSslContextParameters(consumerSslContextParameters); List<Interceptor<? extends Message>> inInterceptors = cxfConsumerEndpoint.getInInterceptors(); // Authentication JAASLoginInterceptor jaasLoginInterceptor = new JAASLoginInterceptor(); jaasLoginInterceptor.setContextName(WILDFLY_SECURITY_DOMAIN_NAME); jaasLoginInterceptor.setAllowAnonymous(false); List<CallbackHandlerProvider> chp = Arrays.asList(new JBossCallbackHandlerTlsCert()); jaasLoginInterceptor.setCallbackHandlerProviders(chp); inInterceptors.add(jaasLoginInterceptor); // Authorization SimpleAuthorizingInterceptor authorizingInterceptor = new SimpleAuthorizingInterceptor(); authorizingInterceptor.setAllowAnonymousUsers(false); Map<String, String> rolesMap = new HashMap<>(1); rolesMap.put("greet", "testRole"); authorizingInterceptor.setMethodRolesMap(rolesMap); inInterceptors.add(authorizingInterceptor); return cxfConsumerEndpoint; }
@Named("cxfConsumer") @Produces public CxfEndpoint createCxfConsumer() { CxfComponent cxfComponent = new CxfComponent(this.context); CxfEndpoint cxfFromEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting-cdi-xml", cxfComponent); cxfFromEndpoint.setServiceClass(GreetingService.class); return cxfFromEndpoint; }
@Named("cxfProducer") @Produces public CxfEndpoint createCxfProducer() { CxfComponent cxfComponent = new CxfComponent(this.context); CxfEndpoint cxfToEndpoint = new CxfEndpoint("http://localhost:8080/webservices/greeting-cdi-xml", cxfComponent); cxfToEndpoint.setServiceClass(GreetingService.class); return cxfToEndpoint; }
@Override public void configure() throws Exception { // Set system properties for use with Camel property placeholders for running the example tests. System.setProperty("routerPort", String.valueOf(AvailablePortFinder.getNextAvailable())); System.setProperty("servicePort", String.valueOf(AvailablePortFinder.getNextAvailable())); 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); }
@Bean @ConditionalOnClass(CamelContext.class) @ConditionalOnMissingBean(CxfComponent.class) public CxfComponent configureCxfComponent(CamelContext camelContext, CxfComponentConfiguration configuration) throws Exception { CxfComponent component = new CxfComponent(); component.setCamelContext(camelContext); Map<String, Object> parameters = new HashMap<>(); IntrospectionSupport.getProperties(configuration, parameters, null, false); IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters); return component; }
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; }
@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(); } }
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); } }
protected CxfEndpoint createEndpoint(String uri) throws Exception { CamelContext context = getCamelContext(); return (CxfEndpoint)new CxfComponent(context).createEndpoint(uri); }
@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(); } }
private CxfEndpoint createCxfEndpoint(String endpointUrl, CxfComponent component) throws Exception { CxfEndpoint cxfEndpoint = new CxfEndpoint(endpointUrl, component); cxfEndpoint.setServiceClass(Endpoint.class.getName()); return cxfEndpoint; }