TomekB
TomekB

Reputation: 461

Apache Camel - CXF: general endpoint's customer configuration

I have many WSDL(>100) files in my projects (many WS java interfaces generated). I want to use general configuration for cxf endpoints, not to configure many endpoints in camel xml configuration file for each ws.

<cxf:cxfEndpoint id="orderEndpoint"
    address="http://localhost:9000/order/"
    serviceClass="camelinaction.order.OrderEndpoint"/>

Is it any other way to configure camel cxf endpoint without manually adding it to xml file for each ws? Is it possible to use some camel annotations in generated interfaces (automatically)?

Upvotes: 2

Views: 1789

Answers (2)

raulk
raulk

Reputation: 2859

There is no Camel annotation to auto-discover JAX-WS interfaces in the classpath and load them as CXF endpoints. That's something too specific to your usecase.

What you can do is use programmatic Spring configuration to register the endpoints in the Spring registry which Camel then uses to resolve endpoints.

Create a class and annotate it with @Configuration and make it implement BeanDefinitionRegistryPostProcessor in order to get a callback along with a BeanDefinitionRegistry which will allow you to add new beans to the registry. Find an example here: Spring - Programmatically generate a set of beans (answer 2).

So now that you have the means to register new beans, you'll need to find the JAX-WS endpoints by searching your classpath. This SO question lists several alternatives: Find Java classes implementing an interface. Since you're using Spring, I would suggest you try out this one.

You'll need to define a technique to generate the bean name and the URL in a meaningful and predictable way, so you can access the bean from the Camel route, and the endpoint from the outside.

Don't forget enabling <context:component-scan /> in your Spring XML to instruct Spring to search Java classes for components.

P.S.: This does not require you to use the Java DSL of Camel. You're simply using Java code to introspect the classpath and dynamically inject the appropriate beans into the Spring registry.

Upvotes: 1

Paul M
Paul M

Reputation: 357

You can use Java DSL (rather than Spring XML) to declare your endpoints programmatically. See the question Apache Camel: RouteBuilder with CxfEndpoint for an example.

Dynamically discovering all of your web services is a separate issue, with many different possible solutions (such as naming conventions, implementing a shared interface, annotation processing).

Upvotes: 0

Related Questions