List of usage examples for javax.servlet ServletConfig getInitParameter
public String getInitParameter(String name);
From source file:org.aselect.server.request.handler.xsaml20.Saml20_Metadata.java
@Override public void init(ServletConfig oServletConfig, Object oConfig) throws ASelectException { String sMethod = "init"; try {//w ww. ja v a 2 s .c o m super.init(oServletConfig, oConfig); try { _systemLogger.log(Level.INFO, MODULE, sMethod, "Saml Bootstrap"); DefaultBootstrap.bootstrap(); } catch (ConfigurationException e) { _systemLogger.log(Level.WARNING, MODULE, sMethod, "OpenSAML library could not be initialized", e); throw new ASelectException(Errors.ERROR_ASELECT_INIT_ERROR, e); } _systemLogger.log(Level.FINEST, MODULE, sMethod, "Bootstrap done"); _oBuilderFactory = org.opensaml.xml.Configuration.getBuilderFactory(); setWorkingDir(oServletConfig.getInitParameter("working_dir")); // from web.xml! _systemLogger.log(Level.FINEST, MODULE, sMethod, "Working directory: " + getWorkingDir()); Object oASelect = null; try { oASelect = _configManager.getSection(null, "aselect"); setRedirectURL(_configManager.getParam(oASelect, "redirect_url")); // redirect_url will be used as entityIdIdp in metadata setEntityIdIdp(_configManager.getParam(oASelect, "redirect_url")); String sValidUntil = ASelectConfigManager.getSimpleParam(oConfig, "valid_until", false); if (sValidUntil != null) { setValidUntil(new Long(Long.parseLong(sValidUntil) * 1000)); } String sCacheDuration = ASelectConfigManager.getSimpleParam(oConfig, "cache_duration", false); if (sCacheDuration != null) { setCacheDuration(new Long(Long.parseLong(sCacheDuration) * 1000)); } } catch (ASelectConfigException e) { _systemLogger.log(Level.WARNING, MODULE, sMethod, "No config item 'redirect_url' in section 'aselect' found", e); throw new ASelectException(Errors.ERROR_ASELECT_INIT_ERROR, e); } } catch (ASelectException e) { throw e; } catch (Exception e) { _systemLogger.log(Level.SEVERE, MODULE, sMethod, "Could not initialize", e); throw new ASelectException(Errors.ERROR_ASELECT_INTERNAL_ERROR, e); } }
From source file:com.kurento.kmf.repository.internal.http.RepositoryHttpServlet.java
/** * Initialize this servlet./*from w w w . ja v a2s . c o m*/ */ @Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); configureKurentoAppContext(servletConfig); configureServletMapping(servletConfig); configureWebappPublicURL(servletConfig); if (servletConfig.getInitParameter("debug") != null) { debug = Integer.parseInt(getServletConfig().getInitParameter("debug")); } }
From source file:net.jawr.web.bundle.processor.BundleProcessor.java
/** * Create the image bundle/*from w w w . ja v a 2s . c o m*/ * * @param servlet * the servlet * @param binaryRsHandler * the binary resource handler * @param destDirPath * the destination directory path * @param servletMapping * the mapping * @param keepUrlMapping * = the flag indicating if we must keep the url mapping * @throws IOException * if an IOExceptin occurs * @throws ServletException * if an exception occurs */ protected void createBinaryBundle(HttpServlet servlet, BinaryResourcesHandler binaryRsHandler, String destDirPath, ServletConfig servletConfig, boolean keepUrlMapping) throws IOException, ServletException { Map<String, String> bundleImgMap = binaryRsHandler.getBinaryPathMap(); Iterator<String> bundleIterator = bundleImgMap.values().iterator(); MockServletResponse response = new MockServletResponse(); MockServletRequest request = new MockServletRequest(JAWR_BUNDLE_PROCESSOR_CONTEXT_PATH); String jawrServletMapping = servletConfig.getInitParameter(JawrConstant.SERVLET_MAPPING_PROPERTY_NAME); if (jawrServletMapping == null) { jawrServletMapping = ""; } String servletMapping = servletConfig.getInitParameter(JawrConstant.SPRING_SERVLET_MAPPING_PROPERTY_NAME); if (servletMapping == null) { servletMapping = jawrServletMapping; } // For the list of bundle defines, create the file associated while (bundleIterator.hasNext()) { String path = (String) bundleIterator.next(); String binaryFinalPath = null; if (keepUrlMapping) { binaryFinalPath = path; } else { binaryFinalPath = getImageFinalPath(path, binaryRsHandler.getConfig()); } File destFile = new File(destDirPath, binaryFinalPath); Map<String, String> variantMap = new HashMap<String, String>(); setRequestUrl(request, variantMap, path, binaryRsHandler.getConfig()); // Update the bundle mapping path = PathNormalizer.concatWebPath(PathNormalizer.asDirPath(jawrServletMapping), path); createBundleFile(servlet, response, request, path, destFile, servletMapping); } }
From source file:org.danann.cernunnos.runtime.web.CernunnosServlet.java
@SuppressWarnings("unchecked") @Override/*from w w w. j a va2 s. c o m*/ public void init() throws ServletException { ServletConfig config = getServletConfig(); // Load the context, if present... try { // Bootstrap the servlet Grammar instance... final Grammar root = XmlGrammar.getMainGrammar(); final InputStream inpt = CernunnosServlet.class.getResourceAsStream("servlet.grammar"); // Can't rely on classpath:// protocol handler... final Document doc = new SAXReader().read(inpt); final Task k = new ScriptRunner(root).compileTask(doc.getRootElement()); final RuntimeRequestResponse req = new RuntimeRequestResponse(); final ReturnValueImpl rslt = new ReturnValueImpl(); req.setAttribute(Attributes.RETURN_VALUE, rslt); k.perform(req, new RuntimeRequestResponse()); Grammar g = (Grammar) rslt.getValue(); runner = new ScriptRunner(g); // Choose a context location & load it if it exists... String defaultLoc = "/WEB-INF/" + config.getServletName() + "-portlet.xml"; URL defaultUrl = getServletConfig().getServletContext().getResource(defaultLoc); URL u = Settings.locateContextConfig( getServletConfig().getServletContext().getResource("/").toExternalForm(), config.getInitParameter(CONFIG_LOCATION_PARAM), defaultUrl); if (u != null) { // There *is* a resource mapped to this path name... spring_context = new FileSystemXmlApplicationContext(u.toExternalForm()); } if (log.isDebugEnabled()) { log.debug("Location of spring context (null means none): " + u); } // Load the Settings... Map<String, String> settingsMap = new HashMap<String, String>(); // default... if (spring_context != null && spring_context.containsBean("settings")) { settingsMap = (Map<String, String>) spring_context.getBean("settings"); } settings = Settings.load(settingsMap); } catch (Throwable t) { String msg = "Failure in CernunnosServlet.init()"; throw new ServletException(msg, t); } }
From source file:com.naryx.tagfusion.cfm.engine.cfEngine.java
/** * ------------------------------------------------------ * Initialisation method//from w w w .j ava 2 s .co m * * Run once and initialises all the sub-components of the main engine */ private cfEngine(ServletConfig config) throws ServletException { thisInstance = this; thisServletContext = config.getServletContext(); // Setup the main marker class for the platform flag String bluedragonXmlParm = config.getInitParameter("BLUEDRAGON_XML"); try { thisPlatform = (Platform) Class.forName("com.bluedragon.platform.java.JavaPlatform").newInstance(); if ((bluedragonXmlParm != null) && (bluedragonXmlParm.length() > 0)) xmlFileLocation = getOpenBDXmlFile(bluedragonXmlParm); } catch (Exception e) { throw new ServletException(PRODUCT_NAME + ": " + e); } // Load in the main XML configuration file try { setSystemParameters(xmlConfigManagerFactory.createXmlConfigManager(xmlFileLocation).getXMLCFML()); engineListeners = new Vector<engineListener>(); } catch (Exception E) { thisInstance = null; System.out.println(PRODUCT_NAME + ": Error " + E + " loading: BLUEDRAGON_XML=" + bluedragonXmlParm); throw new ServletException( PRODUCT_NAME + ": Error occurred loading: BLUEDRAGON_XML=" + bluedragonXmlParm + ", " + E); } // Load in the image try { InputStream in = this.getClass().getResourceAsStream("openbdlogo.txt"); if (in != null) OpenBDLogoDataUri = StreamUtils.readToString(in); } catch (NullPointerException e1) { OpenBDLogoDataUri = null; } catch (IOException e1) { OpenBDLogoDataUri = null; } // Initialise the Platform thisPlatform.init(config); // Get a handle to the underlying FileSystem manager vfsManager = thisPlatform.getFileIO().vfsManager(); // Initialize the Datasource dataSourcePoolFactory = new DataSourcePoolFactory(); try { // Load up the runtimeErrorMessages runtimeMessages = ResourceBundle.getBundle("com.naryx.tagfusion.cfm.engine.exceptionMessage"); log(runtimeMessages.getString("cfEngine.welcomeMessage")); log("Product Version: " + PRODUCT_VERSION); log("Build date: " + BUILD_ISSUE); // TagChecker TagChecker = new tagChecker(); // Core Expression expressionEngine.init(); // fileCache initialisation cfmlFileCache.init(thisServletContext, getSystemParameters()); // CFX initalization com.naryx.tagfusion.cfx.cfCFX.init(getSystemParameters()); // CFCs ComponentFactory.init(getSystemParameters()); startTime = System.currentTimeMillis(); } catch (Exception E) { log(PRODUCT_NAME + " Engine Failed to load:" + E.getMessage()); E.printStackTrace(); thisInstance = null; throw new ServletException("Failed to initialise the cfEngine: " + E.getMessage()); } // Create the plugin Manager and load up any extensions pluginManager = new PluginManager(getSystemParameters()); // Set the Default Character set setDefaultCharset(); // Set the Web Resource path setWebResourcePath(); // Set the native library path; must be done before tags are initialised setNativeLibDirectory(); // Initialise any of the tags try { TagChecker.initialiseTags(getSystemParameters()); } catch (Throwable t) { t.printStackTrace(); thisInstance = null; log(PRODUCT_NAME + " Engine Failed to initialise tags:" + t.getMessage()); com.nary.Debug.printStackTrace(t); throw new ServletException(PRODUCT_NAME + " Engine Failed to initialise tags: " + t.getMessage()); } // Set the startup engine flags String ipList = getSystemParameters().getString("server.debugoutput.ipaddresses"); if ((ipList == null) || (ipList.length() == 0)) debugIPsAsInts = new int[0]; else debugIPsAsInts = cfSession.DecodeIPs(ipList); setDebugOutputFlag(); setScriptProtectFlag(); setStrictFlags(); setAssertionsFlag(); setCombinedFormUrlFlag(); setLegacyFormValidation(); setSuppressWhiteSpace(); setDefaultBufferSize(); setDefaultJSONFlags(); setFormUrlCaseMaintainedFlag(); setCFOutpuShorthand(); // Only update the bluedragon.xml file if flagged to do so if (getSystemParameters().getBoolean("server.system.rewritebluedragonxml", true) && !bluedragonXmlParm.startsWith("http")) { try { writeXmlFile(getSystemParameters(), false); } catch (cfmRunTimeException e) { log(PRODUCT_NAME + " " + e.getMessage()); } } // Auto-configure ODBC datasources (notifyListeners=false, autoConfig=true) autoConfigOdbcDataSources(false, true); // Setup/clean the dynamic web service cache (and any other resources) try { cfWebServices.initialize(config); } catch (Exception e) { throw new ServletException( PRODUCT_NAME + " Engine Failed to initialise Web Services: " + e.getMessage()); } startRequestStats(); // Setup the Journal Manager journalManager = new JournalManager(); log(runtimeMessages.getString("cfEngine.serverStarted")); // The Engine is ready for requests, so lets call the ServerCFC handling new ServerCFC().onServerStart(getSystemParameters()); }
From source file:org.apache.tapestry.request.RequestContext.java
/** * Writes the state of the context to the writer, typically for inclusion * in a HTML page returned to the user. This is useful * when debugging. The Inspector uses this as well. * **///from w w w. j a v a 2 s.c om public void write(IMarkupWriter writer) { // Create a box around all of this stuff ... writer.begin("table"); writer.attribute("class", "request-context-border"); writer.begin("tr"); writer.begin("td"); // Get the session, if it exists, and display it. HttpSession session = getSession(); if (session != null) { object(writer, "Session"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "id", session.getId()); datePair(writer, "creationTime", session.getCreationTime()); datePair(writer, "lastAccessedTime", session.getLastAccessedTime()); pair(writer, "maxInactiveInterval", session.getMaxInactiveInterval()); pair(writer, "new", session.isNew()); List names = getSorted(session.getAttributeNames()); int count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, session.getAttribute(name)); } writer.end(); // Session } object(writer, "Request"); writer.begin("table"); writer.attribute("class", "request-context-object"); // Parameters ... List parameters = getSorted(_request.getParameterNames()); int count = parameters.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Parameters"); header(writer, "Name", "Value(s)"); } String name = (String) parameters.get(i); String[] values = _request.getParameterValues(name); writer.begin("tr"); writer.attribute("class", getRowClass()); writer.begin("th"); writer.print(name); writer.end(); writer.begin("td"); if (values.length > 1) writer.begin("ul"); for (int j = 0; j < values.length; j++) { if (values.length > 1) writer.beginEmpty("li"); writer.print(values[j]); } writer.end("tr"); } section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "authType", _request.getAuthType()); pair(writer, "characterEncoding", _request.getCharacterEncoding()); pair(writer, "contentLength", _request.getContentLength()); pair(writer, "contentType", _request.getContentType()); pair(writer, "method", _request.getMethod()); pair(writer, "pathInfo", _request.getPathInfo()); pair(writer, "pathTranslated", _request.getPathTranslated()); pair(writer, "protocol", _request.getProtocol()); pair(writer, "queryString", _request.getQueryString()); pair(writer, "remoteAddr", _request.getRemoteAddr()); pair(writer, "remoteHost", _request.getRemoteHost()); pair(writer, "remoteUser", _request.getRemoteUser()); pair(writer, "requestedSessionId", _request.getRequestedSessionId()); pair(writer, "requestedSessionIdFromCookie", _request.isRequestedSessionIdFromCookie()); pair(writer, "requestedSessionIdFromURL", _request.isRequestedSessionIdFromURL()); pair(writer, "requestedSessionIdValid", _request.isRequestedSessionIdValid()); pair(writer, "requestURI", _request.getRequestURI()); pair(writer, "scheme", _request.getScheme()); pair(writer, "serverName", _request.getServerName()); pair(writer, "serverPort", _request.getServerPort()); pair(writer, "contextPath", _request.getContextPath()); pair(writer, "servletPath", _request.getServletPath()); // Now deal with any headers List headers = getSorted(_request.getHeaderNames()); count = headers.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Headers"); header(writer, "Name", "Value"); } String name = (String) headers.get(i); String value = _request.getHeader(name); pair(writer, name, value); } // Attributes List attributes = getSorted(_request.getAttributeNames()); count = attributes.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) attributes.get(i); pair(writer, name, _request.getAttribute(name)); } // Cookies ... Cookie[] cookies = _request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (i == 0) { section(writer, "Cookies"); header(writer, "Name", "Value"); } Cookie cookie = cookies[i]; pair(writer, cookie.getName(), cookie.getValue()); } // Cookies loop } writer.end(); // Request object(writer, "Servlet"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "servlet", _servlet); pair(writer, "name", _servlet.getServletName()); pair(writer, "servletInfo", _servlet.getServletInfo()); ServletConfig config = _servlet.getServletConfig(); List names = getSorted(config.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Init Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); ; pair(writer, name, config.getInitParameter(name)); } writer.end(); // Servlet ServletContext context = config.getServletContext(); object(writer, "Servlet Context"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "majorVersion", context.getMajorVersion()); pair(writer, "minorVersion", context.getMinorVersion()); pair(writer, "serverInfo", context.getServerInfo()); names = getSorted(context.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Initial Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getInitParameter(name)); } names = getSorted(context.getAttributeNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getAttribute(name)); } writer.end(); // Servlet Context writeSystemProperties(writer); writer.end("table"); // The enclosing border }
From source file:org.theospi.portfolio.portal.web.XsltPortal.java
public void init(ServletConfig config) throws ServletException { super.init(config); setPortalManager((PortalManager) ComponentManager.get(PortalManager.class.getName() + ".tx")); try {/*from ww w.ja v a 2 s . co m*/ setDocumentBuilder(DocumentBuilderFactory.newInstance().newDocumentBuilder()); String transformPath = config.getInitParameter("transform"); Templates templates = createTemplate(config, transformPath); setTemplates(templates); String transformToolCategoryPath = config.getInitParameter("transformToolCategory"); Templates templatesToolCategory = createTemplate(config, transformToolCategoryPath); setServletResolver(new PortalResourceUriResolver(getPortalManager(), config.getServletContext())); setToolCategoryTemplates(templatesToolCategory); categoryBasePath = config.getInitParameter("categoryBasePath"); if (categoryBasePath == null || categoryBasePath.length() == 0) { categoryBasePath = "/WEB-INF/category"; } Collection categoriesNeedingLoading = getPortalManager().getCategoriesInNeedOfFiles(); if (categoriesNeedingLoading != null) { for (Iterator<ToolCategory> i = categoriesNeedingLoading.iterator(); i.hasNext();) { processCategoryFiles(i.next(), config.getServletContext()); } getPortalManager().saveToolCategories(categoriesNeedingLoading); } } catch (ParserConfigurationException e) { throw new ServletException(e); } catch (TransformerConfigurationException e) { throw new ServletException(e); } catch (MalformedURLException e) { throw new ServletException(e); } catch (IOException e) { throw new ServletException(e); } }
From source file:org.apache.jetspeed.services.resources.VariableResourcesService.java
/** * Initializer method that sets up the generic resources. * * @param confs A Configurations object. */// w ww .ja va2s . c o m private void initVariables(ServletConfig config) { ServletContext ctxt = config.getServletContext(); String path = ctxt.getRealPath("/"); // define web app dir if (path != null) { variables.put(WEBAPP_DIR, normalizePath(path)); } // FIXME. the following code blocks on Tomcat // when loaded on startup /* path = ctxt.getContext("/").getRealPath("/"); if (path != null ) { variables.put(WEB_DIR, normalizePath(path) ); } */ // define JVM app dir try { path = new File(".").getCanonicalPath(); if (path != null) { variables.put(JVM_DIR, normalizePath(path)); } } catch (IOException e) { //very unlikely that the JVM can't //resolve its path //But logging it anyway... logger.error("Exception define JVM app dir", e); } // load servlet init parameters as variables, they may override // the previously defined variables. All param names are folded // to lower case Enumeration en = config.getInitParameterNames(); while (en.hasMoreElements()) { String paramName = (String) en.nextElement(); String paramValue = config.getInitParameter(paramName); variables.put(paramName.toLowerCase(), paramValue); } }
From source file:org.exist.http.urlrewrite.XQueryURLRewrite.java
@Override public void init(ServletConfig filterConfig) throws ServletException { // save FilterConfig for later use this.config = filterConfig; query = filterConfig.getInitParameter("xquery"); // String opt = filterConfig.getInitParameter("check-modified"); // if (opt != null) // checkModified = opt != null && opt.equalsIgnoreCase("true"); final String opt = filterConfig.getInitParameter("compiled-cache"); if (opt != null) { compiledCache = opt != null && opt.equalsIgnoreCase("true"); }/*w w w .ja v a 2 s . c o m*/ }
From source file:org.getobjects.servlets.WOServletAdaptor.java
@Override public void init(final ServletConfig _cfg) throws ServletException { // Jetty: org.mortbay.jetty.servlet.ServletHolder$Config@114024 super.init(_cfg); String an = this.valueFromServletConfig(_cfg, "WOAppName"); String ac = this.valueFromServletConfig(_cfg, "WOAppClass"); if (ac == null) ac = an;/*from ww w .j av a2s. co m*/ if (an == null && ac != null) { /* if only the class is set, we use the shortname of the class */ int dotidx = ac.lastIndexOf('.'); an = dotidx < 1 ? ac : ac.substring(dotidx + 1); } if (an == null) { log.warn("no WOAppName specified in servlet context: " + _cfg); an = WOApplication.class.getName(); } /* Construct properties for the volatile "domain" from servlet init * parameters and context init parameters and attributes. * It's probably best to have a real UserDefaults concept, but for the * time being this is better than nothing. */ final Properties properties = new Properties(); Enumeration parameterNamesEnum = _cfg.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); final String value = _cfg.getInitParameter(name); if (name != null && value != null) properties.put(name, value); else if (value == null) log.error("Got no value for init parameter: " + name); } /* The ServletContext may override the previous init parameters. * ServletContext init parameters will be overridden by attributes. */ final ServletContext sctx = _cfg.getServletContext(); if (sctx != null) { parameterNamesEnum = sctx.getInitParameterNames(); while (parameterNamesEnum.hasMoreElements()) { final String name = (String) parameterNamesEnum.nextElement(); properties.put(name, sctx.getInitParameter(name)); } final Enumeration attributeNamesEnum = sctx.getAttributeNames(); while (attributeNamesEnum.hasMoreElements()) { final String name = (String) attributeNamesEnum.nextElement(); properties.put(name, sctx.getAttribute(name)); } } this.initApplicationWithName(an, ac, properties); }