You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by David Wall <d....@computer.org> on 2011/06/24 03:12:39 UTC

TC 7.0.16 IllegalStateException thrown by pageContext.include

This was working under TC 6, but I have a tag that extends 
BodyTagSupport, and in my doStartTag() method I get my JspWRiter 'out' 
using pageContext.getOut().

I have a bunch of out.write("") statements that all work fine.

Then I have these:

out.write("<style type=\"text/css\">\n/* platform esf.css */\n");
pageContext.include("/static/esf/esf.css",true);
pageContext.include(docPage.context.getDocumentStyleIncludeUrl(),true);
out.write("</style>\n");

out.write("<script type=\"text/javascript\">\n");
pageContext.include("/static/esf/esf.js",true);
out.write("</script>\n");

But the exception IllegalStateException is thrown on the include of the 
esf.js file.  The reason is null, so there's no more details.  I find it 
odd in that the two prior includes works okay, but that third one 
fails.  The file is definitely there (and has been working under TC 6.0 
before).

If I comment out that include, my tag works fine.  What might be causing 
this?

Thanks,
David


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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by Rainer Jung <ra...@kippdata.de>.
On 24.06.2011 03:47, David Wall wrote:
> 
>>
>>> out.write("<script type=\"text/javascript\">\n");
>>> pageContext.include("/static/esf/esf.js",true);
>>> out.write("</script>\n");
>>>
>>> But the exception IllegalStateException is thrown on the include of
>>> the esf.js file.  The reason is null, so there's no more details.  I
>>> find it odd in that the two prior includes works okay, but that third
>>> one fails.  The file is definitely there (and has been working under
>>> TC 6.0 before).
>>
>> When I change the code to use /static/esf/esf.javascript and rename
>> the file to have the same suffix, the exception is not thrown.
>>
>> Is there anything special about the .js suffix on a file for
>> pageContext.include()?
> 
> Okay, I learned that this is because web.xml for TC 6 uses:
> 
> <mime-mapping>
> <extension>js</extension>
> <mime-type>text/javascript</mime-type>
> </mime-mapping>
> 
> But TC 7 uses:
> 
> <mime-mapping>
> <extension>js</extension>
> <mime-type>application/javascript</mime-type>
> </mime-mapping>
> 
> If I put the old TC 6 version in my app's web.xml, then it works again.
> 
> Question: Is this to be expected?  Is TC 7 doing the "right thing"
> here?  Am I breaking something when I update my app's web.xml to say
> it's 'text' again?
> 
> Seems like javascript is really text, and so treating as something else
> is not correct, even if the mime type is correctly supposed to be
> application/javascript.  Maybe TC needs to "know" this particular mime
> type is text and not binary data?

We synced all mime types with the definitions from the Apache Web
Server. Looking at the IANA MIME type registry

http://www.iana.org/assignments/media-types/index.html

you can verify, that they list text/javascript as "obsolete" and
application/javascript without restriction. So from a standards point of
view it is the "right" thing, maybe not for usability?

Regards,

Rainer

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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by Konstantin Kolinko <kn...@gmail.com>.
2011/6/24 David Wall <d....@computer.org>:
>
>>
>>> out.write("<script type=\"text/javascript\">\n");
>>> pageContext.include("/static/esf/esf.js",true);
>>> out.write("</script>\n");
>>>
>>> But the exception IllegalStateException is thrown on the include of the
>>> esf.js file.  The reason is null, so there's no more details.  I find it odd
>>> in that the two prior includes works okay, but that third one fails.  The
>>> file is definitely there (and has been working under TC 6.0 before).
>>
>> When I change the code to use /static/esf/esf.javascript and rename the
>> file to have the same suffix, the exception is not thrown.
>>
>> Is there anything special about the .js suffix on a file for
>> pageContext.include()?
>
> Okay, I learned that this is because web.xml for TC 6 uses:
>
> <mime-mapping>
> <extension>js</extension>
> <mime-type>text/javascript</mime-type>
> </mime-mapping>
>
> But TC 7 uses:
>
> <mime-mapping>
> <extension>js</extension>
> <mime-type>application/javascript</mime-type>
> </mime-mapping>
>
> If I put the old TC 6 version in my app's web.xml, then it works again.
>

Is there stacktrace for the IllegalStateException that you were observing?


> Question: Is this to be expected?  Is TC 7 doing the "right thing" here?  Am
> I breaking something when I update my app's web.xml to say it's 'text'
> again?

I think (without further looking) that the problem is the following:

