You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Thorsten Scherler <sc...@gmail.com> on 2011/10/31 13:04:02 UTC
Re: [cocoon3] @Context Request request
On Mon, 2011-10-31 at 12:46 +0100, 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
>
> >
> > Right now, I assume
> >
> > @POST
> > public Response uploadImage(@Context HttpServletRequest request) {
> > .....
> > }
> >
> > but I do not believe this is actually correct.
>
> It should.
Actually we have done one service on pure jax-ws and there I found
@Path("/rate/")
@Component
@Scope("request")
public class RatingServlet {
@Context
private HttpServletRequest request;
@POST
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Object addRating(@FormParam("url") String url,
@FormParam("rating") String rating) {
...
// create bean and inject it into the storage
Rating bean = new Rating(url, parseInt, new
Date(),request.getRemoteAddr());
Maybe this way it works better (even it should be the same) but as you
can see we can use request.getRemoteAddr() without problem.
HTH
salu2
--
Thorsten Scherler <thorsten.at.apache.org>
codeBusters S.L. - web based systems
<consulting, training and solutions>
http://www.codebusters.es/