On Mon, 2011-10-31 at 14:34 +0200, Andre Juffer wrote:
> On 10/31/2011 01:46 PM, Thorsten Scherler wrote:
> > On Sun, 2011-10-30 at 19:35 +0200, Andre Juffer wrote:
> >> Hi,
> >>
> >> for processing a multipart/form-data request holding image data, I
> >> intend to use the commons imageupload [1]. In order to do so, I need to
> >> get access to the javax.servlet.http.HttpServletRequest object inside a
> >> REST resource. The @Context annotation injects information about the
> >> request, see e.g. [2] and also [3], but the request object should
> >> implement the javax.ws.rs.core.Request interface (I think).
> >>
> >> How can I get to the HttpServletRequest inside a REST resource. Is there
> >> a way to convert Request to javax.servlet.http.HttpServletRequest?
> >> According to [4],"When deploying a JAX-RS application using servlet then
> >> ServletConfig, ServletContext, HttpServletRequest and
> >> HttpServletResponse are available using @Context." But how?
> > http://stackoverflow.com/questions/6984338/how-to-forward-from-a-jax-ws-service-to-jsp
> >
> > like you have
> 
> Yes, indeed. I don't have the exception though.
> 
> >
> >> Right now, I assume
> >>
> >> @POST
> >> public Response uploadImage(@Context HttpServletRequest request) {
> >> .....
> >> }
> >>
> >> but I do not believe this is actually correct.
> > It should.
> 
> Yes, it seems now that this should be the case.
> 
> >
> >> The actual type is com.sun.jersey.spi.container.ContainerRequest
> >> (implements Request), according to request.getClass().getName().
> >>
> >> There is nothing in the request itself, while I see with Firebug that
> >> the image file is sent to the server in the proper way.
> >>
> > Hmm
> > http://jersey.java.net/nonav/apidocs/1.9.1/jersey/com/sun/jersey/spi/container/ContainerRequest.html
> >
> > did you try a simple cast before
> >
> > upload.parseRequest(request);
> >
> > ?
> 
> Actually no. But this should not work, as ContainerRequest is not 
> implementing HttpServletRequest, right? I have no access to my code from 
> where I am right now, but I will try a simple cast this evening.
> 
> Just to be sure that this is clear. The type of 'request' is 
> com.sun.jersey.spi.container.ContainerRequest -only- when I use
> 
> public Response uploadImage(@Context Request request)
> 
> 

That is correct, however you supposed to do like I wrote in my other
mail:

    @Context
    private HttpServletRequest request;

 ...
request.getRemoteAddr();

As you see you do not need a cast but simply asking for the correct
type. 

@Context HttpServletRequest request in method call should work the same.

HTH

salu2

-- 
Thorsten Scherler <thorsten.at.apache.org>
codeBusters S.L. - web based systems
<consulting, training and solutions>
http://www.codebusters.es/


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to