I am using dropwizard. I created a filter for authenticating the user. Here in the code sessionRepository is the one that do all the talking with session table in database. The function works fine when used inside of resources, but fails when used with ContainerRequestFilter. Giving the error:

java.lang.IllegalStateException: No thread bound entity manager.

public class TestFilter implements ContainerRequestFilter {

  public static final String USER_ID = "X_USER_ID";

  private ResourceInfo resourceInfo;

  private Provider<SessionRepository> sessionRepository;

  private Provider<DeviceRepository> deviceProvider;

  public TestFilter(Provider<SessionRepository> sessionRepository,
      Provider<DeviceRepository> deviceProvider) {
    this.sessionRepository = sessionRepository;
    this.deviceProvider = deviceProvider;

  public void filter(ContainerRequestContext request) {
    Optional<Session> session = sessionRepository.get().getActiveSessionBySessionId("sample-session");
    log.info("Inside filter");

0 Answers