You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Leonard Afeng <af...@gmail.com> on 2018/08/05 03:13:17 UTC

[Tomcat] Error page not work for 400 error.

 Dear all,

I custom the error page in web.xml as below:

<error-page>
    <error-code>400</error-code>
    <location>/error400.html</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>/error404.html</location>
</error-page>
<error-page>
    <exception-type>java.lang.IllegalArgumentException</exception-type>
    <location>/error404.html</location>
</error-page>

And I added some log action in org.apache.catalina.util.ErrorPageSupport
and found out that in some case the 400 error page not working but the
default error page.

the log action is:

   public ErrorPage find(int statusCode) {
        log.info("before find, the length of statusPages
is:"+statusPages.size());

     log.info("in addErrorPage find by status Code ************ code
is:"+statusCode );
     log.info(Integer.valueOf(statusCode));
     if ( statusPages.get(Integer.valueOf(statusCode)) == null )
     log.info("cannot find for "+statusCode);
     else
     log.info("find:"+statusPages.get(Integer.valueOf(statusCode)).getLocation()
);

          return statusPages.get(Integer.valueOf(statusCode));
    }

the log print out is:

20:02:59.674 INFO [http-nio-8080-exec-1]
org.apache.coyote.http11.Http11Processor.service
Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at
DEBUG level.
 java.lang.IllegalArgumentException: Invalid character found in the request
target. The valid characters are defined in RFC 7230 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(
Http11InputBuffer.java:463)
at org.apache.coyote.http11.Http11Processor.service(
Http11Processor.java:298)
at org.apache.coyote.AbstractProcessorLight.process(
AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(
AbstractProtocol.java:754)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.
doRun(NioEndpoint.java:1385)
at org.apache.tomcat.util.net.SocketProcessorBase.run(
SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(
ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(
ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(
TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

20:02:59.690 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
before find, the length of statusPages is:0
20:02:59.690 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
in addErrorPage find by status Code ************ code is:400
20:02:59.690 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
400
20:02:59.690 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
cannot find for 400
20:02:59.690 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
before find, the length of statusPages is:0
20:02:59.691 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
in addErrorPage find by status Code ************ code is:0
20:02:59.691 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
0
20:02:59.691 INFO [http-nio-8080-exec-1]
org.apache.catalina.util.ErrorPageSupport.find
cannot find for 0
20:02:59.999 INFO [http-nio-8080-exec-2]
org.apache.catalina.util.ErrorPageSupport.find
before find, the length of statusPages is:2
20:03:00.000 INFO [http-nio-8080-exec-2]
org.apache.catalina.util.ErrorPageSupport.find
in addErrorPage find by status Code ************ code is:404
20:03:00.000 INFO [http-nio-8080-exec-2]
org.apache.catalina.util.ErrorPageSupport.find
404
20:03:00.000 INFO [http-nio-8080-exec-2]
org.apache.catalina.util.ErrorPageSupport.find
find:/error404.html

Is it a known bug or I can get some patch for it ? Thanks advanced.

Sincerely

Leo

答复: [Tomcat] Error page not work for 400 error.

Posted by Leonard Afeng <af...@gmail.com>.
Thanks Mark,

1. The web.xml is defind in the {$TOMCAT_HOME} /conf , not in application.
2. I add some walk around code in the ErrorPageSupport.java
3.     public ErrorPage find(int statusCode) {
4.         log.info("before find, the length of statusPages is:"+statusPages.size());    	
5.     	
6.     	log.info("in addErrorPage find by status Code ************ code is:"+statusCode );
7.     	log.info(Integer.valueOf(statusCode));
8.     	if ( statusPages.get(Integer.valueOf(statusCode)) == null )
9.     		log.info("cannot find for "+statusCode);
10.     	else
11.     		log.info("find:"+statusPages.get(Integer.valueOf(statusCode)).getLocation() );
12.     	
13.     	if ( statusCode == 400 ) {
14.     		log.info("%%%%%%%%%% use custom errorpage");
15.     		ErrorPage ep =new ErrorPage();
16.     		ep.setErrorCode(400);
17.     		ep.setLocation("\400.html");
18.     		return ep;
19.     	}else
20.     	     return statusPages.get(Integer.valueOf(statusCode));
21.     }

This code was reached but the return was not worked.

发送自 Windows 10 版邮件应用

发件人: Mark Thomas
发送时间: 2018年8月6日 3:32
收件人: users@tomcat.apache.org
主题: Re: [Tomcat] Error page not work for 400 error.

On 05/08/2018 04:13, Leonard Afeng wrote:
>   Dear all,
> 
> I custom the error page in web.xml as below:

<snip/>

> And I added some log action in org.apache.catalina.util.ErrorPageSupport
> and found out that in some case the 400 error page not working but the
> default error page.

<snip/>

> 20:02:59.674 INFO [http-nio-8080-exec-1]
> org.apache.coyote.http11.Http11Processor.service
> Error parsing HTTP request header

<snip/>

> Is it a known bug 

No.

> or I can get some patch for it ?

No.

What you are asking for is logically impossible.

The request parsing has failed. Therefore Tomcat can't (reliably) 
identify the web application the request should be routed to. Therefore 
you can't have an application error page generate a response.

If you are using 9.0.6 onwards, the ErrorReportValve can be configured 
to return a custom *static* page for any specific error code and/or 
Exception.

Mark

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



Re: [Tomcat] Error page not work for 400 error.

Posted by Mark Thomas <ma...@apache.org>.
On 05/08/2018 04:13, Leonard Afeng wrote:
>   Dear all,
> 
> I custom the error page in web.xml as below:

<snip/>

> And I added some log action in org.apache.catalina.util.ErrorPageSupport
> and found out that in some case the 400 error page not working but the
> default error page.

<snip/>

> 20:02:59.674 INFO [http-nio-8080-exec-1]
> org.apache.coyote.http11.Http11Processor.service
> Error parsing HTTP request header

<snip/>

> Is it a known bug 

No.

> or I can get some patch for it ?

No.

What you are asking for is logically impossible.

The request parsing has failed. Therefore Tomcat can't (reliably) 
identify the web application the request should be routed to. Therefore 
you can't have an application error page generate a response.

If you are using 9.0.6 onwards, the ErrorReportValve can be configured 
to return a custom *static* page for any specific error code and/or 
Exception.

Mark

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