@Test public void setsUpEnvironmentContextBeforeCallToRequestHandler() throws Exception { ContainerRequest containerRequest = mockContainerRequest(); ContainerResponse containerResponse = mockContainerResponse(); EnvironmentContext environmentContext = mock(EnvironmentContext.class); EnvironmentContext[] environmentContextThatRequestHandlerCalledWith = new EnvironmentContext[1]; doAnswer(invocation -> { environmentContextThatRequestHandlerCalledWith[0] = EnvironmentContext.getCurrent(); return null; }).when(requestHandler).handleRequest(containerRequest, containerResponse); everrestProcessor.process(containerRequest, containerResponse, environmentContext); assertNotNull(environmentContextThatRequestHandlerCalledWith[0]); assertSame(environmentContext, environmentContextThatRequestHandlerCalledWith[0]); }
public void process(GenericContainerRequest request, GenericContainerResponse response, EnvironmentContext environmentContext) throws IOException { EnvironmentContext.setCurrent(environmentContext); ApplicationContext context = anApplicationContext() .withRequest(request) .withResponse(response) .withProviders(requestHandler.getProviders()) .withProperties(properties) .withApplication(everrestApplication) .withConfiguration(new EverrestConfiguration(configuration)) .withDependencySupplier(dependencySupplier) .withMethodInvokerDecoratorFactory(methodInvokerDecoratorFactory) .build(); try { context.start(); ApplicationContext.setCurrent(context); if (configuration.isNormalizeUri()) { normalizeRequestUri(request); } if (configuration.isHttpMethodOverride()) { overrideHttpMethod(request); } requestHandler.handleRequest(request, response); } finally { try { context.stop(); } finally { ApplicationContext.setCurrent(null); } EnvironmentContext.setCurrent(null); } }
EverrestProcessor implements Lifecycle { public void process(GenericContainerRequest request, GenericContainerResponse response, EnvironmentContext environmentContext) throws IOException { EnvironmentContext.setCurrent(environmentContext); ApplicationContext context = anApplicationContext() .withRequest(request) .withResponse(response) .withProviders(requestHandler.getProviders()) .withProperties(properties) .withApplication(everrestApplication) .withConfiguration(new EverrestConfiguration(configuration)) .withDependencySupplier(dependencySupplier) .withMethodInvokerDecoratorFactory(methodInvokerDecoratorFactory) .build(); try { context.start(); ApplicationContext.setCurrent(context); if (configuration.isNormalizeUri()) { normalizeRequestUri(request); } if (configuration.isHttpMethodOverride()) { overrideHttpMethod(request); } requestHandler.handleRequest(request, response); } finally { try { context.stop(); } finally { ApplicationContext.setCurrent(null); } EnvironmentContext.setCurrent(null); } } }
EverrestProcessor implements Lifecycle { public void process(GenericContainerRequest request, GenericContainerResponse response, EnvironmentContext environmentContext) throws IOException { EnvironmentContext.setCurrent(environmentContext); ApplicationContext context = anApplicationContext() .withRequest(request) .withResponse(response) .withProviders(requestHandler.getProviders()) .withProperties(properties) .withApplication(everrestApplication) .withConfiguration(new EverrestConfiguration(configuration)) .withDependencySupplier(dependencySupplier) .withMethodInvokerDecoratorFactory(methodInvokerDecoratorFactory) .build(); try { context.start(); ApplicationContext.setCurrent(context); if (configuration.isNormalizeUri()) { normalizeRequestUri(request); } if (configuration.isHttpMethodOverride()) { overrideHttpMethod(request); } requestHandler.handleRequest(request, response); } finally { try { context.stop(); } finally { ApplicationContext.setCurrent(null); } EnvironmentContext.setCurrent(null); } } EverrestProcessor(DependencySupplier dependencySupplier, RequestHandler requestHandler);  EverrestProcessor(EverrestConfiguration configuration, DependencySupplier dependencySupplier, RequestHandler requestHandler, Application application); }
EverrestProcessor implements Lifecycle { public void process(GenericContainerRequest request, GenericContainerResponse response, EnvironmentContext environmentContext) throws IOException { EnvironmentContext.setCurrent(environmentContext); ApplicationContext context = anApplicationContext() .withRequest(request) .withResponse(response) .withProviders(requestHandler.getProviders()) .withProperties(properties) .withApplication(everrestApplication) .withConfiguration(new EverrestConfiguration(configuration)) .withDependencySupplier(dependencySupplier) .withMethodInvokerDecoratorFactory(methodInvokerDecoratorFactory) .build(); try { context.start(); ApplicationContext.setCurrent(context); if (configuration.isNormalizeUri()) { normalizeRequestUri(request); } if (configuration.isHttpMethodOverride()) { overrideHttpMethod(request); } requestHandler.handleRequest(request, response); } finally { try { context.stop(); } finally { ApplicationContext.setCurrent(null); } EnvironmentContext.setCurrent(null); } } EverrestProcessor(DependencySupplier dependencySupplier, RequestHandler requestHandler);  EverrestProcessor(EverrestConfiguration configuration, DependencySupplier dependencySupplier, RequestHandler requestHandler, Application application); String getProperty(String name); void setProperty(String name, String value); void process(GenericContainerRequest request, GenericContainerResponse response, EnvironmentContext environmentContext); void addApplication(Application application); @Override void start(); @Override void stop(); ProviderBinder getProviders(); ResourceBinder getResources(); EverrestApplication getApplication(); DependencySupplier getDependencySupplier(); }
EverrestProcessor implements Lifecycle { public void process(GenericContainerRequest request, GenericContainerResponse response, EnvironmentContext environmentContext) throws IOException { EnvironmentContext.setCurrent(environmentContext); ApplicationContext context = anApplicationContext() .withRequest(request) .withResponse(response) .withProviders(requestHandler.getProviders()) .withProperties(properties) .withApplication(everrestApplication) .withConfiguration(new EverrestConfiguration(configuration)) .withDependencySupplier(dependencySupplier) .withMethodInvokerDecoratorFactory(methodInvokerDecoratorFactory) .build(); try { context.start(); ApplicationContext.setCurrent(context); if (configuration.isNormalizeUri()) { normalizeRequestUri(request); } if (configuration.isHttpMethodOverride()) { overrideHttpMethod(request); } requestHandler.handleRequest(request, response); } finally { try { context.stop(); } finally { ApplicationContext.setCurrent(null); } EnvironmentContext.setCurrent(null); } } EverrestProcessor(DependencySupplier dependencySupplier, RequestHandler requestHandler);  EverrestProcessor(EverrestConfiguration configuration, DependencySupplier dependencySupplier, RequestHandler requestHandler, Application application); String getProperty(String name); void setProperty(String name, String value); void process(GenericContainerRequest request, GenericContainerResponse response, EnvironmentContext environmentContext); void addApplication(Application application); @Override void start(); @Override void stop(); ProviderBinder getProviders(); ResourceBinder getResources(); EverrestApplication getApplication(); DependencySupplier getDependencySupplier();  }