Use of #Provider and #Component in CXF - cxf

Can anyone explain about #Provider and #Component and when we need to use in Apache CXF for both Rest and Soap Implementation ?

There are two #Provider annotations, a JAX-RS standard annotation and a native CXF provider annotation. You can use them to mark a provider, it will be auto-discovered depending on the setup you use. #Component is a Spring annotation and can be used as an alternative.
If you are using a Spring Boot based setup see http://cxf.apache.org/docs/springboot.html for the different scanning options.

Related

Camel 3.x: Disable automatic registration of routes

I have been trying to migrate from Camel 2.x to 3.x and having some issues with Spring Boot integration.
With Camel 2.x, i managed to disable auto injection of RouteBuilder instances annotated with #Component but have the other benefits, camel-spring provides. I do that since i have a prototype bean that extends from RouteBuilder and i manually add them to camel context as required.
With Camel 3.x, i can't do that. I can't remove #Component annotation from the class since i need Spring to inject other dependencies to class. Is there a way do that with Camel 3.x?
Auto-discovery and registration of RouteBuilder instances to CamelContext can be disabled with property camel.springboot.routes-collector-enabled=false.
See Camel Spring Boot docs:
camel.springboot.routes-collector-enabled
Whether the routes collector is enabled or not. When enabled Camel will auto-discover routes (RouteBuilder instances from the registry and also load additional XML routes from the file system. The routes collector is default enabled.
To disable Camel auto configuration (for example in tests)
#EnableAutoConfiguration(exclude = CamelAutoConfiguration.class)

Does CXF 3.1.X uses Apache HttpComponents - HttpClient?

Does CXF 3.1.x really uses Apache HttpComponents - HttpClient for http transport? Maven dependencies does not list "Apache HttpComponents" as dependency nor do I see any HttpClient class in the CXF jars? However CXF JIRA CXF-6704 discusses about it?
I need access to HttpClient in CXF for NTLM support per connection basis which CXF by default relies on Java 6+ Authenticator which is set per JVM.
CXF has a decoupled runtime layer. Mostly they start with cxf-rt-*.
In the case of transports, cxf-rt-transports-*.
Take a look at this. I believe that this is the HTTP Components transport runtime.
EDIT: I think this is for asynchronous transport - (looked at the pom after I posted this).
EDIT2: I did a little more research on this and found this documentation. It says that the async client can be used for synchronous calls by setting use.async.http.conduit bus property to true. This also specifically refers to NTLM authentication.

How configure JAX-WS for the WLP v 16.0.0.4

I use jaxws-2.2 feature and need to know how to configure JAX-WS for the WLP v 16.0.0.4.
WLP uses Apache CXF implementation for JAX-WS. Apache CXF JAX-WS configuration includes the next two steps.
Create servlet class mapping (org.apache.cxf.transport.servlet.CXFServlet) in the web.xml
Create the JAX-WS endpoint configuration (jaxws:endpoint) in the cxf-servlet.xml
Maybe there are the other ways for configuration JAX-WS Apache CXF implementation on Liberty, however, I don't know it. All examples for cxf-servlet.xml that I found related to Spring:
https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.1/html/Deploying_into_a_Web_Server/DeployCxf.html
Apache CXF http://cxf.apache.org/docs/jax-ws-configuration.html
IBM https://www.ibm.com/developerworks/websphere/library/techarticles/1001_thaker/1001_thaker.html (please see attached pdf and sample application).
I couldn't find the cxf-servlet.xml example for the pure Java EE application without Spring (and any others 3rd party) dependencies.
Kind regards,
Alexander
Once you've added the jax-ws feature to server.xml, the easiest thing is to create a war file with a class in it, just like you would a servlet, but this class has an #WebService annotation on it instead of an #WebServlet. The public methods will become your webservice operations. WSDL will be produced automatically when you deploy the war file. It's exact URL is probably detectable by looking at Liberty's messages.log file. Web.xml is optional.
It's a big mistake to deal with the JAX-WS implementation provided within WLP (here cxf)...
You don't need specific "configuration", just stick with the JAX-WS specification that has lots of annotations to define the services, the operations, the endpoints and the parameter mapping (JAX-B) etc. You don't need any configuration file
In short, just create a POJO, annotated the class with #WebService and the methods with #WebMethod
You'll find lots of tutorial on the web. One from Oracle is here
Check the classes in the javax.jwsand javax.jws.soap packages in the official jee6/jee7 javadoc
It's the same principle for REST services, ie plain annotated POJO classes..

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

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 !

Resources