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.
Related
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.
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.
I just want to implement a service in java that will:
take some arguments, then search the database
return the JSON object of the fetched data
I need help to identify the ways through which I can implement this thing.
e.g. Suppose I am getting the name of the book as argument I want to render.
On service part, I have to fetch book data and convert it to JSON and write/return to response.
I was looking at the Apache Axis2 but I am not sure that I am going in the right direction.
So, pls help.
Need guidelines not implementation.
Thanks
I would suggest using JAX-RS based services which would be ideal for your scenario as you want json data. These are pretty easy to get started with. Jersey is a widely used frameworks. Also see RESTEasy.
If you are returning the data in JSON then you probably don't need to implement a full web service, which uses XML for both the request and the response.
A normal dynamic web application (written as a Java Servlet) will be able to read request parameters in the HTTP payload and return a JSON-encoded HTTP response.
However you need to consider your clients; if they are only able to access web services then you need to forget about a JSON response and simply objectify the response. However if the clients can access web resources without issue then go with the servlet approach.
If you need to go with web services then look at the Metro 2 framework.
One way to do this is to keep it standards-based.
If you are using the JEE5/6 framework, your best bet would be to go with JAX-WS - comes built-in with the JSE too (if I remember correctly)
You really just have to annotate a POJO with #WebService to achieve this.
Regarding creating a JSON response, a good bet is to stick with the implementation from http://code.google.com/p/google-gson/ ; simple and straightforward
Axis2 can handle/support the webservice related part, iaw, transforming java objects into JSON and vice-versa and providing an easy-to-use API for the communication part.
Hibernate or JPA could be useful for database related tasks, although it might be easier to just use JDBC to send some simple SQL commands to the database (especially if the database already existst).
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?
I am new to web services. I have a requirement in my project. I have to consume the web services of our vendor in my project. All he has shared with me is a WSDL file and a document about the description of the the different operations.
Question:-
1: What do I need to do consume these web services in my java project? I have been advised to use axis2, eclipse with tomcat6.
2: Do I need to ask for some other files/information from WS vendor OR wsdl file is enough to consume these web services?
3: Do I need to write a java WS client (using axis2 plugin) or another webservice which will talk to vendor web service?
Please suggest the best possible way.
I am sorry if the question sounds like a naive..
Axis is a solid choice for such application.
You need to generate an axis client based on the provided WSDL. Then you import the generated client and use it's methods. You can see the details of this process here (read whole page or starting from the linked section): http://ws.apache.org/axis2/1_0/userguide3.html#Writing_Web_Service_Clients_using_Code_Generation_with_Data_Binding_Support
You could also need some entry-point (WebService URL).
You need to generate a client, not a webservice. See point 1.
Don't use Axis if you need ambient authentication in a Windows environment. I went down that path and ended up going with Apache CXF - which seems better to me anyhow.
You can use SOAP UI to test the web service. It'll read the WSDL, let you create requests by filling in values, and display the response that you get back. It might help you get a better understanding of what the service does before you start writing your classes.
You don't need to create a new web service in order to consume a web service, you need to write a web service client.
Similar question to this one:
Steps in creating a web service using Axis2 - The client code
All the standard web frameworks have a command (normally called wsdl2java) that will read the WSDL and then generate a java based client object.
I can recommend Axis2, but another popular choice is CXF