开发者

Java Jersey: Get client IP in rest method on Tomcat

I have a Jersey rest webservice that runs on tomcat 6. I have a @Post method that consumes Multipart:

@Path("identify")   
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(Me开发者_开发技巧diaType.APPLICATION_XML)
    public String identifyReception(com.sun.jersey.multipart.MultiPart multiPart) throws Exception {

I would like to get the client IP address inside this method. I found out that you can use @Context HttpServletRequest inside Get method. But in post method I need the multipart input argument. I have also found out that tomcat does not support Servlet specification...

Is there another way I can do it?


I found out that you can use @Context HttpServletRequest inside Get method. But in post method I need the multipart input argument.

I don't think the two are mutually exclusive. Let your method take two arguments (I don't think it matters what order they're in) and annotate one of them with @Context. I believe that will work whether it's a get, post, whatever. You could also just annotate a field with @Context and Jersey will initialize it for you before it calls your @GET method.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