Bug 37466

Summary: c:import doesn't work with HEAD requests
Product: Taglibs Reporter: Eric Haszlakiewicz <erh+apache>
Component: Standard TaglibAssignee: Tomcat Developers Mailing List <dev>
Severity: major    
Priority: P2    
Version: 1.2.1   
Target Milestone: ---   
Hardware: Other   
OS: other   
Bug Depends on: 57601    
Bug Blocks:    
Attachments: A JSP file that will demonstrate the c:import problem.
XML data file to go along with testit.jsp.
Unit test patch to taglibs test system for this bug.
Patch to fix the issue.

Description Eric Haszlakiewicz 2005-11-11 09:03:45 UTC
Attempting to use c:import to read in a file results in no content if the
request sent the the web server is a HEAD instead of a GET.  This causes things
like parsing XML documents to fail, as well as anything else that might depend
on files being read correctly.
I'll attach an example jsp and xml file that demonstrates the problem.
Comment 1 Eric Haszlakiewicz 2005-11-11 09:05:38 UTC
Created attachment 16947 [details]
A JSP file that will demonstrate the c:import problem.
Comment 2 Eric Haszlakiewicz 2005-11-11 09:06:07 UTC
Created attachment 16948 [details]
XML data file to go along with testit.jsp.
Comment 3 Eric Haszlakiewicz 2005-11-11 09:11:38 UTC
To see the problem, copy testit.jsp and testit.xml to a webapp.  Then send a
HEAD request, perhaps like this:

> telnet localhost 8080
Connected to localhost.
Escape character is '^]'.
HEAD /mywebapp/testit.jsp HTTP/1.1
Host: localhost 8080

HTTP/1.1 500 Internal Server Error
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked
Date: Fri, 11 Nov 2005 08:07:55 GMT
Server: Apache-Coyote/1.1
Connection: close

Connection closed by foreign host.

The internal server error is due to x:parse complaining with:
org.xml.sax.SAXParseException: Premature end of file.
Comment 4 Eric Haszlakiewicz 2005-11-11 09:13:10 UTC
d'oh! cut'n'paste error.  The Host: line is missing a colon:
Host: localhost:8080
Comment 5 Bjorn Townsend 2007-01-04 17:28:30 UTC
Created attachment 19364 [details]
Unit test patch to taglibs test system for this bug.
Comment 6 Henri Yandell 2007-01-10 13:13:38 UTC
Problem occurs regardless of whether var=".." or varReader=".." is used in the
Comment 7 Henri Yandell 2007-01-10 14:03:46 UTC
This issue was brought up on tomcat-dev by the original poster, and Bill Barker
suggests a JSTL fix:

Comment 8 Henri Yandell 2007-01-10 14:08:07 UTC
Created attachment 19388 [details]
Patch to fix the issue.
Comment 9 Henri Yandell 2007-01-10 14:09:39 UTC
svn ci -m "Applying Bjorn Townsend's unit test and the fix for #37466 - c:import
doesn't work with HEAD requests. Many thanks to Bill Barker on tomcat-dev for
providing the idea behind the fix. "

Sending        src/org/apache/taglibs/standard/tag/common/core/ImportSupport.java
Adding         test/org/apache/taglibs/standard/tag/ImportTagTest
Adding         test/org/apache/taglibs/standard/tag/ImportTagTest/core
Adding         test/web/org/apache/taglibs/standard/tag/ImportTagTest
Adding         test/web/org/apache/taglibs/standard/tag/ImportTagTest/core
Transmitting file data ....
Committed revision 495005.
Comment 10 Jeremy Boynes 2015-02-18 16:14:39 UTC
The patch in r495005 attempts to address this by wrapping the HttpServletRequest and overriding the getMethod() call to always return GET.

The works on Tomcat when importing a static resource as it causes the DefaultServlet to return content (when the method is HEAD DefaultServlet always returns no content). However, it breaks other servlets that may rely on the method, for example, a servlet that overrides doPost().
Comment 11 Jeremy Boynes 2015-03-02 14:55:39 UTC
Reverted the fix in http://svn.apache.org/r1663321 to be included in Taglibs 1.2.4

The associated change to Tomcat means the patch that addressed this is no longer appropriate. Resolving as INVALID.