Bug 54971 - javax.servlet.http.Part.write(String fileName) is not properly implemented
Summary: javax.servlet.http.Part.write(String fileName) is not properly implemented
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2013-05-15 02:16 UTC by Daniel Koh
Modified: 2013-05-28 14:49 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Koh 2013-05-15 02:16:03 UTC
1. fileName parameter / relative vs absolute
filaName parameter specification in
<1><JSR-000315 Java Servlet 3.0 Final Release javadocs>
is different from the <2><javax API tomcat refers to>.

<1> <JSR-000315 Java Servlet 3.0 Final Release javadocs>

Parameters:fileName - the name of the file to which the stream will be written. The file is created relative to the location as specified in the MultipartConfig

<2> javax. API tomcat refers to

 * @param fileName  The location into which the uploaded part should be
     *                  stored. Relative locations are relative to {@link
     *                  javax.servlet.MultipartConfigElement#getLocation()}

Tomcat is implemented as specified in <2> so that it can process "absolute path",
but it should only accept "relative path" as specified in <1>
<JSR-000315 Java Servlet 3.0 Final Release javadocs>

If MultiPartConfig.location is not set,
write( String relative path ) throws FileNotFound Exception.
A default location needs to be set in order to avoid such exception.

example) os: windows8


java.io.IOException: java.io.FileNotFoundException: \test (Access is denied)
	at org.apache.catalina.core.ApplicationPart.write(ApplicationPart.java:123)
	at servlet.multipart.MultipleUploadServlet.doPost(MultipleUploadServlet.java:76)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
	at java.lang.Thread.run(Thread.java:662)
Comment 2 Eugene Chung (TmaxSoft) 2013-05-15 05:19:49 UTC
For the problem 2, the default location of MultipartConfig is avax.servlet.context.tempdir as defined by 8.1.5
Comment 3 Mark Thomas 2013-05-15 11:02:40 UTC
(In reply to comment #0)
> 1. fileName parameter / relative vs absolute

Tomcat is implementing a container specific extension that allows absolute paths to be specified. I thought that there had been some discussion of this previously but I can't find anything in the archives.

Any specification compliant input (i.e. a relative path) will work so nothing is broken w.r.t. to the spec here.
Comment 4 Mark Thomas 2013-05-15 11:09:49 UTC
(In reply to comment #2)
> For the problem 2, the default location of MultipartConfig is
> avax.servlet.context.tempdir as defined by 8.1.5
> @MultipartConfig.

Agreed. Tomcat applies that default elsewhere but it is missing in this case. Tomcat also handles relative locations by making them relative to javax.servlet.context.tempdir

I'll see about getting this fixed.
Comment 5 Mark Thomas 2013-05-28 14:49:08 UTC
This has been fixed in trunk and 7.0.x and will be included in 7.0.41 onwards.