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 gui开发者_高级运维dance or thoughts would be appreciated.
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.
精彩评论