How configure JAX-WS for the WLP v 16.0.0.4 - cxf

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

Related

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

JAX-WS with Apache CXF under CDI/Weld

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

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 !

Using ServiceMix to Proxy Remote Web Service

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

RESTlet 2.0 tutorial application does not work on appengine

I have been playing with the source code available from the following tutorial.
The GWT/GAE application works in development mode, however when its deployed, the server always returns the response in the JSON format.
I am using the Restlet 2.0 Testing jars, and have also included the dependent libraries.
thank you
I had similar problem you are now experiencing:
Restlet POSTing JSON to Appengine error
As described in my own answer I managed to get it working after much fiddling.
Since then I switched to Jersey.
Two things to consider:
Editions
You need to use the GAE edition of Restlet for the server-side app, and the GWT for the client-side app. Neither will suffice for both. For this reason, the two apps are separate projects in the tutorial archive. So make sure you're using the appropriate edition for each side.
Object/Representation Conversion/Serialization and Extensions
I believe that with Restlet 2.0, when a class method annotated with an HTTP method returns a Java object, and doesn't specify how it should be serialized -- converted to a representation -- then Restlet will defer to whichever Restlet extensions are in the classpath which implement this.
In the tutorial, the server-side app includes this jar: "org.restlet.ext.jackson: Jackson extension used to generate JSON representations of the contact resource" -- which I believe is the reason that the response is JSON; the framework is deferring to the extension, which is converting the object into a JSON representation.
Therefore, if, for example, you wanted the framework to automatically serialize your objects into XML, you could remove the Jackson extension JAR from the classpath, and instead include the XStream extension. I believe that would cause the framework to serialize the objects as XML.
The wiki page for ConverterService lists the various conversions which the framework supports, and which modules enable them.
HTH!

Resources