RESTful java web service with XML Response

In my previous post I discuss about how to write a simple REST web service using jersey, today we discuss more on it and demonstrate how you can create custom java class with JAXB and deal with XML response using jersey.

Let’s first create eclipse Java EE project and add all depending jersey jar files in classpath.

Edit your web.xml to look like similar to following.

We create Car class and make it JAXB compatible so it will be easy for jersey to return response in XML-format. Your class should like below. The annotation is self-explanatory.

Customized exception class for proper exception propagation to client.

Now write web service class which uses Car class and return response to client in XML format. We use @Produces (MediaType.APPLICATION_XML) annotation for returning XML format.

After publishing this web service you can access this through browser using following URL.
http://localhost:8080/RESTfulTest/rest/xml/car/nano

Write java client to access this web service…



Download Source

About the Author

has written 50 posts.

I Love Coding, Analyzing, Designing and doing it the right way. I am obsessed about learn anything new daily and sharing what I have learn each Day. This Blog is journey of my Zeal, going through step by step to the mountain of desire to become prefect. Google

Copyright © 2014 TechZoo - Technology Blog. All rights reserved.
Proudly powered by WordPress. Developed by 7Tech Solutions