Why is there no easy way to consume web services in Java? - java

I've been doing a lot of work exploring different methods to consume (.NET) web services in Java clients. It seems that this area is a black hole in Java. The easiest way that I have found is to use Apache Axis2 wsdl2java to generate the source files. But still, this requires some work to integrate Apache into my existing web applications.
I'm surprised that there is no easier way. Why is that?

Because there is. The required functionality for SOAP clients are included in the standard API library. You can use the wsimport tool (located in the bin directory of your JDK installation) to generate client classes from a specified WSDL.

I've not used metro, but it sounds like it integrates with JAXB2.0 well and might be worth taking a look at. I noticed a metro vs axis2 comparison which might be interesting if you are familiar with axis2 already.
for quick and dirty stuff the apache commons httpclient + jaxb works well.

Related

Exposing Spring services as SOAP webservice

I have a quite extensive Spring 3.0 service architecture (the typical architecture; a bunch of model objects and a bunch of services that do stuff with these objects). I would like expose some of these services as SOAP web services.
We have developed SOAP web services before, but these have always been relatively simple and dedicated, and we have always used Axis 2. I found Axis 2 a bit heavy on the dependency and implementation side, and I'm a bit worried that this will bloat my current project something awful.
I have looked around and apparently using Apache CXF this would seem quite easy. So I'm looking for some advice on this. Does anyone have any practical experience with this? Pros and cons?
We are using spring with CXF for soap services and it goes very smooth. Following the CXF tutorial makes it straightforward to use by simply using the jaxws xml namespace.
I haven't really tested any other webservice frameworks - always been going with CXF and am quite happy with that.
If you're using Netbeans (even if not, it's still useful I'd say), check out this tutorial: http://sites.google.com/site/apachecxfnetbeans/loanproc
Just skip the first few paragraphs (Database integration, testing etc. etc. .. all of which you should already have knowledge about).
The CXF integration in Netbeans is useful for writing fast clients using the built-in netbeans functionalities.
cheers

Java Webservice Client (Best way)

I have a third party WSDL, I need to write code in Java for a web service client to invoke the operations in the third party WSDL. Right now, I have generated the client stub using the WSDL2JAVA tool from Axis and used the XMLbeans for data binding.
What is the best approach to do this JAVA?
I read about SAAJ, looks like that will be more granular level of approach?
Is there any other way than using the WSDL2Java tool, to generate the code. Maybe wsimport in another option. What are the pros and cons?
Can someone send the links for some good tutorials on these topics?
What are the options we need to use while generating the code using the WSDL2Java?
I used some of the basic things initially. Now I have these options
C:\axis2-1.5.1\bin>wsdl2java -uri mywsdlurl -o client -p somepackage -d xmlbeans -s -t -ssi
What is the best approach to do this JAVA?
I would personally NOT use Axis 2, even for client side development only. Here is why I stay away from it:
I don't like its architecture and hate its counter productive deployment model.
I find it to be low quality project.
I don't like its performances (see this benchmark against JAX-WS RI).
It's always a nightmare to setup dependencies (I use Maven and I always have to fight with the gazillion of dependencies) (see #2)
Axis sucked big time and Axis2 isn't better. No, this is not a personal opinion, there is a consensus.
I suffered once, never again.
The only reason Axis is still around is IMO because it's used in Eclipse since ages. Thanks god, this has been fixed in Eclipse Helios and I hope Axis2 will finally die. There are just much better stacks.
I read about SAAJ, looks like that will be more granular level of approach?
To do what?
Is there any other way than using the WSDL2Java tool, to generate the code. Maybe wsimport in another option. What are the pros and cons?
Yes! Prefer a JAX-WS stack like CXF or JAX-WS RI (you might also read about Metro, Metro = JAX-WS RI + WSIT), they are just more elegant, simpler, easier to use. In your case, I would just use JAX-WS RI which is included in Java 6 and thus wsimport.
Can someone send the links for some good tutorials on these topics?
That's another pro, there are plenty of (good quality) tutorials for JAX-WS, see for example:
Developing JAX-WS Web Service Clients (start here)
Introducing JAX-WS 2.0 With the Java SE 6 Platform, Part 1
Creating a Simple Web Service and Client with JAX-WS
Creating a SOAP client with either Apache CXF or GlassFish Metro (Glen Mazza's blog is a great resources)
What are the options we need to use while generating the code using the WSDL2Java?
No options, use wsimport :)
See also
Elad’s Adventures in Java WebServiceLand
Axis2: Why bother? on the BileBlog (be prepared for the bile) - you'll have to stop the redirect.
Related questions
What is the best java webservice framework?
Spring-ws or Axis2 or Something else for “Contract-First” approach to WS
I have had good success using Spring WS for the client end of a web service app - see http://static.springsource.org/spring-ws/sites/1.5/reference/html/client.html
My project uses a combination of:
XMLBeans (generated from a simple Maven job using the xmlbeans-maven-plugin)
Spring WS - using marshalSendAndReceive() reduces the code down to one line for sending and receiving
some Dozer - mapping the complex XMLBeans to simple beans for the client GUI
You can find some resources related to developing web services client using Apache axis2 here.
http://today.java.net/pub/a/today/2006/12/13/invoking-web-services-using-apache-axis2.html
Below posts gives good explanations about developing web services using Apache axis2.
http://www.ibm.com/developerworks/opensource/library/ws-webaxis1/
http://wso2.org/library/136
Some ideas in the following answer:
Steps in creating a web service using Axis2 - The client code
Gives an example of a Groovy client invoking the ADB classes generated from the WSDL.
There are lots of web service frameworks out there...

