craig
craig

Reputation: 26262

Jersey - consume XML and HTML on POST

I would like to provide a flexible authentication method for my RESTful webservice - either via a HTML form or XML. I realize that I can make an AJAX call from the HTML form, but I thought a simpler mechanism would be useful (especially during development).

If I annotate my SessionResource.createSession() method with @Consumes("application/xml","application/x-www-form-urlencoded"), it will accept both types of content. The hard part is to differentiate the XML stream from the HTML.

Any guidance or thoughts would be appreciated.

Upvotes: 1

Views: 1678

Answers (1)

Alexandre Martins
Alexandre Martins

Reputation: 624

Why not do the following:

@...
class SessionResource{

 @POST
 @Consumes("application/xml")
 public void createSessionFromHTML(String message){
   ...
 }

 @POST
 @Consumes("application/x-www-form-urlencoded")
 public void createSessionFromXML(String message){
   ...
 }
}

In case this does not solve your problem please have a look at @QueryParam, @HeaderParam and @FormParam.

This overview may also be of some use to you.

Upvotes: 6

Related Questions