use of javax.servlet.ServletContext in project uavstack by uavorg.
the class JettyPlusIT method onAppStarting.
/**
* onAppStarting
*
* @param args
*/
public void onAppStarting(Object... args) {
WebAppContext sc = (WebAppContext) args[0];
InterceptSupport iSupport = InterceptSupport.instance();
InterceptContext context = iSupport.createInterceptContext(Event.WEBCONTAINER_INIT);
context.put(InterceptConstants.WEBAPPLOADER, sc.getClassLoader());
context.put(InterceptConstants.WEBWORKDIR, sc.getServletContext().getRealPath(""));
context.put(InterceptConstants.CONTEXTPATH, sc.getContextPath());
context.put(InterceptConstants.APPNAME, sc.getDisplayName());
ServletContext sContext = sc.getServletContext();
context.put(InterceptConstants.SERVLET_CONTEXT, sContext);
getBasePath(context, sContext);
iSupport.doIntercept(context);
}
use of javax.servlet.ServletContext in project BIMserver by opensourceBIM.
the class Jsr356Impl method onOpen.
@OnOpen
public void onOpen(Session websocketSession, EndpointConfig config) {
LOGGER.debug("WebSocket open");
try {
this.websocketSession = websocketSession;
ServletContext servletContext = servletContexts.get(websocketSession.getContainer());
if (servletContext == null) {
servletContext = defaultServletContext;
}
BimServer bimServer = (BimServer) servletContext.getAttribute("bimserver");
streamer = new Streamer(this, bimServer);
streamer.onOpen();
} catch (Throwable t) {
LOGGER.error("", t);
}
}
use of javax.servlet.ServletContext in project BIMserver by opensourceBIM.
the class WarServerInitializer method contextInitialized.
public void contextInitialized(ServletContextEvent servletContextEvent) {
ServletContext servletContext = servletContextEvent.getServletContext();
Path homeDir = null;
if (servletContext.getAttribute("homedir") != null) {
homeDir = Paths.get((String) servletContext.getAttribute("homedir"));
}
if (homeDir == null && servletContext.getInitParameter("homedir") != null) {
homeDir = Paths.get(servletContext.getInitParameter("homedir"));
}
boolean autoMigrate = false;
if (servletContext.getAttribute("autoMigrate") != null) {
autoMigrate = (Boolean) servletContext.getAttribute("autoMigrate");
}
if (autoMigrate == false && servletContext.getInitParameter("autoMigrate") != null) {
autoMigrate = Boolean.valueOf(servletContext.getInitParameter("autoMigrate"));
}
String realPath = servletContext.getRealPath("/");
if (!realPath.endsWith("/")) {
realPath = realPath + "/";
}
Path baseDir = Paths.get(realPath + "WEB-INF");
if (homeDir == null) {
homeDir = baseDir;
}
ResourceFetcher resourceFetcher = new WarResourceFetcher(servletContext, homeDir);
BimServerConfig config = new BimServerConfig();
config.setAutoMigrate(autoMigrate);
config.setEnvironment(Environment.WAR);
config.setHomeDir(homeDir);
config.setResourceFetcher(resourceFetcher);
if (homeDir != null) {
// Basically doing this twice (also in BimServer.init), but this makes sure the logback.xml file is copied to the homedir
try {
BimServer.initHomeDir(config);
} catch (IOException e) {
e.printStackTrace();
}
}
setupLogging(homeDir);
try {
fixLogging(config);
config.setClassPath(makeClassPath(resourceFetcher.getFile("lib")));
} catch (IOException e1) {
e1.printStackTrace();
}
config.setStartEmbeddedWebServer(false);
bimServer = new BimServer(config);
Jsr356Impl.setDefaultServletContext(servletContextEvent.getServletContext());
Logger LOGGER = LoggerFactory.getLogger(WarServerInitializer.class);
LOGGER.info("Servlet Context Name: " + servletContext.getServletContextName());
try {
bimServer.start();
} catch (ServerException e) {
LOGGER.error("", e);
} catch (DatabaseInitException e) {
LOGGER.error("", e);
} catch (BimserverDatabaseException e) {
LOGGER.error("", e);
} catch (PluginException e) {
LOGGER.error("", e);
} catch (DatabaseRestartRequiredException e) {
LOGGER.error("", e);
}
servletContext.setAttribute("bimserver", bimServer);
}
use of javax.servlet.ServletContext in project cuba by cuba-platform.
the class PortalAppContextLoader method createApplicationContext.
@Override
protected ApplicationContext createApplicationContext(String[] locations) {
CubaXmlWebApplicationContext webContext = new CubaXmlWebApplicationContext();
String[] classPathLocations = new String[locations.length];
for (int i = 0; i < locations.length; i++) {
classPathLocations[i] = "classpath:" + locations[i];
}
webContext.setConfigLocations(classPathLocations);
webContext.setServletContext(ServletContextHolder.getServletContext());
webContext.refresh();
ServletContext servletContext = ServletContextHolder.getServletContext();
if (servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE) != null) {
throw new IllegalStateException("Cannot initialize context because there is already a root application context present - " + "check whether you have multiple ContextLoader* definitions in your web.xml!");
}
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext);
return webContext;
}
use of javax.servlet.ServletContext in project thymeleaf-tests by thymeleaf.
the class TestMockServletUtil method createServletContext.
public static ServletContext createServletContext(final Map<String, Object> attributes) {
final String contextName = "/testing";
final ServletContext servletContext = Mockito.mock(ServletContext.class);
Mockito.when(servletContext.getAttributeNames()).thenAnswer(new GetVariableNamesAnswer(attributes));
Mockito.when(servletContext.getAttribute(Matchers.anyString())).thenAnswer(new GetAttributeAnswer(attributes));
Mockito.doAnswer(new SetAttributeAnswer(attributes)).when(servletContext).setAttribute(Matchers.anyString(), Matchers.anyObject());
Mockito.doAnswer(new RemoveAttributeAnswer(attributes)).when(servletContext).removeAttribute(Matchers.anyString());
Mockito.when(servletContext.getContextPath()).thenReturn(contextName);
Mockito.when(servletContext.getInitParameterNames()).thenReturn(new ObjectEnumeration<String>(null));
Mockito.when(servletContext.getInitParameter(Matchers.anyString())).thenReturn(null);
return servletContext;
}
Aggregations