You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ken <ki...@gmail.com> on 2008/04/24 07:44:15 UTC

Is it possible to receive uploaded files from non-tapestry pages?

Hi.

I wrote simple HTML like below

start.html:
<form action="/myapp/upload"
	method="post" enctype="multipart/form-data">
<input type="file"/>
<input type="submit"/>
</form>

and very very simple tapestry codes.

Upload.java:
public class Upload {}

When I press submit button in the HTML file,
following error is occurred.

What I should to do?

Thanks for advice.


[ERROR] RequestExceptionHandler Processing of request failed with
uncaught exception: getReader() or getInputStream() called
java.lang.IllegalStateException: getReader() or getInputStream() called
	at
org.mortbay.jetty.servlet.ServletHttpRequest.setCharacterEncoding(ServletHttpRequest.java:602)
	at com.example.myapp.services.AppModule$1.service(AppModule.java:74)
	at $RequestFilter_1197ee90f59.service($RequestFilter_1197ee90f59.java)
	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
	at
org.apache.tapestry.internal.services.LocalizationFilter.service(LocalizationFilter.java:42)
	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
	at
org.apache.tapestry.services.TapestryModule$3.service(TapestryModule.java:553)
	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
	at
org.apache.tapestry.services.TapestryModule$2.service(TapestryModule.java:520)
	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
	at
org.apache.tapestry.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:79)
	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
	at
org.apache.tapestry.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:93)
	at
org.apache.tapestry.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:84)
	at
org.apache.tapestry.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:77)
	at
org.apache.tapestry.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:106)
	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
	at $RequestHandler_1197ee90f51.service($RequestHandler_1197ee90f51.java)
	at
org.apache.tapestry.services.TapestryModule$12.service(TapestryModule.java:924)
	at
org.apache.tapestry.upload.internal.services.MultipartServletRequestFilter.service(MultipartServletRequestFilter.java:43)
	at
$HttpServletRequestHandler_1197ee90f52.service($HttpServletRequestHandler_1197ee90f52.java)
	at
org.apache.tapestry.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
	at
$HttpServletRequestFilter_1197ee90f50.service($HttpServletRequestFilter_1197ee90f50.java)
	at
$HttpServletRequestHandler_1197ee90f52.service($HttpServletRequestHandler_1197ee90f52.java)
	at
$HttpServletRequestHandler_1197ee90f4e.service($HttpServletRequestHandler_1197ee90f4e.java)
	at org.apache.tapestry.TapestryFilter.doFilter(TapestryFilter.java:168)
	at
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
	at
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
	at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
	at
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
	at
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
	at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
	at
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633)
	at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
	at org.mortbay.http.HttpServer.service(HttpServer.java:909)
	at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
	at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
	at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
	at
org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245)
	at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
	at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] Is it possible to receive uploaded files from non-tapestry pages?

Posted by Ken <ki...@gmail.com>.
Hi, again.

I tried to using servlet for file uploading.

I wrote codes below.
Then selected a file and submitted.

But output is only like this:

  Content-Type: multipart/form-data; boundary=...
  Content-Length: 4699
  Command: FileUpload

No "#####"-s are displayed.

I excuted same code on Tomcat, and its succeeded
(Filnames and parameters were displayed).

Why doesn't it work on Tapestry?

My tapestry is 5.0.11.

I hope your advice.
Thank you.


web.xml:
<servlet>
  <servlet-name>connector</servlet-name>
  <servlet-class>com.example.myapp.servlet.Connector</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>connector</servlet-name>
  <url-pattern>/servlet/connector</url-pattern>
</servlet-mapping>

start.html:
<html>
<body>
<form action="/myapp/servlet/connector?Command=FileUpload"
	method="post" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit"/>
<input type="hidden" name="Type" value="Image"/>
</form>
</body>
</html>

