Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Jersey from 1.19.4 to 2.32 #89

Merged
merged 6 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: '0 16 * * 6'

Expand Down
18 changes: 18 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
* MetricTag annotations in the method's parameters
*
* @see MetricTag
* @see javax.ws.rs.Path
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.kill-bill.billing</groupId>
<artifactId>killbill-oss-parent</artifactId>
<version>0.144.39</version>
<version>0.144.44</version>
</parent>
<groupId>org.kill-bill.commons</groupId>
<artifactId>killbill-commons</artifactId>
Expand Down
66 changes: 40 additions & 26 deletions skeleton/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
<artifactId>jackson-jaxrs-base</artifactId>
<optional>true</optional>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.jaxrs</groupId>
Expand Down Expand Up @@ -77,21 +77,6 @@
<artifactId>metrics-guice</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-guice</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
Expand All @@ -102,12 +87,6 @@
<artifactId>metrics-healthchecks</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-jersey</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-servlet</artifactId>
Expand All @@ -119,18 +98,23 @@
<artifactId>metrics-servlets</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
<groupId>org.asynchttpclient</groupId>
Expand All @@ -153,10 +137,40 @@
<artifactId>jetty-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>guice-bridge</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.hk2</groupId>
<artifactId>hk2-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.kill-bill.commons</groupId>
<artifactId>killbill-metrics</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skife.config</groupId>
<artifactId>config-magic</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,35 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;

import javax.inject.Provider;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.glassfish.jersey.spi.ExceptionMappers;
import org.killbill.commons.metrics.MetricTag;

import com.codahale.metrics.MetricRegistry;
import com.sun.jersey.guice.spi.container.servlet.GuiceContainer;
import com.sun.jersey.spi.container.ExceptionMapperContext;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
* A method interceptor which times the execution of the annotated resource method.
*/
public class TimedResourceInterceptor implements MethodInterceptor {

private final Map<String, Map<String, Object>> metricTagsByMethod = new ConcurrentHashMap<String, Map<String, Object>>();
private final Provider<GuiceContainer> jerseyContainer;
private final Provider<MetricRegistry> metricRegistry;
private final ExceptionMappers exceptionMappers;
private final MetricRegistry metricRegistry;
private final String resourcePath;
private final String metricName;
private final String httpMethod;

public TimedResourceInterceptor(final Provider<GuiceContainer> jerseyContainer,
final Provider<MetricRegistry> metricRegistry,
public TimedResourceInterceptor(final ExceptionMappers exceptionMappers,
final MetricRegistry metricRegistry,
final String resourcePath,
final String metricName,
final String httpMethod) {
this.jerseyContainer = jerseyContainer;
this.exceptionMappers = exceptionMappers;
this.metricRegistry = metricRegistry;
this.resourcePath = resourcePath;
this.metricName = metricName;
Expand Down Expand Up @@ -96,8 +94,7 @@ public Object invoke(final MethodInvocation invocation) throws Throwable {
}

private int mapException(final Throwable e) throws Exception {
final ExceptionMapperContext exceptionMapperContext = jerseyContainer.get().getWebApplication().getExceptionMapperContext();
@SuppressWarnings("unchecked") final ExceptionMapper<Throwable> exceptionMapper = exceptionMapperContext.find(e.getClass());
final ExceptionMapper<Throwable> exceptionMapper = (exceptionMappers != null) ? exceptionMappers.findMapping(e) : null;

if (exceptionMapper != null) {
return exceptionMapper.toResponse(e).getStatus();
Expand All @@ -109,7 +106,7 @@ private int mapException(final Throwable e) throws Exception {
private ResourceTimer timer(final MethodInvocation invocation) {
final Map<String, Object> metricTags = metricTags(invocation);

return new ResourceTimer(resourcePath, metricName, httpMethod, metricTags, metricRegistry.get());
return new ResourceTimer(resourcePath, metricName, httpMethod, metricTags, metricRegistry);
}

private Map<String, Object> metricTags(final MethodInvocation invocation) {
Expand Down Expand Up @@ -160,7 +157,7 @@ private static Object getProperty(final Object currentArgument, final String pro
}

try {
final String[] methodNames = {"get" + capitalize(property), "is" + capitalize(property), property };
final String[] methodNames = {"get" + capitalize(property), "is" + capitalize(property), property};
Method propertyMethod = null;
for (final String methodName : methodNames) {
try {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.killbill.commons.skeleton.modules;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;

Expand All @@ -42,24 +41,21 @@ public class BaseServerModule extends ServletModule {
final Map<String, Class<? extends HttpServlet>> jaxrsServlets;
final Map<String, Class<? extends HttpServlet>> jaxrsServletsRegex;
final String jaxrsUriPattern;
final Collection<String> jaxrsResources = new ArrayList<String>();

public BaseServerModule(final Map<String, ArrayList<Entry<Class<? extends Filter>, Map<String, String>>>> filters,
final Map<String, ArrayList<Entry<Class<? extends Filter>, Map<String, String>>>> filtersRegex,
final Map<String, Class<? extends HttpServlet>> servlets,
final Map<String, Class<? extends HttpServlet>> servletsRegex,
final Map<String, Class<? extends HttpServlet>> jaxrsServlets,
final Map<String, Class<? extends HttpServlet>> jaxrsServletsRegex,
final String jaxrsUriPattern,
final Collection<String> jaxrsResources) {
final String jaxrsUriPattern) {
this.filters = filters;
this.filtersRegex = filtersRegex;
this.servlets = servlets;
this.servletsRegex = servletsRegex;
this.jaxrsServlets = jaxrsServlets;
this.jaxrsServletsRegex = jaxrsServletsRegex;
this.jaxrsUriPattern = jaxrsUriPattern;
this.jaxrsResources.addAll(jaxrsResources);
}

@Override
Expand Down
Loading