users@jersey.java.net

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

From: beanor <beanor_at_gmail.com>
Date: Tue, 13 Oct 2009 07:58:27 -0700 (PDT)

Yes, We want to use apache common upload library.

I remember i had post a
question(http://n2.nabble.com/Upload-a-file-from-form-input-But-hava-got-file-is-bad-td2394319.html#a2394319)

But , in jersey1.0.2, The upload file way, I had found it not working well,
Example:Character encoding problem(chinese support). So, we Choose the
apache common upload. it looks working very well. Although it is not Follow
Rest web service Rule(Content negotiation).

I hope the jersey1.1.3-ea is very good at upload file aspect. If it is a
fact that, have some time, I want to upgrade our framework to a later
version.



Paul Sandoz wrote:
>
>
> 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
>>
>
>
> ---------------------------------------------------------------------
> 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-tp3806324p3816610.html
Sent from the Jersey mailing list archive at Nabble.com.