Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple JAX-RS example with @Consumes, @Produces and JAXB
    primarykey
    data
    text
    <p>I'm trying to create and run simple example of JAX-RS using <code>@Produces</code>, <code>@Consumes</code> annotation and JAXB.</p> <pre><code>@Stateless @LocalBean @Path("/hotel") public class RestMain { @GET @Produces(MediaType.APPLICATION_XML) @Path("{hotelId}") public HotelRESTInfo read(@PathParam("hotelId") long hotelId) { HotelDataSourceFake hotelDataSourceFake = new HotelDataSourceFake(); HotelRESTInfo hotelInfo = hotelDataSourceFake.getFakePlaceById(hotelId); return hotelInfo; } } </code></pre> <p>web.xml:</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;REST App&lt;/servlet-name&gt; &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer &lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>The second application which is the client. Now I have the following client code:</p> <pre><code>import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; ... Client client = Client.create(); String uri ="http://localhost:8080/RESTJEE/rest/hotel/" + hotelId; WebResource resource = client.resource(uri); ClientResponse response = resource.accept("application/xml").get(ClientResponse.class); HotelRESTInfo hotelRestInfo = response.getEntity(HotelRESTInfo.class); </code></pre> <p>But I don't want to use jersey's Client, ClientResponse and WebResource. I want to do this with <code>@Consumes</code>. Should client appliaction <code>web.xml</code> contain some additional parameters?</p> <p>Both sides (client and server) contain the <code>HotelRESTInfo</code> class:</p> <pre><code>@XmlRootElement public class HotelRESTInfo { ... } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload