This discussion is archived
8 Replies Latest reply: Jun 3, 2012 8:27 AM by 869679 RSS

Build a RESTful web service

869679 Newbie
Currently Being Moderated
Hello everyone,

I am quite new with RESTful web services (not with SOAP-based WS), but I have been reading and researching a lot. The point is that there are a lot of tools and frameworks and I am confused.

I have to build a RESTful web service that retrieve an Employee resource in XML and JSON formats. Data for the Employee resources are given in txt files and the schema for the XML response "employee.xsd" is also given.

I have to use Java.

Any idea where can I start from?

Thanks in advance
  • 1. Re: Build a RESTful web service
    r035198x Pro
    Currently Being Moderated
    Do you already have a target container that you are going to deploy this at?
    If so then start by checking the docs for the provider they ship with and see if it's going to meet your requirements.
  • 2. Re: Build a RESTful web service
    gimbal2 Guru
    Currently Being Moderated
    The first step is to pick a JAX-RS implementation and stick with it. If you don't want to research them then stick with the reference implementation, which is called Jersey. Of course if you're using a JEE6 compliant application server, JAX-RS is already in there so you may want to stick with the implementation that is provided.

    From there it is a matter of making the documentation your own and creating some test setups to get a feel for it. A good book will also help immensely of course.
  • 3. Re: Build a RESTful web service
    869679 Newbie
    Currently Being Moderated
    Thanks for your answers.

    No, I don't have any target container. In fact, I have the option to consider any open source framework, libraries or any standard JSR-XXX, but I have to take into account the software design, testability and maintainability of my code.

    I should build the RESTful web service with production quality and explain the chosen technologies.

    I am reading several pdfs about RESTful, and trying to find a proper step by step tutorial, but there are several implementations of JAX-RS (jersey, CXF, Restlet, Wink,...) and not sure which one to choose, which target container, or which application server.

    If it is only for testing the technology I will choose Jersey, but I am not quite sure that this implementation is being used in production.

    Any idea?
  • 4. Re: Build a RESTful web service
    gimbal2 Guru
    Currently Being Moderated
    Alvaro wrote:
    I am reading several pdfs about RESTful, and trying to find a proper step by step tutorial, but there are several implementations of JAX-RS (jersey, CXF, Restlet, Wink,...) and not sure which one to choose, which target container, or which application server.

    If it is only for testing the technology I will choose Jersey, but I am not quite sure that this implementation is being used in production.

    Any idea?
    No, nobody can have an idea. Yeah I can tell you to use JBoss 7.1, but that's only because I prefer JBoss. You could also use JAX-RS on Tomcat. Or go for the "default" Glassfish.

    I'll repeat what I said: do test setups. Try it. See what works for you. That's the only way you'll get anywhere, nobody. I repeat: nobody can tell you what you should be using. Only you can, after extensive research and trials. If that is not an option then there is basically only one path to take: pick defaults (likely Glassfish which will have Jersey) and stick with it, then deal with the consequences of your lack of preparation later on. Or not, perhaps it will just work for you. Who knows.
  • 5. Re: Build a RESTful web service
    869679 Newbie
    Currently Being Moderated
    Thanks gimbal2 for the quick response.

    I just wanted to know about other's experiences that it is always good to know.
  • 6. Re: Build a RESTful web service
    gimbal2 Guru
    Currently Being Moderated
    Alvaro wrote:
    Thanks gimbal2 for the quick response.

    I just wanted to know about other's experiences that it is always good to know.
    That's the thing: not really as you're asking the experiences of complete strangers here. It is also only an escape from the inevitable effort that you have to make, with or without "experiences" of others. Just because I had good results using JBoss does not mean you'll have the same. There are plenty of people that come to this forum with the full intent of having other people tell them what to do, followed by "then how do I do that? Can you give me a step by step guide?", followed by "Can you send me an example program?", etc. etc.

    I hope you're different because it just doesn't work that way. But hey, if you want to play around with JBoss then I will not send you off to fend for yourself, I wrote an article about getting up and running:

    http://entjavastuff.blogspot.nl/2011/12/jboss-7-getting-started.html

    That's about JBoss 7, but you can just drop in JBoss 7.1 and it should work as written. BalusC has a nice article on getting up and running with JSF 2 on Glassfish; even though the JSF part is not interesting to you the Glassfish 3 setup part certainly is:

    http://balusc.blogspot.nl/2011/01/jsf-20-tutorial-with-eclipse-and.html
  • 7. Re: Build a RESTful web service
    869679 Newbie
    Currently Being Moderated
    Thanks again gimbal2. I really enjoy the way to resolve a problem by myself, trying different things, learning new technologies, optimizing my solution, but sometimes others' experiences help you a lot particularly when you don't have to much time to play.

    Seriously, thanks a lot for your comments. I am going to have a look those links :)
  • 8. Re: Build a RESTful web service
    869679 Newbie
    Currently Being Moderated
    Hi again everyone,

    Finally, I have implemented a solution using Spring MVC and its RESTful capabilities. I have tested with curl and RESTClient, the RESTful web service does part of the job. Anyway, there is only one thing that get me confused.

    When I load the data of Employee resources from the text files in my DAOs, I read the proper file and create an object of the domain class Employee, then I return this object. I can get the xml and the json representation of the Employee resource doing the proper request, but both of them don't match the schema employee.xsd. The sequence of the elements are in different order from the schema and also between both requests (xml / json). In fact, I haven't used the employee.xsd in all the project. I don't have too much experience with XML schema :(, but I know that something is missing.

    What do you think?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points