com.github.zhengframework.rest.metrics.ResponseMeteredInterceptor Maven / Gradle / Ivy
package com.github.zhengframework.rest.metrics;
import com.codahale.metrics.Meter;
import java.io.IOException;
import java.util.List;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
public class ResponseMeteredInterceptor implements ContainerResponseFilter {
private final List meters;
public ResponseMeteredInterceptor(List meters) {
this.meters = meters;
}
@Override
public void filter(ContainerRequestContext requestContext,
ContainerResponseContext responseContext) throws IOException {
final int responseStatus = responseContext.getStatus() / 100;
if (responseStatus >= 1 && responseStatus <= 5) {
meters.get(responseStatus - 1).mark();
}
}
}