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 18:58:31 +0200

On Oct 13, 2009, at 4:58 PM, beanor wrote:

>
> 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).

OK. I just re-read the thread. Was the charset issue related to the
file name parameter?

If so it could be an issue with header decoding. I would need to check
how non-ASCII characters are decoded. An simple test case would help
if you have one handy :-)


> 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.
>

We have deprecated the use of @FormParam with multpart/form-data.
Instead one should use @FormDataParam.

   https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataParam.html

And we also switched form using JavaMail to an MIMEPull.

But i dunno if your charset issue is fixed.

Paul.

>
>
> 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.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>