• Post Reply Bookmark Topic Watch Topic
  • New Topic

MIME types in web services  RSS feed

 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!