Skip to content

Commit

Permalink
Merge pull request #1282 from koo-taejin/#1257
Browse files Browse the repository at this point in the history
  • Loading branch information
koo-taejin committed Dec 1, 2015
2 parents ec69773 + 58b6f67 commit a72d5fe
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
@TargetMethod(name = "handle", paramTypes = { "org.eclipse.jetty.server.AbstractHttpConnection" })
public class Jetty8ServerHandleInterceptor extends AbstractServerHandleInterceptor {

private volatile Method getRequestMethod;

public Jetty8ServerHandleInterceptor(TraceContext traceContext, MethodDescriptor descriptor, Filter<String> excludeFilter) {
super(traceContext, descriptor, excludeFilter);
}
Expand All @@ -23,7 +25,7 @@ protected Request getRequest(Object[] args) {
try {
Object object = args[0];

Method getRequestMethod = getMethod(object.getClass(), "getRequest");
Method getRequestMethod = getGetRequestMethod(object.getClass());
Request request = (Request) getRequestMethod.invoke(object);
return request;
} catch (Exception e) {
Expand All @@ -33,24 +35,26 @@ protected Request getRequest(Object[] args) {
return null;
}

private Method getMethod(Class clazz, String methodName) {
Class targetClazz = clazz;
private Method getGetRequestMethod(Class clazz) {
if (getRequestMethod != null) {
return getRequestMethod;
}

synchronized (this) {
if (getRequestMethod != null) {
return getRequestMethod;
}

while (targetClazz != null) {
try {
Method method = targetClazz.getMethod(methodName);
if (method != null) {
return method;
Method findedMethod = clazz.getMethod("getRequest");
if (findedMethod != null) {
getRequestMethod = findedMethod;
return getRequestMethod;
}

} catch (NoSuchMethodException e) {
Class superclass = targetClazz.getSuperclass();
if (superclass != null) {
targetClazz = superclass;
}
logger.warn(e.getMessage(), e);
}
}

return null;
};

Expand Down

0 comments on commit a72d5fe

Please # to comment.