.. _tutorial-servlet-example: Java Servlet Container Example ============================== Using the sample Java web application MyBatis `JPetStore ` this example demonstrates how to employ Kieker for monitoring a Java application running in a Java Servlet container -- in this case `Jetty `. Monitoring probes based on the Java Servlet API, Spring and AspectJ are used to monitor execution, trace, and session data (see also instrumenting-software-aspectj_). Prerequisites ------------- - Download and extract the `**Kieker** binary distribution ` - The directory ``kieker-1.14/examples/JavaEEServletContainerExample`` contains the prepared Jetty server with the MyBatis JPetStore application and the **Kieker**-based demo analysis application known from the `Kieker Homepage `. - Switch to this directory or copy it to a suitable location. Instrumenting Servlets ---------------------- The subdirectory ``jetty`` includes the Jetty server with the JPetStore application already deployed to the server's ``webapps/`` directory. The example is prepared to use two alternative types of **Kieker** probes: either the **Kieker** Spring interceptor (default) or the **Kieker** AspectJ aspects. Both alternatives additionally use **Kieker**'s Servlet filter. Required Libraries and Kieker Monitoring Configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Both settings require the files ``aspectjweaver-1.8.2.jar`` and ``kieker-1.14``, which are already included in the webapps's ``WEB-INF/lib/`` directory. Also, a **Kieker** configuration file is already included in the Jetty's root directory, where it is considered for configuration by Kieker Monitoring in both modes. Servlet Filter (Default) ~~~~~~~~~~~~~~~~~~~~~~~~ The file ``web.xml`` is located in the webapps's ``WEB-INF/`` directory. **Kieker**'s Servlet filters are already enabled: .. code-block:: XML sessionAndTraceRegistrationFilter kieker.monitoring.probe.servlet.SessionAndTraceRegistrationFilter logFilterExecution true sessionAndTraceRegistrationFilter /* This filter can be used with both the Spring-based and the AspectJ-based instrumentation mode. Spring-based Instrumentation (Default) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ **Kieker**'s Spring interceptor are already enabled in the file ``applicationContext.xml``, located in the webapps's ``WEB-INF/`` directory: .. code-block:: XML .. note:: When using, for example, the ``@Autowired`` feature in your Spring beans, it can be necessary to force the usage of CGLIB proxy objects with ````. AspectJ-based Instrumentation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In order to use AspectJ-based instrumentation, the following changes need to be performed. The file ``start.ini``, located in Jetty's root directory, allows to pass various JVM arguments, JVM system properties, and other options to the server on startup. When using AspectJ for instrumentation, the respective JVM argument needs to be activated in this file. The AspectJ configuration file ``aop.xml`` is already located in the webapps's ``WEB-INF/classes/META-INF/`` directory and configured to instrument the JPetStore classes with **Kieker**'s **OperationExecutionAspectFull** aspect. When using the AspectJ-based instrumentation, make sure to disable the Spring interceptor in the file ``applicationContext.xml``, mentioned above. #. Start the Jetty server using the ``start.jar`` file (e.g., via ``java -jar start.jar``). You should make sure that the server started properly by taking a look at the console output that appears during server startup. #. Now, you can access the JPetStore application by opening the URL http://localhost:8080/jpetstore/. **Kieker** initialization messages should appear in the console output. .. image:: ../images/jpetstore-example-FFscrsh.png :width: 500px #. Browse through the application to generate some monitoring data. #. In this example, **Kieker** is configured to write the monitoring data to JMX in order to communicate with the **Kieker**-based demo analysis application, which is accessible via /`` directory) located in the default temporary directory. This data can be analyzed and visualized using kieker-tools-trace-analysis-tool_.