Struts Testing, Debugging, Logging, Performance

Document Sample
Struts Testing, Debugging, Logging, Performance Powered By Docstoc
					12/02/2003

Testing, Debugging, Logging, Performance tuning Struts Applications
1

12/02/2003

Sang Shin
sang.shin@sun.com www.javapassion.com Java ™ Technology Evangelist Sun Microsystems, Inc.

2

12/02/2003

Disclaimer & Acknowledgments
?

?

?

Even though Sang Shin is a full-time employees of Sun Microsystems, the contents here are created as their own personal endeavor and thus does not reflect any official stance of Sun Microsystems. Sun Microsystems is not responsible for any inaccuracies in the contents. Acknowledgments:
– –

Struts' user's guide is also used in creating some slides and speaker notes I also used “Programming Jakarta Struts” book written by Chuck Cavaness

3

12/02/2003

Revision History
? ?

12/01/2003: version 1: created by Sang Shin Things to do – Contents on unit testing, best practice guidelines, performance tunning, logging still need to be added

4

12/02/2003

Topics
? ? ? ?

Logging Unit testing and debugging Performance tuning Best practice guidelines

5

12/02/2003

Logging

6

12/02/2003

Logging Schemes for Web Applications
? ?

Using log() method of ServletConext object Jakarta commons logging

7

12/02/2003

Log() method of ServletContext
?

?

?

Every container has to support this method of logging Name and location of the log file is container specific ServletContext class has two log() methods
– –

public void log (String msg); public void log (String msg, Throwable throwable);
8

12/02/2003

What is Jakarta Commons Logging?
?

Provides common logging API
–

API has no dependency to any logging implementations

?

Insulates applications from actual logging implementations
–

Applications do not have to change when logging implementation is changed

?

Developers declaratively configure logging implementation
–

Logging implementation is dynamically discovered at runtime

9

12/02/2003

Possible Logging Implementations
? ? ? ?

log4j JDK 1.4 logging LogKit SimpleLog
– –

available with Struts distribution writes log messages to stdout and stderr available with Struts distribution log messages are ignored
10

?

NoOpLog
– –

12/02/2003

Example: How to Use Logging API?
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public final class EditSubscriptionAction extends Action { private Log log = LogFactory.getLog("org.apache.struts.webapp.Example"); public ActionForward execute(ActionMapping mapping, ..) throw Exception{ .... if (log.isDebugEnabled()) { log.debug("EditSubscriptionAction: Processing " + action + " action"); } .... if (user == null) { if (log.isTraceEnabled()) { log.trace(" User is not logged on in session " + session.getId()); } return (mapping.findForward("logon")); 11 }

12/02/2003

Example: How to Use Logging API?
import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public final class EditSubscriptionAction extends Action { private Log log = LogFactory.getLog("org.apache.struts.webapp.Example"); public ActionForward execute(ActionMapping mapping, ..) throw Exception{ .... if (log.isDebugEnabled()) { log.debug("EditSubscriptionAction: Processing " + action + " action"); } .... if (user == null) { if (log.isTraceEnabled()) { log.trace(" User is not logged on in session " + session.getId()); } return (mapping.findForward("logon")); 12 }

12/02/2003

Example2: init() method of MemoryDatabasePlugin in struts-example1
public final class MemoryDatabasePlugIn implements PlugIn { ... /** * Initialize and load our initial database from persistent storage. * * @param servlet The ActionServlet for this web application * @param config The ApplicationConfig for our owning module * * @exception ServletException if we cannot configure ourselves correctly */ public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { log.info("Initializing memory database plug in from '" + pathname + "'"); // Remember our associated configuration and servlet this.config = config; this.servlet = servlet; 13

12/02/2003

Example2: init() method of MemoryDatabasePlugin in struts-example1

14

12/02/2003

<jwsdp-install>/logs/launcher.server.log

15

12/02/2003

Things still need to be added
? ? ?

log4j configuration Usage of log4j JDK 1.4 configuration

16

12/02/2003

Unit Testing

17

12/02/2003

Unit Testing Tools
?

JUnit
– –

For testing JavaBeans http://www.junit.org For testing JSP, taglibs and conventional servlet components http://jakarta.apache.org/cactus/ For testing Action servlets http://strutstestcase.sourceforge.net
18

?

Cactus
– –

?

StrutsTestCase
– –

12/02/2003

How to Unit Test Struts App?
?

?

Add all unit tests to the build script as a separate target The target should use the junit tag to launch each TestCase descendent

19

12/02/2003

Performance Tuning
20

12/02/2003

Things still need to be added
?

Performance issues of Struts applications

21

12/02/2003

Things still need to be added
? ? ?

JUnit Cactus StrutsTestCase

22

12/02/2003

Best Practice Guidelines
23

12/02/2003

Things still need to be added
?

Best practice guidelines of Struts applications

24

12/02/2003

Live your life with Passion!
25


				
DOCUMENT INFO
Shared By:
Stats:
views:255
posted:9/20/2009
language:English
pages:25
Description: ? Logging ? Unit testing and debugging ? Performance tuning ? Best practice guidelines
Vinothkumar Vinothkumar Engineer
About