开发者

Jersey - consume XML and HTML on POST

开发者 https://www.devze.com 2023-03-14 06:54 出处:网络
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 me

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消