Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:10:21+00:00 2026-06-13T04:10:21+00:00

I’m trying to create and run simple example of JAX-RS using @Produces , @Consumes

  • 0

I’m trying to create and run simple example of JAX-RS using @Produces, @Consumes annotation and JAXB.

@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;
  }
}

web.xml:

<servlet>
    <servlet-name>REST App</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

The second application which is the client.
Now I have the following client 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);

But I don’t want to use jersey’s Client, ClientResponse and WebResource.
I want to do this with @Consumes.
Should client appliaction web.xml contain some additional parameters?

Both sides (client and server) contain the HotelRESTInfo class:

@XmlRootElement
public class HotelRESTInfo {
...
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:10:22+00:00Added an answer on June 13, 2026 at 4:10 am

    I think that you are mismatching something.

    You have on one side the HttpClient that make requests, and on a other computer the HttpServer that build responses. It’s basic and I suppose you get it.

    The thing is that the @GET read ()method consumes the request body, and produces the response body.

    So you can have :

    @GET
    @Consumes(MediaType.APPLICATION_XML) //client sends also xml
    @Produces(MediaType.APPLICATION_XML)
    @Path("{hotelId}")
    public HotelRESTInfo read(@PathParam("hotelId") long hotelId) {
        (...)
    }
    

    Obviously, you would like that your client consumes webservices, so @Consume definitively makes sense in the Client side.

    Unfortunately, JaxRS was built on the server side in 2008 or so, without thinking of synergies with a Java client. And @Consumes is definitively a server annotation, and I haven’t seen in the documentation anything about reusing annotations on the client.

    The Jersey client is pretty recent, in an effort of the JaxRS 2 specifications. Your questions shows that these specs may be difficult to write !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.