JasperException not showing in log4j file

I have a site built using Spring and a logging mechanism with Log4J. Everything is written in order, except for errors in the JSP, such as:

org.apache.jasper.JasperException: /views/user/registration_form.jsp (line: 80, column: 107) 

The error appears in the Eclipse console, but not in the default log4j files. Any idea?

Thank you so much!

EDIT : My log4j configuration file:

 # Root logger option log4j.rootLogger=DEBUG, infofile, errorfile, stdout # Log "INFO" messages to a log file log4j.appender.infofile=org.apache.log4j.RollingFileAppender log4j.appender.infofile.File=/Library/apache-tomcat-8.0.9/logs/info.log log4j.appender.infofile.MaxFileSize=1MB log4j.appender.infofile.MaxBackupIndex=1 log4j.appender.infofile.layout=org.apache.log4j.PatternLayout log4j.appender.infofile.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.appender.infofile.threshold=INFO # Log "ERROR" messages to a log file log4j.appender.errorfile=org.apache.log4j.RollingFileAppender log4j.appender.errorfile.File=/Library/apache-tomcat-8.0.9/logs/error.log log4j.appender.errorfile.MaxFileSize=1MB log4j.appender.errorfile.MaxBackupIndex=1 log4j.appender.errorfile.layout=org.apache.log4j.PatternLayout log4j.appender.errorfile.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.appender.errorfile.threshold=ERROR # Log "INFO" messages to the console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.appender.stdout.threshold=INFO log4j.logger.org.springframework.integration.expression.ExpressionUtils=ERROR # Hibernate #log4j.logger.org.hibernate=INFO, hb #log4j.logger.org.hibernate.SQL=DEBUG #log4j.logger.org.hibernate.type=TRACE #log4j.logger.org.hibernate.hql.ast.AST=info #log4j.logger.org.hibernate.tool.hbm2ddl=warn #log4j.logger.org.hibernate.hql=debug #log4j.logger.org.hibernate.cache=info #log4j.logger.org.hibernate.jdbc=debug 

EDIT 2 : more precisely, we can handle any exception in our Spring MVC application, with the exception of those that were selected on the browse page (for example, JasperException).

+7
spring log4j
source share
2 answers

The first thing to try is org.springframework.web.servlet.handler.SimpleMappingExceptionResolver up org.springframework.web.servlet.handler.SimpleMappingExceptionResolver to handle JasperException (or any other kind?). Strange, I could not get it to work (it seems that it is not involved in the stack at all).

Something like that:

 <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" p:defaultErrorView="uncaughtException"> <property name="exceptionMappings"> <props> <prop key=".AccessDeniedException">error403</prop> <prop key=".DataAccessException">error500</prop> <prop key=".NoSuchRequestHandlingMethodException">error404</prop> <prop key=".TypeMismatchException">error404</prop> <prop key=".MissingServletRequestParameterException">error404</prop> <prop key=".TimeoutException">errorTimeout</prop> <prop key=".JasperException">error500</prop> </props> </property> <property name="warnLogCategory" value="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver" /> <property name="defaultStatusCode" value="500" /> </bean> 

If this is not enough, you can always specify your own SimpleMappingExceptionResolver extension.

Now, if this does not work at all (this is not for me), you can provide your own javax.servlet.Filter , and it will certainly work (although it may not be "spring -est").

Something like:

 public class MyExceptionHandlerFilter extends GenericFilterBean { public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws java.io.IOException ,javax.servlet.ServletException { try { chain.doFilter(request, response); } catch (Exception e) { // do something with the exception here... } } 

}

In Spring 3/4 Java Config, you can put this class above in the @Configuration class, for example:

 @Configuration public class MyConfig { ... @Bean public Filter exceptionSink() { return new MyExceptionHandlerFilter(); } ... } 

(There are really a thousand ways to do this in Spring ... as usual). And if you use web.xml , it will look like this:

 <filter> <filter-name>ExceptionHandlerFilter</filter-name> <filter-class>com.test.MyExceptionHandlerFilter</filter-class> </filter> ... <filter-mapping> <filter-name>ExceptionHandlerFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> 

If you can provide stacktrace errors, it can shed light on your filter chain (it will look for any "springframework" classes there) to see if there could be a less verbose / more spring - ish way to go about it. The chain will differ depending on your configuration (for example, you can see some spring-protective filters there if you use it, etc.).

+1
source share

I think JasperExecption is being written to STDERR, so they probably appear in your eclipse console log. Can you see the messages in the catalina.out log file (/logs/catalina.yyyy-mm-dd.out)?

You can try adding the following to the appfile configuration of your errorfile to capture messages in the error log.

 log4j.appender.errorfile.Target=System.err 
0
source share

All Articles