public void service(
      ChannelHandlerContext ctx, HttpRequest request, HttpResponse response, boolean handleNotFound)
      throws IOException {

    try {
      ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance();
      if (defaultInstance instanceof ThreadLocalResteasyProviderFactory) {
        ThreadLocalResteasyProviderFactory.push(providerFactory);
      }

      SecurityContext securityContext;
      if (domain != null) {
        securityContext = basicAuthentication(request, response);
        if (securityContext == null) // not authenticated
        {
          return;
        }
      } else {
        securityContext = new NettySecurityContext();
      }
      try {

        ResteasyProviderFactory.pushContext(ChannelHandlerContext.class, ctx);
        ResteasyProviderFactory.pushContext(SecurityContext.class, securityContext);
        if (handleNotFound) {
          dispatcher.invoke(request, response);
        } else {
          dispatcher.invokePropagateNotFound(request, response);
        }
      } finally {
        ResteasyProviderFactory.clearContextData();
      }
    } finally {
      ResteasyProviderFactory defaultInstance = ResteasyProviderFactory.getInstance();
      if (defaultInstance instanceof ThreadLocalResteasyProviderFactory) {
        ThreadLocalResteasyProviderFactory.pop();
      }
    }
  }
 @After
 public void tearDown() throws Exception {
   ResteasyProviderFactory.clearContextData();
 }
 public void clearContextData() {
   ResteasyProviderFactory.clearContextData();
   // just in case there were internalDispatches that need to be cleaned up
   MessageBodyParameterInjector.clearBodies();
 }