The static file (the .js) is served by DefaultServlet.  For
DefaultServlet the data are opaque, so it should be served using an
OutputStream.

In your case, 'out' is a Writer. Trying to open OutputStream after a
Writer has been opened is not allowed.


IIRC, there was some workaround in DefaultServlet for the mime types
that are text/*. I wonder maybe that can be made to work in your case.

The underlying problem though is that to include data from the file
into the writer, one has to convert bytes -> chars,  and for that one
has to know the textual encoding of the file.

Where one can get the encoding?

Best regards,
Konstantin Kolinko

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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by David Wall <d....@computer.org>.
>
>> out.write("<script type=\"text/javascript\">\n");
>> pageContext.include("/static/esf/esf.js",true);
>> out.write("</script>\n");
>>
>> But the exception IllegalStateException is thrown on the include of 
>> the esf.js file.  The reason is null, so there's no more details.  I 
>> find it odd in that the two prior includes works okay, but that third 
>> one fails.  The file is definitely there (and has been working under 
>> TC 6.0 before).
>
> When I change the code to use /static/esf/esf.javascript and rename 
> the file to have the same suffix, the exception is not thrown.
>
> Is there anything special about the .js suffix on a file for 
> pageContext.include()?

Okay, I learned that this is because web.xml for TC 6 uses:

<mime-mapping>
<extension>js</extension>
<mime-type>text/javascript</mime-type>
</mime-mapping>

But TC 7 uses:

<mime-mapping>
<extension>js</extension>
<mime-type>application/javascript</mime-type>
</mime-mapping>

If I put the old TC 6 version in my app's web.xml, then it works again.

Question: Is this to be expected?  Is TC 7 doing the "right thing" 
here?  Am I breaking something when I update my app's web.xml to say 
it's 'text' again?

Seems like javascript is really text, and so treating as something else 
is not correct, even if the mime type is correctly supposed to be 
application/javascript.  Maybe TC needs to "know" this particular mime 
type is text and not binary data?

David


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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by David Wall <d....@computer.org>.
> out.write("<script type=\"text/javascript\">\n");
> pageContext.include("/static/esf/esf.js",true);
> out.write("</script>\n");
>
> But the exception IllegalStateException is thrown on the include of 
> the esf.js file.  The reason is null, so there's no more details.  I 
> find it odd in that the two prior includes works okay, but that third 
> one fails.  The file is definitely there (and has been working under 
> TC 6.0 before).

When I change the code to use /static/esf/esf.javascript and rename the 
file to have the same suffix, the exception is not thrown.

Is there anything special about the .js suffix on a file for 
pageContext.include()?



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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by Rainer Jung <ra...@kippdata.de>.
On 24.06.2011 18:42, David Wall wrote:
> 
> 
> On 6/24/2011 5:48 AM, Rainer Jung wrote:
>> On 24.06.2011 14:08, Tim Funk wrote:Looks like this is the root cause
>> from DefaultServlet ...
>>> While the ISE is caught ... since the mimetype for js was changed - it
>>> doesn't match the fallback method ....
>>>
>>>              try {
>>>                  ostream = response.getOutputStream();
>>>              } catch (IllegalStateException e) {
>>>                  // If it fails, we try to get a Writer instead if we're
>>>                  // trying to serve a text file
>>>                  if ( (contentType == null)
>>>                          || (contentType.startsWith("text"))
>>>                          || (contentType.endsWith("xml")) ) {
>>>                      writer = response.getWriter();
>>>                      // Cannot reliably serve partial content with a
>>> Writer
>>>                      ranges = FULL;
>>>                  } else {
>>>                      throw e;
>>>                  }
>>>              }
>>>
>>> So one patch is this (which will catch all javascript variants if
>>> multiple
>>> exist)
>>>                  if ( (contentType == null)
>>>                          || (contentType.startsWith("text"))
>>>                          || (contentType.endsWith("xml"))
>>> +                        || (contentType.contains("/javascript")) ) {
>> Patch applied and credited to you in r1139280.
>>
>> Thanks!
>>
>> Rainer
> 
> Thanks you all for fixing this.  I think that makes good sense that TC
> 7's DefaultServlet recognize javascript as a text type like 'text' and
> 'xml'.

Are you able to apply the patch, recompile Tomcat and check, whether the
patch actually fixes your problem? Feedback welcome!

Regards,

Rainer

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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by David Wall <d....@computer.org>.

On 6/24/2011 5:48 AM, Rainer Jung wrote:
> On 24.06.2011 14:08, Tim Funk wrote:Looks like this is the root cause from DefaultServlet ...
>> While the ISE is caught ... since the mimetype for js was changed - it
>> doesn't match the fallback method ....
>>
>>              try {
>>                  ostream = response.getOutputStream();
>>              } catch (IllegalStateException e) {
>>                  // If it fails, we try to get a Writer instead if we're
>>                  // trying to serve a text file
>>                  if ( (contentType == null)
>>                          || (contentType.startsWith("text"))
>>                          || (contentType.endsWith("xml")) ) {
>>                      writer = response.getWriter();
>>                      // Cannot reliably serve partial content with a Writer
>>                      ranges = FULL;
>>                  } else {
>>                      throw e;
>>                  }
>>              }
>>
>> So one patch is this (which will catch all javascript variants if multiple
>> exist)
>>                  if ( (contentType == null)
>>                          || (contentType.startsWith("text"))
>>                          || (contentType.endsWith("xml"))
>> +                        || (contentType.contains("/javascript")) ) {
> Patch applied and credited to you in r1139280.
>
> Thanks!
>
> Rainer

Thanks you all for fixing this.  I think that makes good sense that TC 
7's DefaultServlet recognize javascript as a text type like 'text' and 
'xml'.

David


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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by Rainer Jung <ra...@kippdata.de>.
On 24.06.2011 14:08, Tim Funk wrote:
> Looks like this is the root cause from DefaultServlet ...
> 
> While the ISE is caught ... since the mimetype for js was changed - it
> doesn't match the fallback method ....
> 
>             try {
>                 ostream = response.getOutputStream();
>             } catch (IllegalStateException e) {
>                 // If it fails, we try to get a Writer instead if we're
>                 // trying to serve a text file
>                 if ( (contentType == null)
>                         || (contentType.startsWith("text"))
>                         || (contentType.endsWith("xml")) ) {
>                     writer = response.getWriter();
>                     // Cannot reliably serve partial content with a Writer
>                     ranges = FULL;
>                 } else {
>                     throw e;
>                 }
>             }
> 
> So one patch is this (which will catch all javascript variants if multiple
> exist)
>                 if ( (contentType == null)
>                         || (contentType.startsWith("text"))
>                         || (contentType.endsWith("xml"))
> +                        || (contentType.contains("/javascript")) ) {

Patch applied and credited to you in r1139280.

Thanks!

Rainer

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


Re: TC 7.0.16 IllegalStateException thrown by pageContext.include

Posted by Tim Funk <fu...@apache.org>.
Looks like this is the root cause from DefaultServlet ...

While the ISE is caught ... since the mimetype for js was changed - it
doesn't match the fallback method ....

            try {
                ostream = response.getOutputStream();
            } catch (IllegalStateException e) {
                // If it fails, we try to get a Writer instead if we're
                // trying to serve a text file
                if ( (contentType == null)
                        || (contentType.startsWith("text"))
                        || (contentType.endsWith("xml")) ) {
                    writer = response.getWriter();
                    // Cannot reliably serve partial content with a Writer
                    ranges = FULL;
                } else {
                    throw e;
                }
            }

So one patch is this (which will catch all javascript variants if multiple
exist)
                if ( (contentType == null)
                        || (contentType.startsWith("text"))
                        || (contentType.endsWith("xml"))
+                        || (contentType.contains("/javascript")) ) {


-Tim

On Thu, Jun 23, 2011 at 9:12 PM, David Wall <d....@computer.org> wrote:

> This was working under TC 6, but I have a tag that extends BodyTagSupport,
> and in my doStartTag() method I get my JspWRiter 'out' using
> pageContext.getOut().
>
> I have a bunch of out.write("") statements that all work fine.
>
> Then I have these:
>
> out.write("<style type=\"text/css\">\n/* platform esf.css */\n");
> pageContext.include("/static/**esf/esf.css",true);
> pageContext.include(docPage.**context.**getDocumentStyleIncludeUrl(),**
> true);
> out.write("</style>\n");
>
> out.write("<script type=\"text/javascript\">\n");
> pageContext.include("/static/**esf/esf.js",true);
> out.write("</script>\n");
>
> But the exception IllegalStateException is thrown on the include of the
> esf.js file.  The reason is null, so there's no more details.  I find it odd
> in that the two prior includes works okay, but that third one fails.  The
> file is definitely there (and has been working under TC 6.0 before).
>
> If I comment out that include, my tag works fine.  What might be causing
> this?
>
> Thanks,
> David
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.**apache.org<us...@tomcat.apache.org>
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>