Apache Camel on a JAXRS API? - apache-camel

Could anybody explain how Apache Camel is able to behave as a routing and mediation engine on a JAXRS API?
As far I've being reading about I've not been able to figure out what's it for?

You can consider Apache Camel as a great integration framework. It doesn't provide functionality itself, but it makes easy to glue multiple services and protocols together.
Apache Camel can expose a REST endpoint using the CXFRS component. This means it listens for a REST call on certain endpoint (URL). On invocation it doesn't invoke the implementing bean (service) itself, but executes a defined mediation route (invoke a route with its Exchange object).
It is very useful when you need to integrate multiple services or translate the call to other protocols. You can implement a REST service by a bean itself and it's ok until the bean provides some functionality or data itself. For integration you often need more flexibility to integrate multiple sources and protocols. Then Apache Camel can be much more practical tool.

Related

Comparison of Camel REST DSL to JAX-RS spec (v2.0)

We are considering the option of defining our REST interfaces using Camel REST DSL, as we are already using Camel for message routing, integration patterns and more. It seems that REST DSL covers what a standard JAX-RS implementation can do, but I am not sure if this is 100% true. Additionally, exposing the REST interfaces through Camel has the the added value of transparently propagating all the HTTP request headers to the Camel message, which seems to be a nice feature.
Apart from the non-functional issues, like separating interface and implementation that JAX-RS can offer, which option would you choose? Any input would be much appreciated.

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)?
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.
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).

Apache-Camel, ActiveMQ, camel-jms and Fuse -> why do I need them?

I am still struggling with undertsanding some of Camel's main features and limitations.
My objective is to implement a demo application that can migrate camel endpoints. To achieve this everyone suggested that I should use the camel load-balancer pattern with the failover construct.
To achieve this objective people have suggested Fuse and ActiveMQ. Some have even suggested JBoss, but I am lost.
I understand that Camel needs the an implementation of a JMS server. To achieve this I can use ActiveMQ - a free implementation of a JMS server.
However camel also provies the jms-component. What is this? Is this a client implementation of JMS? If so, should I not be using an ActiveMQ client for JMS? Could someone provide a working example?
With ActiveMQ and JMS understood I can then try to find out why people suggest Fuse. I want my implementation to be as simple as possible. Why do I need Fuse? The Camel+ActiveMQ combination has the load balancer pattern with the failover mechanism right?
I am lost in this sea of new technologies, if someone could give a direction I would be thankful.
Camel provides two components. The first is the jms component, which is a generic API for working against JMS servers. The other is the activemq component, which uses the activemq API for working with activemq message brokers. The activemq component is the default component within things like servicemix/fuse, using an internal broker (not a networked/external broker).
If you are connecting to activemq, you can use either the activemq component or the jms component. The jms component will not start up a broker automatically, you would need to do this yourself.
Fusesource == JBoss Fuse == Apache ServiceMix + some addons. For argument sake, i'm going to refer to all three of these as ServiceMix.
ServiceMix is an enterprise service bus, you can lookup the term on wikipedia if you're not familiar with the concept. It uses Apache Camel to define routes between your components, implementing a number of integration patterns as you so need. ServiceMix deploys by default with Apache CXF, for JAX-RS and JAX-WS services and Apache ActiveMQ, a JMS message broker. Using Camel, you can tell service mix that when a REST API is called, do a series of steps, each step decoupled from the one before it.
JBoss Fuse (the enterprisey, costs money edition) comes with some additional components around fail over. Some of these are present in servicemix (namely, you can run servicemix in a hot stand by mode, waiting for the primary to go down). The Camel load balancer pattern doesn't really mean anything around replication, except that a message coming from one endpoint can be delivered to any of a set of a N endpoints. http://camel.apache.org/load-balancer.html
On the flipside, take a look at ServiceMix's failover http://servicemix.apache.org/docs/4.4.x/users-guide/failover.html
I think based on your question you're referring to system failure failover (needing to work against a new instance), and not a Camel Loadbalancer component (which is likely where the confusion is coming from, on the community side and your side).
start by reading these...Camel In Action, ActiveMQ In Action

What is benefit of developing webservice using Apache CXF over normal JAX-WS with Java6

Can some body expalain what is the benefit of developing JAX-WS webservice using apache CXF over normal JAX-WS provided by Java 6.
JAX-WS is only the api / specification - to use it you need an implementation. It can be something like CXF, Axis or the one provided by the application server (JBoss, Weblogic et..).
One advantage of using CXF is that you have more flexibility in terms of deployment. It can be deployed in a web container or you can use an embedded web container and runt it as a stand alone application.
CXF also provides integration with other frameworks like spring.
It also provides tools to work with schema / WSDL etc..
Apache CXF is a open source webservice framework which contains JAX-WE and JAX-RS and also it helps to integrate with spring framework
CXF Supports
1) XML , JSON Format
2)JAXB Data Binding
3) SAOP ,REST,HTTP protocal binding
I have recently completed the web service implementation with JAX-WS using reference implementation apache-cxf. And I found with CXF - integration with Spring is very easy. Moreover, It provides various features like:
Customization of Logging features
Inbound and Outbound interceptor
Application Level security
Easy Exception handling using custom Fault.
For more detail, if you want, please checkout this link: http://predic8.com/axis2-cxf-jax-ws-comparison.htm
And, I read above link, its preety helpful for me.
Thanks !

jax-rs, active mq integration

Can anyone give me a sample source code where i can use restful jax-rs web service as an interface to message broker using active mq. The requirement is traffic comes to application through jax-rs webservice and the message is transferred to active mq which is processed asynchronously and the consumer on active mq inserts data into db. Can anyone please provide sample code, that would be great
The question is very fuzzy. There are multiple concerns to take into account when doing this kind of interfaces as jax-rs is a http interface (synchronous, non transcational, non persistent, non guaranteed delivery) while activemq (jms) is the other way around, asynchronous, transactional and persistent.
I suggest you take a look at Apache Camel which is a lightweight integration framework that works really good with ActiveMQ. It supports JAX-RS as well. There are multiple code examples over at the Camel website and connecting rest with activemq is rather easy given you have your case fully designed.

Resources