Search in sources :

Example 1 with CxfComponent

use of org.apache.camel.component.cxf.CxfComponent 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)

Example 2 with CxfComponent

use of org.apache.camel.component.cxf.CxfComponent in project camel by apache.

the class CxfComponentAutoConfiguration method configureCxfComponent.

@Lazy
@Bean(name = "cxf-component")
@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);
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        Class<?> paramClass = value.getClass();
        if (paramClass.getName().endsWith("NestedConfiguration")) {
            Class nestedClass = null;
            try {
                nestedClass = (Class) paramClass.getDeclaredField("CAMEL_NESTED_CLASS").get(null);
                HashMap<String, Object> nestedParameters = new HashMap<>();
                IntrospectionSupport.getProperties(value, nestedParameters, null, false);
                Object nestedProperty = nestedClass.newInstance();
                IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), nestedProperty, nestedParameters);
                entry.setValue(nestedProperty);
            } catch (NoSuchFieldException e) {
            }
        }
    }
    IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), component, parameters);
    return component;
}
Also used : HashMap(java.util.HashMap) CxfComponent(org.apache.camel.component.cxf.CxfComponent) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) HashMap(java.util.HashMap) Map(java.util.Map) Lazy(org.springframework.context.annotation.Lazy) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnClass(org.springframework.boot.autoconfigure.condition.ConditionalOnClass) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

CxfComponent (org.apache.camel.component.cxf.CxfComponent)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CamelContext (org.apache.camel.CamelContext)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 CxfEndpoint (org.apache.camel.component.cxf.CxfEndpoint)1 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 Greeter (org.apache.hello_world_soap_http.Greeter)1 ConditionalOnBean (org.springframework.boot.autoconfigure.condition.ConditionalOnBean)1 ConditionalOnClass (org.springframework.boot.autoconfigure.condition.ConditionalOnClass)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1 Lazy (org.springframework.context.annotation.Lazy)1