use of com.google.inject.servlet.ServletModule in project hadoop by apache.
the class TestHsWebServicesJobs method testJobCountersForKilledJob.
@Test
public void testJobCountersForKilledJob() throws Exception {
WebResource r = resource();
appContext = new MockHistoryContext(0, 1, 1, 1, true);
GuiceServletConfig.setInjector(Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
webApp = mock(HsWebApp.class);
when(webApp.name()).thenReturn("hsmockwebapp");
bind(JAXBContextResolver.class);
bind(HsWebServices.class);
bind(GenericExceptionHandler.class);
bind(WebApp.class).toInstance(webApp);
bind(AppContext.class).toInstance(appContext);
bind(HistoryContext.class).toInstance(appContext);
bind(Configuration.class).toInstance(conf);
serve("/*").with(GuiceContainer.class);
}
}));
Map<JobId, Job> jobsMap = appContext.getAllJobs();
for (JobId id : jobsMap.keySet()) {
String jobId = MRApps.toString(id);
ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").path(jobId).path("counters/").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
JSONObject info = json.getJSONObject("jobCounters");
WebServicesTestUtils.checkStringMatch("id", MRApps.toString(id), info.getString("id"));
assertTrue("Job shouldn't contain any counters", info.length() == 1);
}
}
use of com.google.inject.servlet.ServletModule in project hadoop by apache.
the class TestRMWithXFSFilter method createInjector.
protected void createInjector(final String headerValue, final boolean explicitlyDisabled) {
GuiceServletConfig.setInjector(Guice.createInjector(new ServletModule() {
@Override
protected void configureServlets() {
bind(JAXBContextResolver.class);
bind(RMWebServices.class);
bind(GenericExceptionHandler.class);
Configuration conf = new Configuration();
conf.setClass(YarnConfiguration.RM_SCHEDULER, FifoScheduler.class, ResourceScheduler.class);
rm = new MockRM(conf);
bind(ResourceManager.class).toInstance(rm);
serve("/*").with(GuiceContainer.class);
XFrameOptionsFilter xfsFilter = new XFrameOptionsFilter();
Map<String, String> initParams = new HashMap<>();
if (headerValue != null) {
initParams.put(XFrameOptionsFilter.CUSTOM_HEADER_PARAM, headerValue);
}
if (explicitlyDisabled) {
initParams.put("xframe-options-enabled", "false");
}
filter("/*").through(xfsFilter, initParams);
}
}));
}
use of com.google.inject.servlet.ServletModule in project roboguice by roboguice.
the class GuiceObjectFactory method createInjector.
private void createInjector() {
try {
logger.info("Creating injector...");
this.injector = Guice.createInjector(new AbstractModule() {
protected void configure() {
// Install default servlet bindings.
install(new ServletModule());
// Install user's module.
if (module != null) {
logger.info("Installing " + module + "...");
install(module);
} else {
logger.info("No module found. Set 'guice.module' to a Module " + "class name if you'd like to use one.");
}
// can validate them at startup.
for (Class<?> boundClass : boundClasses) {
// TODO: Set source from Struts XML.
bind(boundClass);
}
// Validate the interceptor class.
for (ProvidedInterceptor interceptor : interceptors) {
interceptor.validate(binder());
}
}
});
// Inject interceptors.
for (ProvidedInterceptor interceptor : interceptors) {
interceptor.inject();
}
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
logger.info("Injector created successfully.");
}
use of com.google.inject.servlet.ServletModule in project guice by google.
the class GuiceObjectFactory method createInjector.
private void createInjector() {
try {
logger.info("Creating injector...");
this.injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
// Install default servlet bindings.
install(new ServletModule());
// Install user's module.
if (module != null) {
logger.info("Installing " + module + "...");
install(module);
} else {
logger.info("No module found. Set 'guice.module' to a Module " + "class name if you'd like to use one.");
}
// can validate them at startup.
for (Class<?> boundClass : boundClasses) {
// TODO: Set source from Struts XML.
bind(boundClass);
}
// Validate the interceptor class.
for (ProvidedInterceptor interceptor : interceptors) {
interceptor.validate(binder());
}
}
});
// Inject interceptors.
for (ProvidedInterceptor interceptor : interceptors) {
interceptor.inject();
}
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
logger.info("Injector created successfully.");
}
use of com.google.inject.servlet.ServletModule in project ninja by ninjaframework.
the class NinjaServletBootstrap method configure.
@Override
protected void configure() throws Exception {
super.configure();
// Context for servlet requests
addModule(new AbstractModule() {
@Override
protected void configure() {
bind(Context.class).to(NinjaServletContext.class);
}
});
// Load servlet module. By convention this is a ServletModule where
// the user can register other servlets and servlet filters
// If the file does not exist we simply load the default servlet
String servletModuleClassName = ninjaBaseDirectoryResolver.resolveApplicationClassName(APPLICATION_GUICE_SERVLET_MODULE_CONVENTION_LOCATION);
if (SwissKnife.doesClassExist(servletModuleClassName, this)) {
Class<?> servletModuleClass = Class.forName(servletModuleClassName);
ServletModule servletModule = (ServletModule) servletModuleClass.getConstructor().newInstance();
addModule(servletModule);
} else {
// The servlet Module does not exist => we load the default one.
ServletModule servletModule = new ServletModule() {
@Override
protected void configureServlets() {
bind(NinjaServletDispatcher.class).asEagerSingleton();
serve("/*").with(NinjaServletDispatcher.class);
}
};
addModule(servletModule);
}
}
Aggregations