Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c:import tag: importing file into var does not work on Tomcat 9 #107

Open
nzall opened this issue Aug 6, 2020 · 0 comments
Open

c:import tag: importing file into var does not work on Tomcat 9 #107

nzall opened this issue Aug 6, 2020 · 0 comments

Comments

@nzall
Copy link

nzall commented Aug 6, 2020

Environment:

  • Tomcat 9.0.25
  • Struts 2.5.22
  • org.classfish.web jakarta.servlet.jsp.jstl 1.2.6.

Steps to reproduce:

Put this in a struts 2 jsp:

<c:set var="xml" value='${phaseLog.log}' />
<c:import url="${phaseLog.formattingData}" var="xslt" charEncoding="UTF-8" />
<table id="xmlLogTable" class="c-error-log-xml u-width-full">
    <x:transform xml="${xml}" xslt="${xslt}" />
</table>

and put this in the action:

phaseLog.log: String contents:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="log.xsl"?>

<build time="0 seconds">
	<task location="E:\webtest_environments\COMMON\CONTBUILD\BUILD\source\752\COMMON\build.xml:3: " name="description" time="0 seconds" />
	<target name="copySourceToTarget" time="0 seconds">
		<task location="E:\webtest_environments\COMMON\CONTBUILD\BUILD\source\752\COMMON\build.xml:14: " name="copy" time="0 seconds">
			<message priority="info"><![CDATA[Copying 5 files to E:\\webtest_environments\COMMON\CONTBUILD\BUILD\target\752]]></message>
		</task>
		<task location="E:\webtest_environments\COMMON\CONTBUILD\BUILD\source\752\COMMON\build.xml:21: " name="fail" time="0 seconds" />
	</target>
	<target name="buildDemo" time="0 seconds" />
</build>

phaseLog.formattingData: String. Should be a relative URL to the below xsl file. Mine referred to /xslt/ant/log.xsl.

log.zip

Expected result:

for the xsl file to properly be imported into the variable.

Actual outcome:

The xsl file is loaded as an empty string, which in turn crashes the x:transform task because it expects an xslt string.

Additional information:

I've done some debugging. What happens is that in a Tomcat 9.0.0 change (apache/tomcat@25462b8), Tomcat now calls flush() on the PrintWriter that is used to return the request data. This in turn bubbles down to the ImportSupportWrapper, where a change 4 years (javaee/jstl-api@e41c5e8) overrides the flush() method to reset the ByteArrayOutputStream, which in turn sets the internal byte counter to 0. This all happens during the RequestDispatcher.include() call in the acquireString() method of ImportSupport. However, due to the way this ImportSupportWrapper is used, the ByteArrayOutputStream is reused after this in the getString() method. This getString() in turn calls the toString() of the ByteArrayOutputStream, which in turn uses the internal byte counter to determine how much needs to be converted to a string. Because this counter has been reset back to 0, it doesn't include any bytes in the response, leading to an empty String being returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant