本文整理匯總了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);
}