• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MIME types in web services

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to implement a simple web service through java.I found that we can return an output in different formats irrespective of MIME type declared,we just need to have the path declared in @Path annotation at the method level and the path given in the url matching.

For example:

@Path("/trial")
public class Myservice {
Document doc=null;
List<Document> ld=new ArrayList<Document>();
//String doc=null;


@GET
@Path("/doc")
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
System.out.println("coming in empty method");
return "Hello Jersey plain text";
}

}

In the above example,though for the method sayPlainTextHello() we have declared mime type as text_plain for response,i tested it by returning an xml object which i created doing some JAXB stuff i.e i found that if i give the same path "doc" in the url then the above method will be called and will return an xml or any other format other than text_plain,if intended.

Please someone clarify the logic behind this.

Thanks.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic