Am 31.10.2011 11:29, schrieb Andre Juffer:
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(..)'.
I'm sorry, but I'm not familiar with commons-fileupload and not very
familiar with Jersey.
All I can say is that your problem is (probably) not within Cocoon.
Using some rather uncommon Servlet-Container is a good source for
obscure problems, but Jetty is very common and should work fine.
At this time I can only advise you to check the documentation for
commons-fileupload an maybe try to get it working with a very simple
servlet without any Cocoon, Jersey and any other framework at all.
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.
Generics cannot have an effect on this.
At worst you would receive a ClassCastException at runtime, but it
cannot alter the result in any way.
Thanks,
Andre
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]