Skip to content

Instrumenting Jersey Containers

WolfgangTheilmann edited this page Mar 31, 2016 · 3 revisions

Introduction

Jersey Container instrumentation is implemented as a combination of a container request filter and a container response filter as defined in the Java API for RESTful Services (JAX-RS), Version 2.0

Enabling the Feature

In order to make this feature available in your application, you need to add the corresponding library to your Maven dependencies in your application's pom.xml like this, assuming that you've also defined a property cf-logging-version that refers to the latest version of this feature:

<!-- We're using the Servlet Filter instrumentation -->
<dependency>
   <groupId>com.sap.hcp.cf.logging</groupId>
   <artifactId>cf-java-logging-support-jersey</artifactId>
   <version>${cf-logging-version}</version>
</dependency>

Enabling the Request/Response Filters

One way to enable the filters is to programmatically as done in the sample application:

public class SampleApp extends Application {
  @Override
  public Set<Class<?>> getClasses() {
    Set<Class<?>> result = new HashSet<Class<?>>();
    result.add(Sample.class);
    result.add(RequestMetricsDynamicBinding.class);
    return result;
  }
}

Here, we add our RequestMetricsDynamicBinding as a provider which, in turn, will register the two filter implementations.