List of usage examples for javax.servlet ServletConfig getInitParameter
public String getInitParameter(String name);
From source file:org.jahia.services.content.files.FileServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); characterEncoding = SettingsBean.getInstance().getCharacterEncoding(); String value = config.getInitParameter("cache-threshold"); if (value != null) { cacheThreshold = new Integer(value); }//w w w .ja va2 s.c o m value = config.getInitParameter("cache-for-logged-in-users"); if (value != null) { cacheForLoggedUsers = Boolean.parseBoolean(value); } value = config.getInitParameter("cache-from-external-providers"); if (value != null) { cacheFromExternalProviders = Boolean.parseBoolean(value); } try { cacheManager = FileCacheManager.getInstance(); cacheManager.getContentCache(); cacheManager.getLastModifiedCache(); } catch (JahiaRuntimeException e) { throw new ServletException(e.getCause()); } if (SettingsBean.getInstance().isFileServletStatisticsEnabled()) { try { loggingService = (MetricsLoggingService) SpringContextSingleton.getBean("loggingService"); sessionFactory = JCRSessionFactory.getInstance(); } catch (Exception e) { logger.error("Unable to get the logging service instance. Metrics logging will be disabled."); } } }
From source file:org.apache.velocity.tools.view.servlet.VelocityViewServlet.java
/** * Looks up an init parameter with the specified key in either the * ServletConfig or, failing that, in the ServletContext. *///from w w w. ja v a 2 s . c o m protected String findInitParameter(ServletConfig config, String key) { // check the servlet config String param = config.getInitParameter(key); if (param == null || param.length() == 0) { // check the servlet context ServletContext servletContext = config.getServletContext(); param = servletContext.getInitParameter(key); } return param; }
From source file:be.fedict.eid.applet.service.impl.handler.AuthenticationDataMessageHandler.java
public void init(ServletConfig config) throws ServletException { String channelBindingServerCertificate = config .getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVER_CERTIFICATE); if (null != channelBindingServerCertificate) { File serverCertificateFile = new File(channelBindingServerCertificate); if (false == serverCertificateFile.exists()) { throw new ServletException("server certificate not found: " + serverCertificateFile); }/*w w w. jav a 2s . c o m*/ byte[] encodedServerCertificate; try { encodedServerCertificate = FileUtils.readFileToByteArray(serverCertificateFile); } catch (IOException e) { throw new ServletException("error reading server certificate: " + e.getMessage(), e); } this.serverCertificate = getCertificate(encodedServerCertificate); } }
From source file:org.wso2.carbon.registry.core.servlet.RegistryServlet.java
public void init(final ServletConfig config) throws ServletException { super.init(config); EmbeddedRegistryService embeddedRegistryService; try {/*w w w . jav a2 s . c o m*/ // read the registry.xml file from the configured location. if not configured, read the // default registry.xml file bundled with the webapp. String configPath = config.getInitParameter(RegistryConstants.REGISTRY_CONFIG_PATH); InputStream configStream; if (configPath != null) { try { configStream = new FileInputStream(configPath); } catch (FileNotFoundException e) { throw new ServletException("Couldn't find specified config file '" + configPath + "'", e); } } else { configStream = config.getServletContext().getResourceAsStream("/WEB-INF/registry.xml"); } RegistryContext registryContext = RegistryContext.getBaseInstance(configStream, new RegistryContext.RegURLSupplier() { public String getURL() { return config.getServletContext().getRealPath("/WEB-INF"); } }); embeddedRegistryService = registryContext.getEmbeddedRegistryService(); // create a system registry and put it in the context UserRegistry systemRegistry = embeddedRegistryService.getConfigSystemRegistry(); // add configured handers to the jdbc registry // note: no need to do this here. this is done inside the registry context //Iterator<HandlerConfiguration> handlers = // registryContext.getHandlerConfigurations().iterator(); //while (handlers.hasNext()) { // HandlerConfiguration handlerConfiguration = handlers.next(); // registryContext.getHandlerManager().addHandler(0, // handlerConfiguration.getFilter(), handlerConfiguration.getHandler()); //} // create system resources NodeGroupLock.lock(NodeGroupLock.INITIALIZE_LOCK); if (log.isTraceEnabled()) { log.trace("Creating system collections used in WSO2 Registry server."); } if (!systemRegistry.resourceExists("/system")) { try { boolean inTransaction = Transaction.isStarted(); if (!inTransaction) { systemRegistry.beginTransaction(); } Collection systemCollection = systemRegistry.newCollection(); String systemDesc = "This collection is used to store system data of the " + "WSO2 Registry server. User nor the admins of the registry are not expected " + "to edit any content of this collection. Changing content of this collection " + "may result in unexpected behaviors."; systemCollection.setDescription(systemDesc); systemRegistry.put("/system", systemCollection); Collection advancedQueryCollection = systemRegistry.newCollection(); String advaceDesc = "This collection is used to store auto generated queries " + "to support various combinations of advanced search criteria. " + "This is initialy empty and gets filled as advanced search is " + "executed from the web UI."; advancedQueryCollection.setDescription(advaceDesc); systemRegistry.put("/system/queries/advanced", advancedQueryCollection); if (!inTransaction) { systemRegistry.commitTransaction(); } } catch (Exception e) { String msg = "Unable to setup system collections used by the Carbon server."; log.error(msg, e); systemRegistry.rollbackTransaction(); throw new RegistryException(e.getMessage(), e); } } try { AuthorizationManager ac = systemRegistry.getUserRealm().getAuthorizationManager(); RealmConfiguration realmConfig; realmConfig = registryContext.getRealmService().getBootstrapRealmConfiguration(); String systemUserName = CarbonConstants.REGISTRY_SYSTEM_USERNAME; ac.clearResourceAuthorizations("/system"); ac.authorizeUser(systemUserName, "/system", ActionConstants.GET); ac.authorizeUser(systemUserName, "/system", ActionConstants.PUT); ac.authorizeUser(systemUserName, "/system", ActionConstants.DELETE); ac.authorizeUser(systemUserName, "/system", AccessControlConstants.AUTHORIZE); String adminUserName = CarbonConstants.REGISTRY_SYSTEM_USERNAME; ac.authorizeUser(adminUserName, "/system", ActionConstants.GET); String adminRoleName = realmConfig.getAdminRoleName(); ac.authorizeRole(adminRoleName, "/system", ActionConstants.GET); // any user should be able to execute auto generated queries, though the results // of such queries are filtered to match current users permission level. String everyoneRoleName = realmConfig.getEveryOneRoleName(); ac.authorizeRole(everyoneRoleName, "/system/queries/advanced", ActionConstants.GET); } catch (UserStoreException e) { String msg = "Failed to set permissions for the system collection."; log.fatal(msg, e); throw new RegistryException(msg, e); } if (log.isTraceEnabled()) { log.trace("System collections for WSO2 Registry server created successfully."); } NodeGroupLock.unlock(NodeGroupLock.INITIALIZE_LOCK); // todo: we should make this decision according to the registry.xml or web.xml config //try { // RemoteRegistry remote = new RemoteRegistry(new URL("http://localhost:8080/wso2registry/atom")); // config.getServletContext().setAttribute(RegistryConstants.REGISTRY, remote); //} catch (MalformedURLException e) { // config.getServletContext().setAttribute(RegistryConstants.REGISTRY, coreRegistry); //} config.getServletContext().setAttribute(RegistryConstants.REGISTRY, embeddedRegistryService); //config.getServletContext() // .setAttribute(RegistryConstants.REGISTRY_REALM, userRealm); System.getProperties().put(RegistryConstants.REGISTRY, embeddedRegistryService); System.getProperties().put(RegistryConstants.SYSTEM_REGISTRY, systemRegistry); //System.getProperties().put(RegistryConstants.REGISTRY_REALM, userRealm); } catch (RegistryException e) { String msg = "Registry initialization failed. " + e.getMessage(); log.fatal(msg, e); throw new ServletException(msg, e); } /*if (log.isDebugEnabled()) { log.debug(Messages.getMessage("server.initalized")); }*/ }
From source file:org.tinygroup.jspengine.EmbeddedServletOptions.java
private boolean getBoolean(ServletConfig config, boolean init, String param) { String sParam = config.getInitParameter(param); if (sParam != null) { if (sParam.equalsIgnoreCase("true")) { return true; }/* w ww.j av a 2 s . co m*/ if (sParam.equalsIgnoreCase("false")) { return false; } if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.boolean", param, (init ? "true" : "false"))); } } return init; }
From source file:org.codeartisans.proxilet.Proxilet.java
@Override public void init(ServletConfig servletConfig) { // Get the proxy host String stringProxyHostNew = servletConfig.getInitParameter("targetHost"); if (stringProxyHostNew == null || stringProxyHostNew.length() == 0) { throw new IllegalArgumentException("Proxy host not set, please set init-param 'targetHost' in web.xml"); }/*from ww w.j a va 2 s. co m*/ targetHost = stringProxyHostNew; // Get the proxy port if specified String stringProxyPortNew = servletConfig.getInitParameter("targetPort"); if (stringProxyPortNew != null && stringProxyPortNew.length() > 0) { targetPort = Integer.parseInt(stringProxyPortNew); } // Get the credentials, if specified String strProxyCredentials = servletConfig.getInitParameter("targetCredentials"); if (strProxyCredentials != null && strProxyCredentials.length() > 0) { targetCredentials = strProxyCredentials; } // Get the secure flag if specified String secure = servletConfig.getInitParameter("targetSsl"); if (secure != null && secure.length() > 0) { targetSsl = "true".equalsIgnoreCase(secure); } // Get the proxy path if specified String stringProxyPathNew = servletConfig.getInitParameter("proxyPath"); if (stringProxyPathNew != null && stringProxyPathNew.length() > 0) { proxyPath = stringProxyPathNew; } String strPrefixPath = servletConfig.getInitParameter("prefixPath"); if (strPrefixPath != null && strPrefixPath.length() > 0) { stringPrefixPath = strPrefixPath; } String strMimeType = servletConfig.getInitParameter("mimeType"); if (strMimeType != null && strMimeType.length() > 0) { stringMimeType = strMimeType; } String strForwardTypes = servletConfig.getInitParameter("forwardTypes"); if (strForwardTypes != null && strForwardTypes.length() > 0) { stringForwardTypes = strForwardTypes.split(","); } String strRemovePrexif = servletConfig.getInitParameter("removePrefix"); if (strRemovePrexif != null && strRemovePrexif.length() > 0) { removePrefix = Boolean.valueOf(strRemovePrexif); } // Get the maximum file upload size if specified String stringMaxFileUploadSize = servletConfig.getInitParameter("maxFileUploadSize"); if (stringMaxFileUploadSize != null && stringMaxFileUploadSize.length() > 0) { maxFileUploadSize = Integer.parseInt(stringMaxFileUploadSize); } String strSourcePath = servletConfig.getInitParameter("sourcePath"); if (strSourcePath != null && strSourcePath.length() > 0) { stringSourcePath = strSourcePath; } String strDestinationPath = servletConfig.getInitParameter("destinationPath"); if (strDestinationPath != null && strDestinationPath.length() > 0) { stringDestinationPath = strDestinationPath; } }
From source file:com.qlkh.client.server.proxy.ProxyServlet.java
/** * Initialize the <code>ProxyServlet</code> * * @param servletConfig The Servlet configuration passed in by the servlet container *//*w ww. j a v a 2 s .c o m*/ public void init(ServletConfig servletConfig) { // Get the proxy host String stringProxyHostNew = servletConfig.getInitParameter("proxyHost"); if (stringProxyHostNew == null || stringProxyHostNew.length() == 0) { throw new IllegalArgumentException("Proxy host not set, please set init-param 'proxyHost' in web.xml"); } this.setProxyHost(stringProxyHostNew); // Get the proxy port if specified String stringProxyPortNew = servletConfig.getInitParameter("proxyPort"); if (stringProxyPortNew != null && stringProxyPortNew.length() > 0) { this.setProxyPort(Integer.parseInt(stringProxyPortNew)); } // Get the proxy path if specified String stringProxyPathNew = servletConfig.getInitParameter("proxyPath"); if (stringProxyPathNew != null && stringProxyPathNew.length() > 0) { this.setProxyPath(stringProxyPathNew); } // Get the maximum file upload size if specified String stringMaxFileUploadSize = servletConfig.getInitParameter("maxFileUploadSize"); if (stringMaxFileUploadSize != null && stringMaxFileUploadSize.length() > 0) { this.setMaxFileUploadSize(Integer.parseInt(stringMaxFileUploadSize)); } }
From source file:net.oneandone.jasmin.main.Servlet.java
/** creates configuration. */ @Override//ww w .j av a 2 s . co m public void init(ServletConfig config) throws ServletException { World world; String str; try { world = new World(); configure(world, "http"); configure(world, "https"); str = config.getInitParameter("docroot"); docroot = Application.file(world, str != null ? str : config.getServletContext().getRealPath("")); docroot.checkDirectory(); LOG.info("home: " + world.getHome()); application = Application.load(world, config, docroot); LOG.info("docroot: " + docroot); } catch (RuntimeException | Error e) { error(null, "init", e); throw e; } catch (Exception e) { error(null, "init", e); throw new ServletException(e); } catch (Throwable e) { error(null, "init", e); throw new RuntimeException("unexpected throwable", e); } }
From source file:de.itsvs.cwtrpc.controller.RemoteServiceControllerServlet.java
@Override public void init(ServletConfig config) throws ServletException { final WebApplicationContext applicationContext; final RemoteServiceControllerConfig controllerConfig; String configBeanName;/*w w w . j a v a 2 s .c o m*/ String initParam; super.init(config); initParam = config.getInitParameter(SPRING_REQUEST_CONTEXT_ENABLED_INIT_PARAM); if (initParam != null) { setSpringRequestContextEnabled(Boolean.valueOf(initParam)); } else { setSpringRequestContextEnabled(DEFAULT_SPRING_REQUEST_CONTEXT_ENABLED); } if (log.isInfoEnabled()) { log.info("Spring request context initialization on every request: " + isSpringRequestContextEnabled()); } configBeanName = config.getInitParameter(CONFIG_BEAN_NAME_INIT_PARAM); if (configBeanName == null) { configBeanName = RemoteServiceControllerConfig.DEFAULT_BEAN_ID; } applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); if (log.isDebugEnabled()) { log.debug( "Resolving controller config with bean name '" + configBeanName + "' from application context"); } controllerConfig = applicationContext.getBean(configBeanName, RemoteServiceControllerConfig.class); setApplicationContext(applicationContext); setSerializationPolicyProvider(controllerConfig.getSerializationPolicyProvider()); setServiceConfigsByUri( Collections.unmodifiableMap(createPreparedRemoteServiceConfigBuilder().build(controllerConfig))); setUncaughtExceptions(getUncaughtExceptions(controllerConfig)); }
From source file:org.nunux.poc.portal.ProxyServlet.java
/** * Initialize the//from w w w . ja va2s . c o m * <code>ProxyServlet</code> * * @param servletConfig The Servlet configuration passed in by the servlet * container */ @Override public void init(ServletConfig servletConfig) { // Get the proxy host String stringProxyHostNew = servletConfig.getInitParameter("proxyHost"); if (stringProxyHostNew == null || stringProxyHostNew.length() == 0) { throw new IllegalArgumentException("Proxy host not set, please set init-param 'proxyHost' in web.xml"); } this.setProxyHost(stringProxyHostNew); // Get the proxy port if specified String stringProxyPortNew = servletConfig.getInitParameter("proxyPort"); if (stringProxyPortNew != null && stringProxyPortNew.length() > 0) { this.setProxyPort(Integer.parseInt(stringProxyPortNew)); } // Get the proxy path if specified String stringProxyPathNew = servletConfig.getInitParameter("proxyPath"); if (stringProxyPathNew != null && stringProxyPathNew.length() > 0) { this.setRemovePrefix(true); this.setProxyPath(stringProxyPathNew); } // Get the maximum file upload size if specified String stringMaxFileUploadSize = servletConfig.getInitParameter("maxFileUploadSize"); if (stringMaxFileUploadSize != null && stringMaxFileUploadSize.length() > 0) { this.setMaxFileUploadSize(Integer.parseInt(stringMaxFileUploadSize)); } }