TracEE binding for Java Servlets

tracee-servlet contains Servlet-Listeners and -Filters that allows you to use TracEE Context Propagation with Java Servlets.

  • TraceeServletRequestListener: Parses a TracEE-Context from a ServletHttpRequest-Header before a request is processed by a servlet. It also cleans the TraceeBackend when the request processing is finished by the container.
  • TraceeFilter: Writes a TracEE-Context back to a ServletHttpResponse-Header.
  • TraceeSessionListener: Listens on Session.create() and Session.destroy() events and creates and deletes the tracee-sessionId from the TracEE-Backend accordingly.

Installation

Its super-easy for Servlet3+-Containers. Just add tracee-servlet-VERSION.jar to your webapp-classpath (WEB-INF/lib or as maven runtime dependency). tracee-servlet contains a web-fragment.xml that registers all required filters and event listeners.

If you’re use Maven for your dependency management simple add this to your pom:

<dependencies>
<!-- … -->
    <dependency>
        <groupId>io.tracee.binding</groupId>
        <artifactId>tracee-servlet</artifactId>
        <version>RELEASE</version>
        <scope>runtime</scope>
    </dependency>
<!-- … -->
</dependencies>

If you are on a Servlet-Container with servlet-version < 3, you need to register the following filters in your web.xml:

<!-- … -->
<filter>
    <filter-name>traceeFilter</filter-name>
    <filter-class>io.tracee.binding.servlet.TraceeFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>traceeFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
    <listener-class>io.tracee.binding.servlet.TraceeServletRequestListener</listener-class>
</listener>
<listener>
    <listener-class>io.tracee.binding.servlet.TraceeSessionListener</listener-class>
</listener>
<!-- … -->

You may change the filter-mapping:url-pattern according to your needs.

Spring Boot

If you’re running in an embedded SpringBoot container you’ve to add the ServletListener and Filter to your application configuration:

@Bean
public FilterRegistrationBean traceeFilter() {
    FilterRegistrationBean frb = new FilterRegistrationBean();
    frb.setFilter(new TraceeFilter());
    frb.addUrlPatterns("/*");
    return frb;
}

@Bean
public ServletListenerRegistrationBean traceeServletListener() {
    return new ServletListenerRegistrationBean<TraceeServletRequestListener>(new TraceeServletRequestListener());
}

License

This project is released under the revised BSD License.

Social Links

Imprint

Web-Template based on SOLID by Carlos Alvarez and remixed according to the Creative Commons Attribution 3.0 License.