users@jersey.java.net

Re: [Jersey] I had found a bug for jersey1.0.1

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 13 Oct 2009 15:13:59 +0200

On Oct 13, 2009, at 3:05 PM, beanor wrote:

>
> Hi Paul:
>
> Thanks for you quick reply! If we want to log some thing,and want to
> consumer request entity in the Resource class,

... using HttpServletRequest...

> how do I? we must to achieve
> a servlet filter by myself?
>

Yes, you need to do some buffering at the level of a servlet filter,
or use a logging feature of a web server.

Why are you using HttpServletRequest? are you using a third party
library?

Paul.

>
>
>
>
> Paul Sandoz wrote:
>>
>> Hi,
>>
>> The problem is because Jersey logging is enabled. It will consume the
>> request entity at the level of the HTTP servlet.
>>
>> Thus if your application needs to use HttpServletRequest to consume
>> request entities you cannot use Jersey to log the request (you need
>> to
>> use something else that preserves the request at the servlet layer)
>>
>> Paul.
>>
>> On Oct 12, 2009, at 8:10 AM, beanor wrote:
>>
>>>
>>> Hi Paul:
>>>
>>> We have been using jersey1.0.2,It has been working quite
>>> nice,But
>>> today, I
>>> have got a issue for it.
>>>
>>> Here is my code:
>>>
>>>
>>> 1.web.xml
>>>
>>> <servlet>
>>> <servlet-name>Jersey Web Application</servlet-name>
>>> <servlet-class>
>>> com.sun.jersey.spi.spring.container.servlet.SpringServlet
>>> </servlet-class>
>>>
>>> <init-param>
>>> <param-name>
>>> com.sun.jersey.config.property.packages
>>> </param-name>
>>> <param-value>com.jersey.sample</param-value>
>>> <!--
>>> <param-
>>> value>com.jersey.sample.provider;com.jersey.sample.resources</
>>> param-value>
>>> -->
>>>
>>> <init-param>
>>> <param-name>
>>> com.sun.jersey.spi.container.ContainerRequestFilters
>>> </param-name>
>>> <param-value>
>>> com.sun.jersey.api.container.filter.LoggingFilter;
>>> </param-value>
>>> </init-param>
>>>
>>> <init-param>
>>> <param-name>
>>> com.sun.jersey.spi.container.ContainerResponseFilters
>>> </param-name>
>>> <param-value>
>>> com.sun.jersey.api.container.filter.LoggingFilter;
>>> </param-value>
>>> </init-param>
>>> </init-param>
>>> <load-on-startup>1</load-on-startup>
>>> </servlet>
>>> <servlet-mapping>
>>> <servlet-name>Jersey Web Application</servlet-name>
>>> <url-pattern>/resources/*</url-pattern>
>>> </servlet-mapping>
>>>
>>> 2.UploadFileResource.java
>>>
>>> @Path("/uploadFile")
>>> public class UploadFileResource {
>>>
>>> /**
>>> * httpServletRequest
>>> */
>>> @Context
>>> private HttpServletRequest httpServletRequest;
>>>
>>> /**
>>> * 上传文件
>>> * @throws JSONException
>>> */
>>> @SuppressWarnings("unchecked")
>>> @POST
>>> public Response uploadFile() {
>>>
>>> DiskFileItemFactory factory = new DiskFileItemFactory();
>>> factory.setSizeThreshold(4 * 1024);
>>>
>>> ServletFileUpload upload = new ServletFileUpload(factory);
>>> upload.setSizeMax(10 * 1024 * 1024);
>>>
>>> // FileItem
>>> List<FileItem> fileItemList = null;
>>>
>>> try {
>>> fileItemList = upload.parseRequest(httpServletRequest);
>>> System.out.println("fileItemList size:" +
>>> fileItemList.size());
>>> } catch (FileUploadException e) {
>>> }
>>> return
>>> Response.ok("{success:true}").status(Status.OK).build();
>>> }
>>> }
>>>
>>>
>>> run result: fileItemList size:0
>>>
>>>
>>> uploadFile.jsp:
>>>
>>> <%@ page language="java" contentType="text/html; charset=utf-8"
>>> pageEncoding="utf-8"%>
>>> <html>
>>> <head>
>>> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
>>> <title>Insert title here</title>
>>> </head>
>>> <body>
>>> <h1>"multipart/form-data"</h1>
>>> <form action="/jerseydemo/resources/uploadFile" method="post"
>>> enctype="multipart/form-data">
>>> <input type="file" name="file" />
>>> <input type="submit" name="submit" value="upload" />
>>> </form>
>>> </body>
>>>
>>>
>>> But , I have changed web.xml like this:
>>>
>>>
>>> <servlet>
>>> <servlet-name>Jersey Web Application</servlet-name>
>>> <servlet-class>
>>> com.sun.jersey.spi.spring.container.servlet.SpringServlet
>>> </servlet-class>
>>>
>>> <init-param>
>>> <param-name>
>>> com.sun.jersey.config.property.packages
>>> </param-name>
>>> <param-value>com.jersey.sample</param-value>
>>> <!--
>>> <param-
>>> value>com.jersey.sample.provider;com.jersey.sample.resources</
>>> param-value>
>>> -->
>>> <load-on-startup>1</load-on-startup>
>>> </servlet>
>>> <servlet-mapping>
>>> <servlet-name>Jersey Web Application</servlet-name>
>>> <url-pattern>/resources/*</url-pattern>
>>> </servlet-mapping>
>>>
>>> The UploadFile.java runing result is :fileItemList size:2
>>>
>>> Why ?
>>>
>>> Any help?
>>>
>>>
>>> --
>>> View this message in context:
>>> http://n2.nabble.com/I-had-found-a-bug-for-jersey1-0-1-tp3806324p3806324.html
>>> Sent from the Jersey mailing list archive at Nabble.com.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>
> --
> View this message in context: http://n2.nabble.com/I-had-found-a-bug-for-jersey1-0-1-tp3806324p3815936.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>