Versão atual:

Utilizando Jersey com varias instancias no Google App Engine

Estou utilizando o Google App Engine, Jersey e um app desenvolvido em Android.

Na documentação do GAE encontrei estas configurações do appengine-web.xml:

<automatic-scaling>
    <min-idle-instances>5</min-idle-instances>

    <!-- ‘automatic’ is the default value. -->

    <max-idle-instances>automatic</max-idle-instances>

    <!-- ‘automatic’ is the default value. -->

    <min-pending-latency>30ms</min-pending-latency>

    <max-pending-latency>automatic</max-pending-latency>


  </automatic-scaling>

No código acima, se mudo o valor de "min-idle-instances" para 0, ou seja, nenhuma instancia ociosa todas dinâmicas, o sistema funciona sem problemas. Quando coloco um valor como o 5 por exemplo, alguns erros começam a apontar para a terceira linha do código abaixo:

private DefaultOAuth1Provider provider = new DefaultOAuth1Provider();

...


Token requestToken = provider.getRequestToken(token);

...

String verifier = provider.authorizeToken(requestToken, userPrincipal,roles); // ERRO

erro:

java.lang.NullPointerException
    at org.glassfish.jersey.server.oauth1.DefaultOAuth1Provider.authorizeToken(DefaultOAuth1Provider.java:150)
    at br.com.server.rest.AuthorizeResource.postTokenRefresh(AuthorizeResource.java:180) // esta é a linha do código acima
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:44)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$TypeOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:205)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:234)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at java.lang.Thread.run(Thread.java:745)

Parece que o requestToken está retornando "null", mas o estranho é que este mesmo código funciona quando o numero de instancias ociosas do App Engine esta com 0.

Cheguei a pensar que toda vez que faço uma chamada pelo App Android o GAE pode estar executando em instancias diferentes, causando os erros. Mas se for isso, não sei como resolver.

Segue minha classe Application:

@Override
    public Set<Object> getSingletons() {
        Set<Object> singletons = new HashSet<>();

        singletons.add(new MultiPartFeature());

        DefaultOAuth1Provider oauthProvider = new DefaultOAuth1Provider();
        MultivaluedMap<String, String> attributes = new MultivaluedStringMap();
        oauthProvider.registerConsumer(APP_OWNER, CONSUMER_KEY,CONSUMER_SECRET, attributes);
        singletons.add(new OAuth1ServerFeature(oauthProvider));

        return singletons;
    }

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> s = new HashSet<Class<?>>();

        s.add(RolesAllowedDynamicFeature.class);
        return s;
    }

    @Override
    public Map<String, Object> getProperties() {
        Map<String, Object> properties = new HashMap<>();

        properties.put("jersey.config.server.provider.packages", "br.com.server.rest");

        properties.put(OAuth1ServerProperties.ENABLE_TOKEN_RESOURCES,
                Boolean.TRUE);
        return properties;
    }

Versões(5):

Ver a versão formatada

Utilizando Jersey com varias instancias no Google App Engine

  • criado 17 de nov de 2015

Comentário

new question