0
votes

Hi I am using annotation to map the servlet instead of web.xml, I am trying to retrive the entities from the datastore using objectify, (I am using java8 version of google app engine) and I am using static block to register the entity(class).

I got this error:

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)

I know that, need have to objectify filter in the web.xml:(as below code) in my case I am not using web.xml

<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>

Question:

How can I do this objectify filter in the annotation?

2

2 Answers

1
votes

This would require a code change to ObjectifyFilter so it gets a @WebFilter annotation. While you are using annotations for your own Servlet/related code, you could still create a web.xml to define the Objectify filter, which should resolve the issue.

1
votes

I solved the problem by creating a class which extends the ObjectifyFilter

@WebFilter(urlPatterns = {"/*"})
public class ObjectifyFilterServlet extends ObjectifyFilter {
}

so, Its working fine, but when I use web.xml, for the code

<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> 

I am getting Error 404 for the first request. so I created a simple class which extends ObjectifyFilter, I solved this problem. if there is other solution, share those information also. Thank you