Pax-CDI, Camel and CXF...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pax-CDI, Camel and CXF...

Brad Johnson
There may not be a simple way to do this in a pure Java way with CDI and Camel Java DSL routes.  But I've been able to get my application running in the karaf 4.0.6 with just CDI with one exception.

Thanks in advance for any comments, questions or criticisms.

Brad

Here's a very simple blueprint example:

<cxf:cxfEndpoint id="myEndpoint" address="/myendpointaddress/" serviceClass="org.foo.ServiceAPI" />
<route id="cxf">
<!-- route starts from the cxf webservice in POJO mode -->
<from uri="cxf:bean:myEndpoint" />

<recipientList>
<simple>direct-vm:${header.operationName}</simple>
</recipientList>
</route>
</camelContext>


I'm going to lash up some tests for what I have below but the web services tests take a bit of time and I thought I'd just run it by folks to see if this looks at least plausible.

The first thing is an annotation for setting values on a CXFEndpoint. Then the producer and finally the route builder.

@Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface CXFEndpointConfig {
Class serviceClazz();
String address();
}

Then a producer that gets such an injectionpoint and looks for that config.

@Singleton
public class EndpointFactory {

@Produce
public CxfEndpoint getCxfEndpoint(InjectionPoint injectEndpoint) {

CXFEndpointConfig endpointConfig = injectEndpoint.getAnnotated().getAnnotation(CXFEndpointConfig.class);
CxfEndpoint endpoint = null;
if (endpointConfig != null) {
endpoint = new CxfEndpoint();
endpoint.setServiceClass(endpointConfig.serviceClazz());
endpoint.getInInterceptors().add(new LoggingInInterceptor());
endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
endpoint.setAddress(endpointConfig.address());
}
return endpoint;

}
}

//I'm not explicitly setting the service name in the endpoint though I could add another property on the annotation for that.  But the API service class has a WebService with name of "whiteVaultService" and the variable in the route builder also has that name.  I believe the latter is what the cxf:bean:xxxx is looking for in any case.

As I said I'll set this up and run some SOAP UI tests against it soon but wanted to make sure I wasn't being all wrong headed about this.

@Inject 
@CXFEndpointConfig(address = "/whitevault/", serviceClazz = org.enjekt.panda.commons.api.WhiteVaultAPI.class)
CxfEndpoint whiteVaultService;


@Override
    public void configure() {
        // you can configure the route rule with Java DSL here

        from("cxf:bean:whiteVaultService")
        .recipientList("direct-vm:${header.operationName}");
        

   
}
Reply | Threaded
Open this post in threaded view
|

Re: Pax-CDI, Camel and CXF...

Brad Johnson
Well once I realized that I had the Camel @Produce instead of @Produces I was over one hurdle.  I'm still not seeing my route start up nor my factory getting called so that's an issue.  But it doesn't crash and burn on start up anyway.  There is hope.

On Tue, Sep 13, 2016 at 4:27 PM, Brad Johnson <[hidden email]> wrote:
There may not be a simple way to do this in a pure Java way with CDI and Camel Java DSL routes.  But I've been able to get my application running in the karaf 4.0.6 with just CDI with one exception.

Thanks in advance for any comments, questions or criticisms.

Brad

Here's a very simple blueprint example:

<cxf:cxfEndpoint id="myEndpoint" address="/myendpointaddress/" serviceClass="org.foo.ServiceAPI" />
<route id="cxf">
<!-- route starts from the cxf webservice in POJO mode -->
<from uri="cxf:bean:myEndpoint" />

<recipientList>
<simple>direct-vm:${header.operationName}</simple>
</recipientList>
</route>
</camelContext>


I'm going to lash up some tests for what I have below but the web services tests take a bit of time and I thought I'd just run it by folks to see if this looks at least plausible.

The first thing is an annotation for setting values on a CXFEndpoint. Then the producer and finally the route builder.

@Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER})
public @interface CXFEndpointConfig {
Class serviceClazz();
String address();
}

Then a producer that gets such an injectionpoint and looks for that config.

@Singleton
public class EndpointFactory {

@Produce
public CxfEndpoint getCxfEndpoint(InjectionPoint injectEndpoint) {

CXFEndpointConfig endpointConfig = injectEndpoint.getAnnotated().getAnnotation(CXFEndpointConfig.class);
CxfEndpoint endpoint = null;
if (endpointConfig != null) {
endpoint = new CxfEndpoint();
endpoint.setServiceClass(endpointConfig.serviceClazz());
endpoint.getInInterceptors().add(new LoggingInInterceptor());
endpoint.getOutInterceptors().add(new LoggingOutInterceptor());
endpoint.setAddress(endpointConfig.address());
}
return endpoint;

}
}

//I'm not explicitly setting the service name in the endpoint though I could add another property on the annotation for that.  But the API service class has a WebService with name of "whiteVaultService" and the variable in the route builder also has that name.  I believe the latter is what the cxf:bean:xxxx is looking for in any case.

As I said I'll set this up and run some SOAP UI tests against it soon but wanted to make sure I wasn't being all wrong headed about this.

@Inject 
@CXFEndpointConfig(address = "/whitevault/", serviceClazz = org.enjekt.panda.commons.api.WhiteVaultAPI.class)
CxfEndpoint whiteVaultService;


@Override
    public void configure() {
        // you can configure the route rule with Java DSL here

        from("cxf:bean:whiteVaultService")
        .recipientList("direct-vm:${header.operationName}");
        

   
}