本文整理汇总了Java中javax.servlet.ServletContextEvent.getServletContext方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContextEvent.getServletContext方法的具体用法?Java ServletContextEvent.getServletContext怎么用?Java ServletContextEvent.getServletContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletContextEvent
的用法示例。
在下文中一共展示了ServletContextEvent.getServletContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent e) {
LOG.info("Creating Smaph context.");
ServletContext context = e.getServletContext();
context.setAttribute("nif-parser", new TurtleNIFDocumentParser());
context.setAttribute("nif-creator", new TurtleNIFDocumentCreator());
String watGcubeToken = context.getInitParameter(WAT_GCUBE_TOKEN);
SmaphBuilder.initialize(watGcubeToken);
try {
context.setAttribute("wikipedia-api", new WikipediaInterfaceWAT.WikipediaInterfaceWATBuilder().gcubeToken(watGcubeToken).build());
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
context.setAttribute("wiki-to-freebase", WikipediaToFreebase.open(context.getInitParameter(FREEBASE_DIR)));
context.setAttribute("entity-to-anchors", EntityToAnchors.fromDB(context.getInitParameter(ENTITY_TO_ANCHORS_DB)));
}
示例2: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
// Try and use one of the Servlet 3.0 methods that should be blocked
try {
servletContext = sce.getServletContext();
sc.getEffectiveMajorVersion();
log.append("FAIL-01");
} catch (UnsupportedOperationException uoe) {
log.append("PASS-01");
} catch (Exception e) {
log.append("FAIL-02");
}
}
示例3: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
// 加载配置文件
ServletContext context = sce.getServletContext();
loadConfig(context.getInitParameter(CONFIGURATIONS_PARAM_NAME));
// 实例化bean处理器
Optional<String> handler = getConfiguration().getBeansHandler();
String finalClass = handler.orElse(DEFAULT_BEANS_HANDLER);
BeansHandler beansHandler = BasicUtil.newInstance(finalClass);
getBeansFactory().setBeansHandler(beansHandler);
getBeansFactory().setConfiguration(getConfiguration());
// 将所有bean对象注册到bean容器
getBeansFactory().register();
loadServlets(context);
}
示例4: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
public void contextInitialized(final ServletContextEvent sce) {
LOGGER.info("GOLDespQuartz Initializer Listener loaded, initializing Scheduler...");
waitOnShutdown = Boolean.valueOf(WAIT_ON_SHUTDOWN);
final ServletContext servletContext = sce.getServletContext();
String configFile = servletContext.getInitParameter("quartz:config-file");
if (configFile == null) {
configFile = servletContext.getInitParameter("config-file");
}
String fileName = System.getProperty("org.quartz.properties", null);
if ((fileName == null || 0 == fileName.length()) && (configFile != null && 0 < configFile.length())) {
System.setProperty("org.quartz.properties", configFile);
}
LOGGER.info("Quartz Schedule StdSchedulerFactory: org.quartz.properties=" + System.getProperty("org.quartz.properties", null));
SchedulerHelperFactory.instance().instantiateSchedulerFactory();
SchedulerHelperFactory.instance().startScheduler();
}
示例5: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
/**
* Record the fact that this web application has been initialized.
*
* @param event
* The servlet context event
*/
@Override
public void contextInitialized(ServletContextEvent event) {
this.context = event.getServletContext();
log("contextInitialized()");
}
示例6: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public final void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
context.setAttribute(OryxResource.MODEL_MANAGER_KEY,
new MockClassificationServingModelManager(ConfigUtils.getDefault()));
context.setAttribute(OryxResource.INPUT_PRODUCER_KEY, new MockTopicProducer());
}
示例7: contextDestroyed
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextDestroyed(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
if (obj instanceof WsServerContainer) {
((WsServerContainer) obj).destroy();
}
}
示例8: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
public void contextInitialized(final ServletContextEvent sce) {
try {
this.delegate.contextInitialized(sce);
} catch (final Throwable t) {
/*
* no matter what went wrong, our role is to capture this error and
* prevent it from blocking initialization of the context. logging
* overkill so that our deployer will find a record of this problem
* even if unfamiliar with Commons Logging and properly configuring
* it.
*/
final String message = "SafeContextLoaderListener: \n"
+ "The Spring ContextLoaderListener we wrap threw on contextInitialized.\n"
+ "But for our having caught this error, the web application context would not have initialized.";
// logger it via Commons Logging
logger.error(message, t);
// logger it to the ServletContext
ServletContext context = sce.getServletContext();
context.log(message, t);
/*
* record the error so that the application has access to later
* display a proper error message based on the exception.
*/
context.setAttribute(CAUGHT_THROWABLE_KEY, t);
}
}
示例9: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
try {
context.setAttribute("upTime", System.currentTimeMillis());
} catch (Exception e) {
}
}
示例10: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
// Don't trigger WebSocket initialization if a WebSocket Server
// Container is already present
if (sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE) == null) {
WsSci.init(sce.getServletContext(), false);
}
}
示例11: contextDestroyed
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextDestroyed(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
Object obj = sc.getAttribute(Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
if (obj instanceof WsServerContainer) {
((WsServerContainer) obj).destroy();
}
}
示例12: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
try {
String tangyuanResource = context.getInitParameter("tangyuan.resource");
if (null != tangyuanResource) {
TangYuanContainer.getInstance().start(tangyuanResource);
}
} catch (Throwable e) {
log.error(null, e);
throw new TangYuanException(e);
}
}
示例13: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
public void contextInitialized(ServletContextEvent contextEvent)
{
final ServletContext context = contextEvent.getServletContext();
try
{
LoggingUtility.init(context.getRealPath("/WEB-INF/logs"));
}
catch(Exception ex)
{
getLogger().error("Unable to initialize logging system.");
}
}
示例14: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextInitialized(final ServletContextEvent event) {
final ServletContext servletContext = event.getServletContext();
final ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(servletContext);
LOGGER.info("[{}] has loaded the CAS servlet application context: {}",
servletContext.getServerInfo(), ctx);
}
示例15: contextInitialized
import javax.servlet.ServletContextEvent; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
log.info("ModelManagerListener initializing");
ServletContext context = sce.getServletContext();
init(context);
if (!readOnly) {
Preconditions.checkArgument(KafkaUtils.topicExists(inputTopicLockMaster, inputTopic),
"Topic %s does not exist; did you create it?", inputTopic);
Preconditions.checkArgument(KafkaUtils.topicExists(updateTopicLockMaster, updateTopic),
"Topic %s does not exist; did you create it?", updateTopic);
inputProducer = new TopicProducerImpl<>(inputTopicBroker, inputTopic);
context.setAttribute(INPUT_PRODUCER_KEY, inputProducer);
}
KafkaConsumer<String,U> consumer = new KafkaConsumer<>(
ConfigUtils.keyValueToProperties(
"group.id", "OryxGroup-ServingLayer-" + UUID.randomUUID(),
"bootstrap.servers", updateTopicBroker,
"max.partition.fetch.bytes", maxMessageSize,
"key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer",
"value.deserializer", updateDecoderClass.getName(),
// Do start from the beginning of the update queue
"auto.offset.reset", "earliest"
));
consumer.subscribe(Collections.singletonList(updateTopic));
consumerIterator = new ConsumeDataIterator<>(consumer);
modelManager = loadManagerInstance();
new Thread(LoggingCallable.log(() -> {
// Possible if it shuts down immediately; just exit
if (modelManager == null) {
return;
}
// Can we do better than a default Hadoop config? Nothing else provides it here
Configuration hadoopConf = new Configuration();
try {
modelManager.consume(consumerIterator, hadoopConf);
} catch (Throwable t) {
log.error("Error while consuming updates", t);
// Ideally we would shut down ServingLayer, but not clear how to plumb that through
// without assuming this has been run from ServingLayer and not a web app deployment
close();
}
}).asRunnable(), "OryxServingLayerUpdateConsumerThread").start();
// Set the Model Manager in the Application scope
context.setAttribute(MANAGER_KEY, modelManager);
}