Connector.java:
public void service(
	HttpServletRequest request, HttpServletResponse responce)
	throws ServletException, IOException {
  responce.setContentType("text/html; charset=UTF-8");

  DiskFileItemFactory factory = new DiskFileItemFactory();
  ServletFileUpload upload = new ServletFileUpload(factory);

  factory.setSizeThreshold(1024);
  upload.setSizeMax(MAX_CONTENT_SIZE * 1024);
  upload.setHeaderEncoding("UTF-8");

  PrintWriter out = responce.getWriter();
  try {
    @SuppressWarnings("unchecked")
    List<FileItem> list = upload.parseRequest(request);
    for (FileItem item : list) {
      out.println("#####");
      if (item.isFormField()) {
        out.println(item.getFieldName() + ": ");
        out.println(item.getString(responce.getCharacterEncoding()));
      } else {
        out.println("FileName: " + item.getName());
      }
    }
  } catch (FileUploadException e) {
    e.printStackTrace();
  } catch (IOException e) {
    e.printStackTrace();
  }
  out.println("Content-Type: " + request.getContentType());
  out.println("Content-Length: " + request.getContentLength());
  out.println("Command: " + request.getParameter("Command"));
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Is it possible to receive uploaded files from non-tapestry pages?

Posted by Ken <ki...@gmail.com>.
Hi, Dmitry
Thanks for your advice.

> May be it possible but will be hard to achieve, because T5 (you use T5,
> don't you?) use hidden fields with internal information with every form.
> Without this information form can't be processed.

Yes, I am using 5.0.11.
I should to write so.

> As for your stacktrace:
> You try to change character encoding for request when it is too late for
> this. If you do this as RequestHandler it should be placed first in
> chain. But probably usage of javax.servlet.ServletFilter is more
> appropriated.

After sending my first mail, I found a fault in the
stacktrace which you pointed.

I bothered you.
Sorry about that.

I removed the character encoding filter from my AppModule,
then error was gone.

But I still not reached to my goal.
I will try more.
Maybe I will ask you again in the few days.

Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Is it possible to receive uploaded files from non-tapestry pages?

Posted by Dmitry Shyshkin <sh...@devoler.com>.
Hi, Ken
May be it possible but will be hard to achieve, because T5 (you use T5,
don't you?) use hidden fields with internal information with every form.
Without this information form can't be processed.

As for your stacktrace:
You try to change character encoding for request when it is too late for
this. If you do this as RequestHandler it should be placed first in
chain. But probably usage of javax.servlet.ServletFilter is more
appropriated.

Ken wrote:
> Hi.
>
> I wrote simple HTML like below
>
> start.html:
> <form action="/myapp/upload"
> 	method="post" enctype="multipart/form-data">
> <input type="file"/>
> <input type="submit"/>
> </form>
>
> and very very simple tapestry codes.
>
> Upload.java:
> public class Upload {}
>
> When I press submit button in the HTML file,
> following error is occurred.
>
> What I should to do?
>
> Thanks for advice.
>
>
> [ERROR] RequestExceptionHandler Processing of request failed with
> uncaught exception: getReader() or getInputStream() called
> java.lang.IllegalStateException: getReader() or getInputStream() called
> 	at
> org.mortbay.jetty.servlet.ServletHttpRequest.setCharacterEncoding(ServletHttpRequest.java:602)
> 	at com.example.myapp.services.AppModule$1.service(AppModule.java:74)
> 	at $RequestFilter_1197ee90f59.service($RequestFilter_1197ee90f59.java)
> 	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
> 	at
> org.apache.tapestry.internal.services.LocalizationFilter.service(LocalizationFilter.java:42)
> 	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
> 	at
> org.apache.tapestry.services.TapestryModule$3.service(TapestryModule.java:553)
> 	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
> 	at
> org.apache.tapestry.services.TapestryModule$2.service(TapestryModule.java:520)
> 	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
> 	at
> org.apache.tapestry.internal.services.StaticFilesFilter.service(StaticFilesFilter.java:79)
> 	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
> 	at
> org.apache.tapestry.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:93)
> 	at
> org.apache.tapestry.internal.services.CheckForUpdatesFilter$2.invoke(CheckForUpdatesFilter.java:84)
> 	at
> org.apache.tapestry.ioc.internal.util.ConcurrentBarrier.withRead(ConcurrentBarrier.java:77)
> 	at
> org.apache.tapestry.internal.services.CheckForUpdatesFilter.service(CheckForUpdatesFilter.java:106)
> 	at $RequestHandler_1197ee90f5b.service($RequestHandler_1197ee90f5b.java)
> 	at $RequestHandler_1197ee90f51.service($RequestHandler_1197ee90f51.java)
> 	at
> org.apache.tapestry.services.TapestryModule$12.service(TapestryModule.java:924)
> 	at
> org.apache.tapestry.upload.internal.services.MultipartServletRequestFilter.service(MultipartServletRequestFilter.java:43)
> 	at
> $HttpServletRequestHandler_1197ee90f52.service($HttpServletRequestHandler_1197ee90f52.java)
> 	at
> org.apache.tapestry.internal.services.IgnoredPathsFilter.service(IgnoredPathsFilter.java:62)
> 	at
> $HttpServletRequestFilter_1197ee90f50.service($HttpServletRequestFilter_1197ee90f50.java)
> 	at
> $HttpServletRequestHandler_1197ee90f52.service($HttpServletRequestHandler_1197ee90f52.java)
> 	at
> $HttpServletRequestHandler_1197ee90f4e.service($HttpServletRequestHandler_1197ee90f4e.java)
> 	at org.apache.tapestry.TapestryFilter.doFilter(TapestryFilter.java:168)
> 	at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> 	at
> org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
> 	at
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
> 	at
> org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
> 	at
> org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
> 	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
> 	at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
> 	at
> org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633)
> 	at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
> 	at org.mortbay.http.HttpServer.service(HttpServer.java:909)
> 	at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
> 	at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
> 	at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
> 	at
> org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245)
> 	at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
> 	at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org