Change Router to do reflective setAccessible() calls itself

This change moves the reflective setAccessible() calls on the request component
methods (needed so that they can be invoked reflectively from RequestHandler)
to within Router itself, eliminating the need to manually call this from each
Servlet class and then pass in the resulting Method objects.  Instead, we just
pass in the request component class and let Router do the rest.

Old comments say that cross-package reflection is not allowed on AppEngine, but
while it's quite possible this was once the case, I can't reproduce that
limitation, and the documentation seems to contradict any such restriction:

"""
An application is allowed full, unrestricted, reflective access to its own
classes.  It can query any private members, call the method
java.lang.reflect.AccessibleObject.setAccessible(), and read/set private
members.
"""
https://cloud.google.com/appengine/docs/java/runtime#reflection

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=138693006
This commit is contained in:
nickfelt 2016-11-09 15:23:47 -08:00 committed by Ben McIlwain
parent 59c213c66f
commit 9122372e38
7 changed files with 34 additions and 87 deletions

View file

@ -14,14 +14,9 @@
package google.registry.module.tools;
import static java.util.Arrays.asList;
import com.google.common.base.Function;
import com.google.common.collect.FluentIterable;
import google.registry.request.RequestHandler;
import google.registry.request.RequestModule;
import java.io.IOException;
import java.lang.reflect.Method;
import java.security.Security;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -34,14 +29,7 @@ public final class ToolsServlet extends HttpServlet {
private static final ToolsComponent component = DaggerToolsComponent.create();
private static final RequestHandler<ToolsRequestComponent> requestHandler =
RequestHandler.create(ToolsRequestComponent.class, FluentIterable
.from(asList(ToolsRequestComponent.class.getMethods()))
.transform(new Function<Method, Method>() {
@Override
public Method apply(Method method) {
method.setAccessible(true); // Make App Engine's security manager happy.
return method;
}}));
RequestHandler.create(ToolsRequestComponent.class);
@Override
public void init() {