Search in sources :

Example 11 with CxfEndpoint

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());
}
Also used : CamelContext(org.apache.camel.CamelContext) QName(javax.xml.namespace.QName) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) Test(org.junit.Test)

Example 12 with CxfEndpoint

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();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) HttpResponse(org.wildfly.camel.test.common.http.HttpRequest.HttpResponse) CxfComponent(org.apache.camel.component.cxf.CxfComponent) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 13 with CxfEndpoint

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;
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Interceptor(org.apache.cxf.interceptor.Interceptor) Arquillian(org.jboss.arquillian.junit.Arquillian) Message(org.apache.cxf.message.Message) RunWith(org.junit.runner.RunWith) CamelExecutionException(org.apache.camel.CamelExecutionException) HashMap(java.util.HashMap) Test(org.junit.Test) Endpoint(org.wildfly.camel.test.common.types.Endpoint) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) List(java.util.List) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) CamelAware(org.wildfly.extension.camel.CamelAware) RouteBuilder(org.apache.camel.builder.RouteBuilder) Deployment(org.jboss.arquillian.container.test.api.Deployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Map(java.util.Map) ProducerTemplate(org.apache.camel.ProducerTemplate) CxfComponent(org.apache.camel.component.cxf.CxfComponent) Assert(org.junit.Assert) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Message(org.apache.cxf.message.Message) RouteBuilder(org.apache.camel.builder.RouteBuilder) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelExecutionException(org.apache.camel.CamelExecutionException) CxfComponent(org.apache.camel.component.cxf.CxfComponent) Interceptor(org.apache.cxf.interceptor.Interceptor) JAASLoginInterceptor(org.apache.cxf.interceptor.security.JAASLoginInterceptor)

Example 14 with CxfEndpoint

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();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Message(org.apache.cxf.message.Message) RouteBuilder(org.apache.camel.builder.RouteBuilder) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) URL(java.net.URL) Endpoint(org.wildfly.camel.test.common.types.Endpoint) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) CxfComponent(org.apache.camel.component.cxf.CxfComponent) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) Test(org.junit.Test)

Example 15 with CxfEndpoint

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);
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) RouteBuilder(org.apache.camel.builder.RouteBuilder) Greeter(org.apache.hello_world_soap_http.Greeter) CxfComponent(org.apache.camel.component.cxf.CxfComponent) CxfEndpoint(org.apache.camel.component.cxf.CxfEndpoint) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Aggregations

CxfEndpoint (org.apache.camel.component.cxf.CxfEndpoint)32 Test (org.junit.Test)30 CamelContext (org.apache.camel.CamelContext)10 QName (javax.xml.namespace.QName)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 CxfComponent (org.apache.camel.component.cxf.CxfComponent)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4 Endpoint (org.wildfly.camel.test.common.types.Endpoint)3 Exchange (org.apache.camel.Exchange)2 Processor (org.apache.camel.Processor)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 CxfProducer (org.apache.camel.component.cxf.CxfProducer)2 SoapBindingConfiguration (org.apache.cxf.binding.soap.SoapBindingConfiguration)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2 Message (org.apache.cxf.message.Message)2 URL (java.net.URL)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1