List of usage examples for javax.servlet ServletConfig getServletContext
public ServletContext getServletContext();
From source file:com.atlassian.jira.web.dispatcher.JiraWebworkActionDispatcher.java
/** * Initialize dispatcher servlet/*from ww w. jav a 2s.c o m*/ * * @param config ServletConfig */ public void init(ServletConfig config) throws ServletException { super.init(config); if (JiraStartupChecklist.startupOK()) { // Clear caches // RO: If not, then it will contain garbage after a couple of redeployments Introspector.flushCaches(); // Clear ValueStack method cache // RO: If not, then it will contain garbage after a couple of redeployments ValueStack.clearMethods(); // Find the save dir, which should be the servlet context temp directory // Use the default - the Servlet Context Temp Directory. File tempdir = (File) config.getServletContext().getAttribute("javax.servlet.context.tempdir"); if (tempdir != null) { saveDir = tempdir.getAbsolutePath(); } else { log.error("Servlet Context Temp Directory isn't set. No save directory set for file uploads."); } log.info("Setting Upload File Directory to '{}'", saveDir); log.info("JiraWebworkActionDispatcher initialized"); } else { // JIRA startup not OK String message = "JIRA startup failed, JIRA has been locked."; String line = StringUtils.repeat("*", message.length()); log.error(NEW_LINE + NEW_LINE + line + NEW_LINE + message + NEW_LINE + line + NEW_LINE); } }
From source file:org.seasar.cadhelin.ControllerServlet.java
@Override public void init(ServletConfig config) throws ServletException { LOG.info("start cadhelin servlert" + config.getServletName()); String s = config.getInitParameter("encoding"); if (s != null) { encoding = s;//from ww w. j a va 2 s .com } s = config.getInitParameter("viewUrlPattern"); if (s != null) { viewUrlPattern = s; } container = SingletonS2ContainerFactory.getContainer(); Object[] objects = container.findAllComponents(Plugin.class); if (objects != null && 0 < objects.length) { plugins = new Plugin[objects.length]; System.arraycopy(objects, 0, plugins, 0, plugins.length); } for (Plugin plugin : plugins) { plugin.start(config); } actionMetadataFactory = new ActionMetadataFactoryImpl(container); config.getServletContext().setAttribute(CONTROLLER_METADATA_NAME, actionMetadataFactory); if (container.hasComponentDef(ExceptionHandler.class)) { exceptionHandlerMetadata = new ExceptionHandlerMetadata( container.getComponentDef(ExceptionHandler.class)); } Object[] f = container.findComponents(ActionFilter.class); this.filters = new ActionFilter[f.length]; System.arraycopy(f, 0, filters, 0, filters.length); }
From source file:com.linkedin.restli.server.RestliServlet.java
private AbstractR2Servlet buildR2ServletFromServletParams(ServletConfig servletConfig) { ResourceFactory resourceFactory = new PrototypeResourceFactory(); RestLiConfig config = new RestLiConfig(); config.setResourcePackageNamesSet(getResourcePackageSet(servletConfig)); final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool(getParseqThreadPoolSize(servletConfig)); Engine engine = new EngineBuilder().setTaskExecutor(scheduler).setTimerScheduler(scheduler).build(); DelegatingTransportDispatcher dispatcher = new DelegatingTransportDispatcher( new RestLiServer(config, resourceFactory, engine)); boolean useAsync = getUseAsync(servletConfig); long asyncTimeOut = getAsyncTimeout(servletConfig); if (useAsync && servletConfig.getServletContext().getMajorVersion() < 3) { throw new IllegalArgumentException( "This servlet is configured with useAsync=true, but the current servlet " + "context does not support the required Servlet API 3.0."); }//www . j a v a 2 s .c o m if (!useAsync) { log.info( "Initializing Rest.li with a thread based request handling. Set useAsync=true on a Servlet API 3.0 container to enable Rest.li's async servlet."); return new RAPServlet(dispatcher); } else { log.info("Initializing Rest.li with an async request handling enabled."); return new AsyncR2Servlet(dispatcher, asyncTimeOut); } }
From source file:com.ctriposs.rest4j.server.Rest4JServlet.java
private AbstractR2Servlet buildR2ServletFromServletParams(ServletConfig servletConfig) { ResourceFactory resourceFactory = new PrototypeResourceFactory(); Rest4JConfig config = new Rest4JConfig(); config.setResourcePackageNamesSet(getResourcePackageSet(servletConfig)); final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool(getParseqThreadPoolSize(servletConfig)); Engine engine = new EngineBuilder().setTaskExecutor(scheduler).setTimerScheduler(scheduler).build(); DelegatingTransportDispatcher dispatcher = new DelegatingTransportDispatcher( new Rest4JServer(config, resourceFactory, engine)); boolean useAsync = getUseAsync(servletConfig); long asyncTimeOut = getAsyncTimeout(servletConfig); if (useAsync && servletConfig.getServletContext().getMajorVersion() < 3) { throw new IllegalArgumentException( "This servlet is configured with useAsync=true, but the current servlet " + "context does not support the required Servlet API 3.0."); }/*from w w w . j av a 2 s . com*/ if (!useAsync) { log.info( "Initializing Rest4J with a thread based request handling. Set useAsync=true on a Servlet API 3.0 container to enable Rest4J's async servlet."); return new RAPServlet(dispatcher); } else { log.info("Initializing Rest4J with an async request handling enabled."); return new AsyncR2Servlet(dispatcher, asyncTimeOut); } }
From source file:org.wso2.carbon.registry.resource.ui.clients.ResourceServiceClient.java
public ResourceServiceClient(String cookie, ServletConfig config, HttpSession session) throws RegistryException { this.session = session; String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session); ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); epr = backendServerURL + "ResourceAdminService"; try {/*from w ww .j a v a 2 s .c om*/ stub = new ResourceAdminServiceStub(configContext, epr); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault axisFault) { String msg = "Failed to initiate resource service client. " + axisFault.getMessage(); log.error(msg, axisFault); throw new RegistryException(msg, axisFault); } }
From source file:de.fuberlin.wiwiss.marbles.MarblesServlet.java
/** * Reads servlet configuration, initializes Sesame repositories and loads ontologies *//*w w w . j a va 2s .c o m*/ @Override public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext context = config.getServletContext(); dataRoot = getAbsolutePath(config.getInitParameter("dataRoot"), context); if (!(dataRoot != null && new File(dataRoot).isDirectory())) throw new ServletException("Invalid dataRoot " + (dataRoot == null ? "(null)" : dataRoot)); try { if (config.getInitParameter("assetsURL") != null) assetsURL = new URL(config.getInitParameter("assetsURL")); } catch (Exception e) { throw new ServletException("Invalid assetsURL " + config.getInitParameter("assetsURL")); } try { if (config.getInitParameter("serviceURL") != null) serviceURL = new URL(config.getInitParameter("serviceURL")); } catch (Exception e) { throw new ServletException("Invalid serviceURL " + config.getInitParameter("serviceURL")); } org.apache.log4j.BasicConfigurator.configure(); boolean enableDebugging = (config.getInitParameter("enableDebugging") != null && config.getInitParameter("enableDebugging").equalsIgnoreCase("true")); Logger.getRootLogger().setLevel(enableDebugging ? Level.DEBUG : Level.WARN); /* Set up HTTP Client logging */ // Commented out at this should be configured on the server level // System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Log4JLogger"); // System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); // System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug"); // System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug"); /* Set up Sesame MySQL RDBMS */ try { confRepository = new SailRepository(new MemoryStore()); confRepository.initialize(); ontoRepository = new SailRepository( new NativeStore(new File(getAbsolutePath(config.getInitParameter("ontologyStore"), context)))); ontoRepository.initialize(); SailBase baseStore = null; if (config.getInitParameter("mysqlDb") != null && config.getInitParameter("mysqlServer") != null && config.getInitParameter("mysqlUser") != null && config.getInitParameter("mysqlPass") != null) { MySqlStore myStore = new MySqlStore(config.getInitParameter("mysqlDb")); myStore.setServerName(config.getInitParameter("mysqlServer")); myStore.setUser(config.getInitParameter("mysqlUser")); myStore.setPassword(config.getInitParameter("mysqlPass")); myStore.setMaxNumberOfTripleTables(16); //myStore.setIndexed(true); baseStore = myStore; } else { baseStore = new NativeStore( new File(getAbsolutePath(config.getInitParameter("cacheStore"), context))); } /* SameAsInferencer requires an InferencerConnection, which is provided by the native store */ sameAsInferencer = new SameAsInferencer(baseStore); sameAsInferencer.setAutoInference(false); dataRepository = new SailRepository(sameAsInferencer); dataRepository.initialize(); metaDataRepository = new SailRepository( new NativeStore(new File(getAbsolutePath(config.getInitParameter("metadataStore"), context)))); metaDataRepository.initialize(); RepositoryConnection ontoConn = ontoRepository.getConnection(); ValueFactory ontoValueFactory = ontoRepository.getValueFactory(); /* Load ontologies */ File ontoDir = new File(dataRoot + "/" + ontologiesDirectory); for (File f : ontoDir.listFiles(new RDFFilenameFilter())) { URI ontoResource = ontoValueFactory.createURI("file://" + f.getName()); /* Only load new ontologies */ if (!ontoConn.hasStatement(null, null, null, false, ontoResource)) { try { loadTriples(ontoRepository, f, null /* parameters */, ontoResource); } catch (Exception e) { System.err.println("Error loading " + f.getName()); e.printStackTrace(); } } } ontoConn.close(); valueFactory = dataRepository.getValueFactory(); /* Set up external data providers */ ArrayList<DataProvider> dataProviders = new ArrayList<DataProvider>(); if (config.getInitParameter("dataProviders") != null) { String[] providers = config.getInitParameter("dataProviders").split(","); for (String dsName : providers) { try { DataProvider d = (DataProvider) (this.getClass().getClassLoader().loadClass(dsName)) .newInstance(); dataProviders.add(d); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } /* Set up Virtuoso Sponger */ SpongerProvider spongerProvider = null; if (config.getInitParameter("spongerServiceURL") != null) { spongerProvider = new SpongerProvider(config.getInitParameter("spongerServiceURL")); } cacheController = new CacheController(dataRepository, metaDataRepository); semwebClient = new SemanticWebClient(cacheController, spongerProvider, dataProviders); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.wso2.carbon.registry.info.ui.clients.InfoServiceClient.java
public InfoServiceClient(String cookie, ServletConfig config, HttpSession session) throws RegistryException { this.session = session; if (proxy == null) { String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session); ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String epr = backendServerURL + "InfoAdminService"; try {/*from w w w . j a va 2 s .c o m*/ stub = new InfoAdminServiceStub(configContext, epr); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault axisFault) { String msg = "Failed to initiate comment service client. " + axisFault.getMessage(); log.error(msg, axisFault); throw new RegistryException(msg, axisFault); } proxy = this; } }
From source file:de.mpg.imeji.presentation.servlet.DigilibServlet.java
@Override public void init(ServletConfig config) throws ServletException { PropertyBean propBean = new PropertyBean(); if (propBean.isDigilibEnabled()) { try {//from w w w. j a va 2 s . co m authorization = new Authorization(); navigation = new Navigation(); } catch (Exception e) { throw new RuntimeException(e); } storageController = new StorageController(); InternalStorageManager ism = new InternalStorageManager(); internalStorageBase = FilenameUtils .getBaseName(FilenameUtils.normalizeNoEndSeparator(ism.getStoragePath())); // Copy the digilib-config.xml before initialising the digilib servlet, which needs this file copyFile(getDigilibConfigPath(), config.getServletContext().getRealPath("/WEB-INF")); super.init(config); } else { logger.info("Digilib Viewer is disabled."); } }
From source file:net.unicon.academus.apps.blogger.access.CompositeAuthorizationProvider.java
public void init(ServletConfig servletConfig, BlojsomConfiguration blojsomConfiguration) throws BlojsomConfigurationException { if (!bootstrapped) { synchronized (this) { if (!bootstrapped) { String authorizationConfiguration = servletConfig.getInitParameter(BLOG_COMPOSITEAUTH_IP); if (BlojsomUtils.checkNullOrBlank(authorizationConfiguration)) { _logger.error("No authorization configuration file specified: Attempted to load: " + authorizationConfiguration + " with key: " + BLOG_COMPOSITEAUTH_IP); throw new BlojsomConfigurationException("No authorization configuration file specified"); }/* w w w. j a v a2s. c o m*/ Properties authorizationProperties; InputStream is = servletConfig.getServletContext() .getResourceAsStream(authorizationConfiguration); authorizationProperties = new BlojsomProperties(); try { authorizationProperties.load(is); is.close(); Map authorizationMap = BlojsomUtils.propertiesToMap(authorizationProperties); if (!authorizationMap.containsKey(AUTHENTICATION_KEY) || !authorizationMap.containsKey(AUTHORIZATION_KEY)) { _logger.error("Both authentication and authorization keys must be specified."); throw new BlojsomConfigurationException( "Both authentication and authorization keys must be specified."); } authorization = loadClass((String) authorizationMap.get(AUTHORIZATION_KEY)); authentication = loadClass((String) authorizationMap.get(AUTHENTICATION_KEY)); } catch (IOException e) { _logger.error(e); throw new BlojsomConfigurationException(e); } this.bootstrapped = true; } } } authorization.init(servletConfig, blojsomConfiguration); authentication.init(servletConfig, blojsomConfiguration); }