org.zalando.putittorest.zmon.ZmonRequestInterceptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of put-it-to-rest Show documentation
Show all versions of put-it-to-rest Show documentation
Spring Boot REST Client Auto Configuration
package org.zalando.putittorest.zmon;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.RequestLine;
import org.apache.http.protocol.HttpContext;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.lang.System.currentTimeMillis;
public class ZmonRequestInterceptor implements HttpRequestInterceptor {
@Override
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
try {
context.setAttribute(Timing.ATTRIBUTE, assemble(request));
} catch (final Exception ignored) {
// ignore
}
}
private Timing assemble(final HttpRequest request) throws URISyntaxException {
final RequestLine requestLine = request.getRequestLine();
return new Timing(requestLine.getMethod(), getHost(requestLine), currentTimeMillis());
}
private String getHost(final RequestLine requestLine) throws URISyntaxException {
final URI uri = new URI(requestLine.getUri());
final int port = uri.getPort();
return checkNotNull(uri.getHost()) + (port == -1 ? "" : ":" + port);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy