Steven,

thanks for the reply.

The purpose of the request is to upload an image file. With commons fileupload this is straightforward, but it requires direct access to HttpServletRequest. I did understand that HttpServletRequest is an interface of course.

With commons fileupload, one would do something like

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> items = upload.parseRequest(request);

Here, 'request' must be (an implementation of) HttpServletRequest. One of 'items' would contain the image.

If I use

public Response uploadImage(@Context Request request)

the type of 'request' is com.sun.jersey.spi.container.ContainerRequest, which will not work with 'upload.parseRequest(request)' above. The ContainerRequest does not implement HttpServletRequest. Following your email, one should see for 'request' a HttpServletRequest? I would agree with this, given the statement at the jersey website "When deploying a JAX-RS application using servlet then ServletConfig, ServletContext, HttpServletRequest and HttpServletResponse are available using @Context.".

With

public Response uploadImage(@Context HttpServletRequest request)

the type of request is some proxy (this is the name of an implementing class, something like $Proxy38).

In any case, i -did- use public Response uploadImage(@Context HttpServletRequest request) and noticed that the request is empty (that is, the List<FileItem> above is empty). That is, no image file is available, although it was sent correctly (checked with Firebug).

So, my conclusion was that something is not working correctly and that's why I was wondering about the type of request. The POST request on the client was something like

http://localhost:8888/eap/rest/image

with jetty as the servlet engine. I cannot be sure what happens in between sending the request and the handling by 'ImageResource.uploadImage(..)'.


One thing, though (just occurred to me while preparing this email): I did use

List<FileItem> items = upload.parseRequest(request);

which possibly should be

List items = upload.parseRequest(request);

(so no generics). The version of fileupload I use is 1.2.1 (if I correctly remember), but I will look into this this evening.

Thanks,
Andre



On 10/31/2011 11:44 AM, Steven Dolg wrote:
Am 30.10.2011 18:35, schrieb Andre Juffer:
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?

Right now, I assume

@POST
public Response uploadImage(@Context HttpServletRequest request) {
.....
}

but I do not believe this is actually correct.

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.

Hi André,

the code fragment you posted appears to be correct and conform with Jersey - the JAX-RS implementation used by Cocoon 3.

If you receive a value in the parameter request, then it will be of type HttpServletRequest. The JVM won't allow anything else. Of course you receive an actual implementation, since HttpServletRequest is only an interface.

So the question is:
What do you want to do with the request and why do you believe it is not working correctly?

Cheers,
Steven


Thanks,
André


[1] http://commons.apache.org/fileupload/index.html
[2] http://cocoon.apache.org/3.0/reference/html/webapps.html
[3] http://jsr311.java.net/nonav/releases/1.1/javax/ws/rs/core/Context.html
[4] http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e524




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



--
Andre H. Juffer              | Phone: +358-8-553 1161
Biocenter Oulu and           | Fax: +358-8-553-1141
Department of Biochemistry   | Email: [email protected]
University of Oulu, Finland  | WWW: www.biochem.oulu.fi/Biocomputing/
StrucBioCat                  | WWW: www.strucbiocat.oulu.fi
Triacle Biocomputing         | WWW: www.triacle-bc.com


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

Reply via email to