Objectify context not started / ObjectifyFilter is missing

The App Engine (all of a sudden) tells me that I installed Objectify incorrectly. It worked before, and I have an Objectify filter in my web.xml.

Here's the full stack from my logs:

javax.servlet.ServletContext log: unavailable
java.lang.IllegalStateException: You have not started an Objectify context.
                                 You are probably missing the ObjectifyFilter.
                                 If you are not running in the context of an http request, see the ObjectifyService.run() method.
    at com.googlecode.objectify.ObjectifyService.ofy(ObjectifyService.java:44)
    at com.mydomain.gae.defaultmodule.MyObject.loadEverything(MyObject.java:21)
    at com.mydomain.gae.defaultmodule.MyServlet.init(MyServlet.java:40)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:206)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:179)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:136)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:469)
    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:256)
    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 com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:235)
    at java.lang.Thread.run(Thread.java:745)

Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <listener>
        <listener-class>
            com.mydomain.gae.defaultmodule.Initializer
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>com.mydomain.gae.defaultmodule.MyServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

    <filter>
        <filter-name>ObjectifyFilter</filter-name>
        <filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ObjectifyFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>

... and then here is the code:

public class Initializer implements ServletContextListener {

    @Override
    public void contextInitialized(@Nonnull final ServletContextEvent SCE) {
        ObjectifyFactory oFactory = ObjectifyService.factory();
        oFactory.register(MyEntity.class);
        oFactory.register(MyOtherEntity.class);
        oFactory.begin();
    }
}

public final class MyServlet extends HttpServlet {

    private MyObject = myObj;

    @Override
    public void init() throws ServletException {
        myObj = new MyObject();
        myObj.loadEverything();
    }
}

public class MyObject extends MyOtherObject {

    public void loadEverything() {
        for (MyEntity me : ofy().load().type(MyEntity.class).list()) {
            // Do very important things.
        }
    }
}

IllegalStateExceptioncalled as soon as it gets into ofy().load().type(MyEntity.class).list(). This code worked before. I am at a loss why it suddenly exploded in my face, since none of the codes here were changed before this explosion.

If someone has ANY ideas that can make me move in the right direction, I am 100% interested in listening to them.

+4
source share
1 answer

. init , ObjectifyFilter - , stacktrace.

oFactory.begin() contextInitialized(), .

Objectify init(), ObjectifyService.run():

ObjectifyService.run(new VoidWork() {
    public void vrun() {
        myObj = new MyObject();
        myObj.loadEverything();
    }
});

Objectify , .

+4

Source: https://habr.com/ru/post/1621828/


All Articles