Web services clients in Java

I'd like you to list all the solutions available to generate web-service clients in Java platform.
I need to extract the structured information from the web-service to work with.
What do we have in the box? Preferably available as Eclipse plugins.
Axis2
JBossTools
Apache CXF
What else ?
The problem here is that most tools do not work with web-services I need to consume.
Apache CXF does not generate the client.
JBoss only partially does the job.
I would like to try something and find what really works with particular web services.
java.sun.com/webservices/.../wsit/.../Examples_glassfish6.html
this is for creating web services
No one gave a clear answer yet.
I got one advice: always try different versions of a framework, and try the latest.
It may sometimes be the key answer.

How to get started with java web-services?

I am intermediate in java now I am planning to move to java web-services...
How can i get started with web-services?
What are the prerequisites?
Thanks...
To get started with web services in Java, I would recommend to use the Java API for XML Web Services A.K.A. JAX-WS. The reference implementation of this API (JAX-WS RI) is included in Java 6 (since Java 6 update 4) so you don't have anything to install if you are using Java 6u4+. Like the other APIs of Java EE, JAX-WS uses annotations to simplify the development and deployment of web service clients and endpoints. This API supports both Java-first and contract-first approaches (the former begin debatable but, well, this is the easiest way to get started).
You'll find many good tutorials on the NetBeans website, see Getting Started with JAX-WS Web Services or Developing JAX-WS Web Service Clients for example. When it comes to web services, I must say that NetBeans has actually far more better support than Eclipse and would be my recommend IDE. I do not want to go to much into the details (because things will become confusing) so I'd just recommend to use GlassFish for the deployment of your JAX-WS web services, it has everything required included 1.
But please, forget Axis 2 and its horrible deployment model (to be honest, I don't understand why people keep mentioning Axis 2, maybe only because it has been promoted by IBM with its Eclipse support).
You'll find plenty of other resources on Glen Mazza's Weblog, for example the "famous" DoubleIt tutorial.
If you want to go further, have a loot at this great online Web Services Course from JavaPassion (great resources, as always).
1 If really you want to know, the web services stack in GlassFish is called Metro. Metro includes JAX-WS RI (the reference implementation of JAX-WS) and WSIT (that provides an implementation of others WS-* standards for Secure, Reliable, Transactional and Interoperable Web services). Another implementation of JAX-WS is Apache CXF. You may find all these terms in the literature. For now, I'd stick with JAX-WS RI with GlassFish as container and NetBeans as IDE.
This is a must if you plan to provide (SOAP based) webservices or want to get a feeling on how to consume services: soapUI
And I am quite happy with eclipse's web tools platform when it comes to designing xml schemas and wsdl files.
One of the most common java libraries is apache axis2. Pretty sure, they have a lot of documentation and tutorials on their pages.
Just start with apache tomcat and run a web-application in it with a small servlet or JSP, and then once you master a bit how to create web applications for tomcat, go and check axis2, this is a web application that gets installed in tomcat, then you will be able to run your own web services in axis2.
If you one something more advanced you could go and check EJB3 and create a stateless session bean that will work as a web service... but this is more advanced and is much more difficult to set up an EJB3 project, I advise starting with tomcat/axis2.
good luck.

Java SOAP Server that can be deployed in Tomcat, JBoss, Geronimo, etc. etc. etc

I'm hoping to create a Java SOAP server which I can deploy in Tomcat, or in JBoss, or in Geronimo, or in XYZ, etc. etc. etc.
Bottom line, it should have the least dependencies possible. I'm trying to avoid libraries outside of what's included in a standard java distro because of licensing/packaging/reusability issues.
Can any provide a link to where I should start looking, or some example code?
Java 1.6 introduced the possibility to create standard SOAP webservices with the standard JDK.
There are many examples on the web, for example http://weblogs.java.net/blog/2006/12/12/webservices-jdk-6
IDEs like NetBeans also call the necessary tools (apt) automatically which makes it very easy to get started.
However I did not research how well this will work across all available containers.
Apache Axis2 (http://ws.apache.org/axis2/) should provide what you're looking for, or JAX-WS (https://jax-ws.dev.java.net/) if you want more lightweight.
Wow.
http://www.w3.org/TR/soap/
There's the standard. You will be spending a lot of time on this project. You'll need to also check out the HTTP and XML specs to build those components.
Ignoring XFire and Axis2 is an very very expensive choice...
I recently used Metro 1.4 for this (an open source glassfish component) which implements the standard approach for web services.
Drop in the jars in a Java 5 web container, annotate your class and method with standard #tags, and let Metro do the rest.
I have been very pleased with performance in a Jetty container.
If you use Spring web service module you don't need Axis or XFire. I think it's a good way to go if you're already using Spring.

Categories