GAEでもGoogle GuiceのAOPは使えます。
Google App Engine上でも普通に使えましたよ > Google GuiceのAOP。ということで、動作確認に使った簡単なサーブレットを公開してみます。
import java.io.IOException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.matcher.Matchers; /** * インターセプターを使うサーブレット */ @SuppressWarnings("serial") public class InterceptorTestServlet extends HttpServlet { /** * GETメソッドを処理する。 */ public void doGet( final HttpServletRequest req, final HttpServletResponse resp) throws IOException { resp.setContentType("text/plain"); // インターセプターを作成 final MethodInterceptor interceptor = new MethodInterceptor() { @Override public Object invoke(MethodInvocation mi) throws Throwable { try { resp.getWriter().write("before."); return mi.proceed(); } finally { resp.getWriter().write("after."); } } }; // コンテナを作成/アスペクト適用済みインスタンスを取得 Foo aspected = Guice.createInjector(new AbstractModule() { @Override protected void configure() { bind( Foo.class ); bindInterceptor(Matchers.any(), Matchers.any(), interceptor); } }).getInstance( Foo.class ); // メソッドを実行。 try { aspected.call( resp ); } catch (Exception e) { throw new IOException(e); } } // テスト用クラス static class Foo { public void call( HttpServletResponse resp )throws Exception { resp.getWriter().write("foo."); } } }