java - Using UncaughtExceptionHandler in Struts Application -


i have web application based on struts 2 mvc. had configure proper logging in application did , working fine.

what want is, need runtime exceptions , error due system failure (such lost database connection, third party service down etc etc), logged in application log file.

i read thread.uncaughtexceptionhandler , gone through this answer still unable start requirement.

can suggest me how initiate this? classes make? configure? etc etc. tell, there no multithreading involved in application.

thank you!

below log4j.properties

log4j.appender.file=org.apache.log4j.rollingfileappender log4j.appender.file.file=${catalina.home}/logs/backlogapp.log log4j.appender.file.maxfilesize=1000kb log4j.appender.file.maxbackupindex=1 log4j.appender.file.layout=org.apache.log4j.patternlayout log4j.appender.file.layout.conversionpattern=%d{yyyy-mm-dd hh:mm:ss} %-4p %m%n log4j.appender.datepattern='.'yyyy-mm-dd  # root logger option log4j.rootlogger=warn, file log4j.logger.com.nagarro=warn  # off hibernate , spring log4j.logger.org.hibernate=off log4j.logger.org.springframework=off  # off jdbc parameters log4j.logger.org.hibernate.type=off 

also, global exception handler in struts.xml

<global-results>         <result name="error">/jsp/errorpage.jsp</result>         <result name="sessionexpired">/jsp/login.jsp</result>     </global-results>      <global-exception-mappings>         <exception-mapping exception="java.lang.exception"             result="error" />         <exception-mapping exception="javax.persistence.persistenceexception"             result="error" />     </global-exception-mappings> 

this should happen automatically; how configuring logging?

the existing "exception" interceptor can this, although intended more way implement "go page if exception occurs".

you use same idea , write thin interceptor around action invocation only logs relevant exception information , continues on action's original result name, seems little wonky, since rte should interrupt normal flow.

imo if you're wrapping functionality might throw rte then:

  • that functionality should live in service, and...
  • ...that service should catch exceptions , wrap them in app-specific exception, and...
  • ...then can use existing "exception" interceptor.

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -