Calling a soap web service using java - java

In my java program, I need to call a SOAP web service that is deployed on a remote server.
Looks like there are several different approaches when explored in web.
But I would like to know as what is currently being used more in the developer world.
Also is there is a way to call a SOAP web service using Spring or axis or xfire.
Thanks in advance for your input.

For spring you can look at http://static.springsource.org/spring-ws/site/reference/html/client.html for client information.
When I write SOAP webservices I tend to use jax-ws now, especially since it comes installed with JDK6 now.
For a tutorial on that you can look at http://download.oracle.com/docs/cd/E17802_01/webservices/webservices/docs/2.0/tutorial/doc/JAXWS.html.
I like it since it uses annotations, so is simpler than using axis.
If you are using Spring then using their webservice options would be your best bet though.

Related

Simple web services in Java applications

I am new to web service and WSDL. I have a MySQL database stored in a server and I need to create a very simple web service that allows third party Java applications to input an integer (say 'membership number') and receive a string (say 'member name'). This should be done with WSDL.
Can someone please tell me what files do I need? A WSDL file, a schema file? Do I need a Java class stored in the server responsible to communicate with the database?
I am pretty lost, I would be thankful if you could give me some suggestion
As the simplest form of webservice is you can continue with JAX-WS, upon deployment of appilication it will publish a WSDL file and you can use this WSDL to communicate it from client
JAX-WS is the simplest way to convert an existing method into a web service endpoint, with a few annotations, and the simple web server in the standard Java 6 JRE. It can autogenerate the WSDL too.
This tutorial covers the essentials for getting started: http://java.dzone.com/articles/jax-ws-hello-world
I have found this to be a very robust technology.
Using the SOAP Webservices can get pretty messy. Unless you are forced, I would recommend you use REST for webservices, it is much less complex than SOAP. You can find a good REST tutorial here.
If on the other hand you must use SOAP, you could strat by taking a look here.

What is purpose of CXF or Spring WS

I am new to consuming web services. I am trying to consume a SOAP service. This is currently in the test environment. What I have done is
Use wsdl2java to generate a wsdl that I have copied to my domain folder.
Use the API to send requests and receive responses.
What concerns me is do I need CXF or Spring WS to wire the service or is what I have sufficient. I am asking this because I have seen elsewhere like
What I don't get is where I would generate property when environments are switching from development to QA to production. And do I need to use CXF or Spring WS or are the annotated classes (#WebServiceClient sufficient) to consume the SOAP service. Basically, how to connect to different endpoints.
I apologize if this is rudimentary question. Thanks.
Spring-WS and Apache CXF are primarily useful for creating web-services. They are alternative web service implementations to the one that ships with Java6.
You can use them for writing clients, but there's not really much point, unless you're really keen on the alternative API that those provide.
The standard JAX-WS artifacts generated by wsdl2java should be perfectly sufficient for what you need.
As for your second question regarding how to target different prod/QA endpoints, you should ask a separate question for that, with full examples of what you have.

Can we use php web services in java?

I have a web application in JAVA (Spring MVC framework) and I want to connect to a website and use its web services which wrote in php, is it possible ? if yes how can I do that?
It doesn't matter what language one used to create a webservice. You can talk to any webservice by agreeing on how it exchanges messages.
Yes, Spring integrates well with Apache Axis: http://axis.apache.org/axis2/java/core/docs/spring.html
To consume web services with Spring you can use JaxWsPortProxyFactoryBean to create a client proxy: http://musingsofaprogrammingaddict.blogspot.com/2009/03/writing-and-testing-jax-ws-clients.html
From Spring in Action, here's how you'd configure an example web service proxy bean:
<bean id="spitterService" class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean"
p:wsdlDocumentUrl="http://localhost:8080/services/SpitterService?wsdl"
p:serviceName="spitterService" p:portName="spitterServiceHttpPort"
p:serviceInterface="com.habuma.spitter.service.SpitterService"
p:namespaceUri="http://spitter.com"/>
The beautiful thing about web services, and web services are beautiful things, their hosts are made with wsdl's, their client is made in Spring! (Totally stole that from the mouse (just a warning, as per the comments, this rhyme is not to be used as an authoritative anything. It is an attempt at humor by someone who was excessively tired at 3 AM because of Win 7 issues))
Web services are language agnostic -- the only thing which matters is that they are up and running (and serving valid outputs), not that they are using technology X, Y, or Z. Theoretically, you could even have a webservice running on something written in Piet or Brainf*ck.
A tutorial on how to create a client can be found here.
Use CWSDLGeneratorDocument.php for generate WSDL file in DOCUMENT/LITERAl style and use standart library JAX-WS in java 1.7.

Combing Metro and Jersey

I've been at this for a little while and my mind has gone to mush.
I'm wondering if anyone can help me out here. I'm trying to make a Java Web Service (using its own HTTP server and not something like tomcat), that supports Metro and Jersey. This way a client can connect to the web service anyway they want whether it is SOAP or REST.
I've got the metro part down so it can support Doc/Lit wsdls and RPC/lit wsdls but I've having some difficultly understanding the Jersey part so it will support REST/xml and REST/json
Also the idea is that there would be one class where all the endpoint methods are written in and other classes would extend it.
Has anyone used these two combined before? Can you point me the direction of a decent article or do you have an example yourself?
Thanks
Metro is a implementaion of JAX-WS used mainly for WSDL/SOAP based webservices.
Jesery is a implementation of JAX-RS used maily for Restful based webservices.
I have used both in the same project but for different purposes. You can also use apache httpclient for restful services, but jersery provides lot of useful annotations for converting to json, xml etc. Hope it helps.
I am a bit confused about what you mean when you say you want to support Jersey. Jersey is an implementation of JAX-RS (JSR-311). Do you mean you want to support JAX-RS?

Creating a Java based web service

I have a very basic Java based web service requirement. Requirement is very simple, pass some String parameters, save them to database and generate a response ("success", "failed"). There is also a case where I need to return simple XML representation (SOAP message) of a simple Object:
<person>
<name>the name</name>
<address>the name</address>
......
</person>
Our current environment is Windows, Apache Tomcat 5, SQL Server.
I'm new to web services so I'm trying to figure out what technologies I could use to make this work. For example:
Do I really need Apache Axis 2 to implement this or would it be overkill?
I saw a tutorial online where all that was needed to create web service was Eclipse, Lomboz plugin for Eclipse and Apache Tomcat. Will I still need Apache Axis2 if I take this route?
Is it possible for Tomcat to process web service requests messages or do I need third party libraries?
I guess I'm looking for the easiest way to implement this. Thank you.
Do you actually need SOAP support? If you do, Axis is probably your best bet. Otherwise, I'd take a look at Jersey.
If it will be as simple as you have mentioned, why don't you look at RESTful Web Services? You can specify your resource calls through a GET, POST, DELETE or PUT HTTP methods.
There's a blog tutorial on how to achieve this. It also shows you how you can return JSON strings/XML (depending on what you want).
A web framework would make this much easier (and actually maintainable), but you could just write a raw servlet to handle requests. You'll want to use an XML object serialization method, though, or at the very least an xml parsing library.
I think you would need axis for this one. But I'll advice you to look at Apache CXF, if in future you will need more support with web service apps. CXF just like axis2 is an implimentation of jax-ws but with an advantage of supporting jax-rs (rest). This means you can expose both REST and SOAP web service interfaces.

Categories