Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Servlet doPOST() flushed the response, but client could not receive

843842Aug 20 2009 — edited Aug 20 2009
Hi All,
I encountered a weird scenario. The client is using GWT 1.5.3, the server is Tomcat5.5. I am implementing a file upload service. The client use the multipart post protocol and the server side is using apache's fileUpload package.
My client is using plain html file upload form like following:
<form ENCTYPE='multipart/form-data' method='POST' action='/servlet/upload'><INPUT TYPE='file' NAME='mptest'>
	<INPUT TYPE='submit' VALUE='upload'>
</form>
Overall it just works fine except on Mac OS X. On Mac OS X the user can choose an application (For example, iPhoto Library) as a file to upload. Once the upload servlet received the request, it try to parse it using following code:
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
1		PrintWriter out = null;
2		// parse request
3		if ( ServletFileUpload.isMultipartContent(request) ) {
4			try {
5				out = response.getWriter();
6				DiskFileItemFactory factory = new DiskFileItemFactory();
7
8				// Create a new file upload handler
9				ServletFileUpload upload = new ServletFileUpload(factory);
10
11				// Parse the request
12				List /* FileItem */items = upload.parseRequest(request);
13				
14                // ..... some other logic
15
16				// using print instead of println to avoid '\n' being appended
17				out.print(fileName);
18				out.close();
19				out.flush();
20			}
21			catch (Exception e) {
22				log.fatal("[uploadServlet.doPost()] " + e.getMessage());
23                            out.print("UPLOAD_EXCEPTION");
24				out.close();
25				out.flush();
26			}
27		}
inside the debugger, I can see the servlet does throw exception on line 12 and went to line 22. then it went all the way down to line 25.

By using TCPMon I can see the response does send back to the client with the "UPLOAD_EXCEPTION" string inside it. But the client javascript code cannot catch it by all means. Why is that?

I am uisng FireFox as the browser. Is it possible that the FireFox browser did not handle this correctly ?

The safari browser is smart that it zips the iPhoto Library into a zip file and send to the server so there is no such problem.


Thanks for any input.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 17 2009
Added on Aug 20 2009
4 comments
206 views