I have seen the other questions on CXF under CDI but they all seem to be for JAX-RS style web services.
Is JAX-WS possible in this configuration? If not, how can I expose a JAX-WS service using CDI/Weld in a non-EE container (Tomcat 8)?
If you want to use CDI and JAX-WS in Tomcat then most possibly the easiest you can do is to use Apache TomEE.
TomEE is basically a standard Apache Tomcat, but pimped with lots of JavaEE libs. It brings a full CDI container, JAX-RS, JAX-WS etc.
For JAX-WS you should take the 'plus' variant.
If you want it really just embedded or smallish (in size, not in power), then you can also take a look at Apache Meecrowave and bundle the JAX-WS part of CXF to it.
Meecrowave is a EE8 technology based smallish (9MB) Application Server which can be used standalone or embedded (via Meecrowave#bake()). It's pure Apache:
Tomcat (Servlets-4.0), OpenWebBeans (CDI-2.0), Johnzon (JSON-P_1.1, JSON-B_1.0), CXF, log4j2.
First, you have to enable CDI on tomcat. See here.
In my case, #Inject did not work on classes with #WebService but I was able to inject using CDI.current().select(MyClass.class).get().
It did not work on #PostConstruct though, but you can use it inside a #WebMethod.
[Note] I was using Metro instead of Apache CXF
Related
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..
The Camel web page says
The following projects can leverage Apache Camel as a routing and mediation engine:
Apache ServiceMix - a popular distributed open source ESB and JBI container
Apache ActiveMQ - a mature, widely used open source message broker
Apache CXF - a smart web services suite (JAX-WS and JAX-RS)
Apache Karaf - a small OSGi based runtime in which applications can be deployed
Apache MINA - a high-performance NIO-driven networking framework
However, I would like to run Camel inside a Java EE web application and have access to web services, JMS, and EJB (CDI, message driven beans, JPA, etc.) Preferably using an open source Java EE server.
If I recommend this to my company, then then all the usual Java EE wizards such as wsdl2java need to work out of the box. There also needs to be documentation and tutorials so we can hire people to jump in and start using it.
Glassfish failed across the board. The wsdl2java wizard for CXF fails using the Glassfish runtime classes (I ran it manually and hacked my code tree.) There is no documentation nor any tutorials for wiring in OpenMQ (and google searches on the topic are discouraging.) Simple library-only samples run fine, of course, but without having ActiveMQ as the native JMS it seems to be a dead end. CXF integration seems unworkable as well. My first attempt at copying a WS sample complains "No component found with scheme: cxf" which appears to be a bundle or classpath issue.
I'm starting to think I should go back to ServiceMix and drop back to servlets without EJBs and CDI, even though I really hated not being able to use Eclipse gracefully for edit/compile/debug (you pretty much have to build and run from an outside DOS prompt window and remote debug in.)
You can use Apache Camel with any container of choice. We try to not have any restrictions or barriers. You can also run it standalone. The web page just mentions some of the containers you can use.
Apache Camel is just a bunch of JAR files you can deploy and use in any container of choice. For example with WAR files you can deploy to Tomcat, TomEE, etc.
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 !
I have ported a Java EE web application from JBoss 4.0.5/Java 5 to Tomcat 6.0.33/Java 6.
The web application exposes some web services. They were implemented as JAX-RPC web services in JBoss, I have adapted them as JAX-WS web services using CXF 2.6 as the implementation run-time. Now I have been requested to make available in the new environment (Tomcat 6.0.33/Java 6) also the JAX-RPC web services for compatibility with existing clients. The two versions of the same web services would of course be available through two different end point URLs.
The JAX-RPC web services in JBoss 4.0.5/Java 5 are implemented using Spring (the implementation class extends org.springframework.remoting.jaxrpc.ServletEndpointSupport, found in spring-remoting-2.0.8.jar) but I cannot guess which is the underlaying implementation framework for JAX-RPC made available by JBoss. I just can see that the configuration files are webservices.xml and jaxrpc-mapping.xml.
I tried to "replicate" that Spring configuration in Tomcat but when I try to retrieve the WSDL I get an error javax.servlet.ServletException: Class pack.age.MyEndPoint is not a Servlet. Indeed that class (the JAX-RPC end point implementation class) is not a servlet but under JBoss 4.0.5/Java 5 it is declared in web.xml as a servlet and it works.
Could you please help? I imagine I just have to supply the proper JAX-RPC implementation framework to Tomcat (I would like to avoid AXIS because it uses different configuration files). Thanks in advance.
This might be obvious but i just still don't understand how i'd do it with ServiceMix :
An external web service http://mypartner.com/service/partnerService
My platform is for example http://myservicemix.com/
I'd like to use OSGI bundles
Is this what i need ? :
A cxfbc:provider (this is the one that talks to the remote service, just a wsdl in the bundle right ?)
A camel route and transformations to bridge the two
A jaxrs:server (i'd like to expose it as a REST service)
The cxfbc is a JBI component. JBI is essentially dead/legacy, so I suggest to not use that for new projects. You can read more about JBI is dead here: http://gnodet.blogspot.com/2010/12/thoughts-about-servicemix.html
So Apache ServiceMix is the server where you can host your Camel applications. So I suggest to look into how to do a webservice proxy with Camel.
For example there is an example with Camel
http://camel.apache.org/cxf-proxy-example.html
That example is OSGi ready and can be deployed in Apache ServiceMix.
Also check out some of the CXF examples that are shipped with Apache ServiceMix, in the examples directory
The Camel CXF component can do both REST and WS.
Also there is the camel-restlet component for REST support as well: http://camel.apache.org/restlet