public String getInitParameter(String name) { String param = initParams.get(name); if (param == null) { param = sc.getInitParameter(name); if (param == null && useServletContextParameters) { param = sc.getServletContext().getInitParameter(name); } } return param; }
/** * Create new ServletConfigPropertyValues. * @param config the ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } } }
@Override public void init() throws ServletException { format = getServletConfig().getInitParameter("outputFormat"); if (format == null || format.trim().isEmpty()) { throw new ServletException("Invalid outputFormat setting."); String spacingStr = getServletConfig().getInitParameter("preserveSpacing"); if (spacingStr == null || spacingStr.trim().isEmpty()) { throw new ServletException("Invalid preserveSpacing setting."); CRFClassifier model = null; String filename = "/WEB-INF/data/models/" + classifier; InputStream is = getServletConfig().getServletContext().getResourceAsStream(filename); throw new ServletException("File not found. Filename = " + filename);
/** * Initializes the servlet from hints the container passes. * <p> * Delegates to sub-init methods and parses the following parameters: * <ul> * <li> <tt>"generatedBy"</tt> : boolean, appends "Generated by ..." to the * HTML response text generated by this servlet. * </li> * </ul> * * @param config Passed by the servlet container. * @throws ServletException if this method encountered difficulties * @see TemplateServlet#initTemplateEngine(ServletConfig) */ public void init(ServletConfig config) throws ServletException { super.init(config); this.engine = initTemplateEngine(config); if (engine == null) { throw new ServletException("Template engine not instantiated."); } String value = config.getInitParameter("generated.by"); if (value != null) { this.generateBy = Boolean.valueOf(value); } value = config.getInitParameter(GROOVY_SOURCE_ENCODING); if (value != null) { this.fileEncodingParamVal = value; } log("Servlet " + getClass().getName() + " initialized on " + engine.getClass()); }
/** * Initializes the servlet. */ public void init(ServletConfig config) throws ServletException { super.init(config); connectString = config.getInitParameter("connectString"); Enumeration initParameterNames = config.getInitParameterNames(); while (initParameterNames.hasMoreElements()) { String name = (String) initParameterNames.nextElement(); String value = config.getInitParameter(name); MondrianProperties.instance().setProperty(name, value); } locator = new ServletContextCatalogLocator(config.getServletContext()); }
String s = sc.getInitParameter(PROPERTY_NATIVE_COMETSUPPORT); if (s != null) { useNativeImplementation = Boolean.parseBoolean(s); if (useNativeImplementation) isCometSupportSpecified = true; s = sc.getInitParameter(PROPERTY_USE_STREAM); if (s != null) { useStreamForFlushingComments = Boolean.parseBoolean(s); s = sc.getInitParameter(PROPERTY_COMET_SUPPORT); if (asyncSupport == null && s != null && !reconfigure) { asyncSupport = new DefaultAsyncSupportResolver(config).newCometSupport(s); isCometSupportSpecified = true; s = sc.getInitParameter(BROADCASTER_CLASS); if (s != null) { broadcasterClassName = s; isBroadcasterSpecified = true; s = sc.getInitParameter(BROADCASTER_CACHE); if (s != null) { broadcasterCacheClassName = s; s = sc.getInitParameter(PROPERTY_SESSION_SUPPORT); if (s == null) { s = sc.getServletContext().getInitParameter(PROPERTY_SESSION_SUPPORT); s = sc.getInitParameter(PROPERTY_ALLOW_SESSION_TIMEOUT_REMOVAL); if (s != null) {
@Override public void init() throws ServletException { ServletConfig config = getServletConfig(); String endpoint = config.getInitParameter(ENDPOINT); if (endpoint == null) { throw new ServletException("init-param '" + ENDPOINT + "' must be specified."); throw e; } catch (Exception e) { throw new ServletException("Failed to parse an endpoint.", e); throw e; } catch (Exception e) { throw new ServletException("Failed to create a channel factory.", e); String temp = config.getInitParameter(CONNECT_ATTEMPTS); if (temp != null) { try { temp = config.getInitParameter(RETRY_DELAY); if (temp != null) { try {
String value = config.getInitParameter("verbose"); if (value != null) { this.verbose = Boolean.valueOf(value); value = config.getInitParameter("encoding"); if (value != null) { this.encoding = value; String regex = config.getInitParameter(INIT_PARAM_RESOURCE_NAME_REGEX); if (regex != null) { String replacement = config.getInitParameter("resource.name.replacement"); if (replacement == null) { Exception npex = new NullPointerException("resource.name.replacement"); String message = "Init-param 'resource.name.replacement' not specified!"; log(message, npex); throw new ServletException(message, npex); } else if ("EMPTY_STRING".equals(replacement)) {//<param-value></param-value> is prohibited replacement = ""; String flagsStr = config.getInitParameter(INIT_PARAM_RESOURCE_NAME_REGEX_FLAGS); if (flagsStr != null && flagsStr.length() > 0) { String all = config.getInitParameter("resource.name.replace.all"); if (all != null) { this.resourceNameReplaceAll = Boolean.valueOf(all.trim()); value = config.getInitParameter("logGROOVY861"); if (value != null) { this.logGROOVY861 = Boolean.valueOf(value);
final ServletContext context = getServletConfig().getServletContext(); for (final Enumeration<String> e = context.getInitParameterNames(); e .hasMoreElements();) { final String name = e.nextElement(); initParameters.setProperty(name, getServletConfig().getInitParameter(name));
/** * Create new ServletConfigPropertyValues. * @param config the ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } } }
public AtmosphereFrameworkInitializer configureFramework(ServletConfig sc, boolean init, boolean useNative, Class<? extends AtmosphereFramework> frameworkClass) throws ServletException { if (framework == null) { if (sc.getServletContext().getMajorVersion() > 2) { try { framework = (AtmosphereFramework) sc.getServletContext() .getAttribute(sc.getServletContext().getServletRegistration(sc.getServletName()).getName()); } catch (Exception ex) { // Equinox throw an exception (NPE) // WebLogic Crap => https://github.com/Atmosphere/atmosphere/issues/1569 if (UnsupportedOperationException.class.isAssignableFrom(ex.getClass())) { logger.warn("WebLogic 12c unable to retrieve Servlet. Please make sure your servlet-name is 'AtmosphereServlet' " + "or set org.atmosphere.servlet to the current value"); String name = sc.getInitParameter(ApplicationConfig.SERVLET_NAME); if (name == null) { name = AtmosphereServlet.class.getSimpleName(); } framework = (AtmosphereFramework) sc.getServletContext().getAttribute(name); } else { logger.trace("", ex); } } } if (framework == null) { framework = newAtmosphereFramework(frameworkClass, isFilter, autoDetectHandlers); } } framework.setUseNativeImplementation(useNative); if (init) framework.init(sc); return this; }
return; String cfgFile = getServletConfig().getInitParameter(cfgFilePathParam); throw new ServletException("Failed to read property: " + cfgFilePathParam); throw new ServletException("Failed to find Spring configuration file (path provided should be " + "either absolute, relative to IGNITE_HOME, or relative to META-INF folder): " + cfgFile); throw new ServletException("Failed to find a single grid factory configuration in: " + cfgUrl);
try { String configFile = cfg.getInitParameter("config-file"); String shutdownPref = cfg.getInitParameter("shutdown-on-unload"); String shutdownWaitPref = cfg.getInitParameter("wait-on-shutdown"); if (shutdownPref != null) { waitOnShutdown = Boolean.valueOf(shutdownWaitPref).booleanValue(); .getInitParameter("start-scheduler-on-load"); String startDelayS = cfg.getInitParameter("start-delay-seconds"); try { if(startDelayS != null && startDelayS.trim().length() > 0) String factoryKey = cfg.getInitParameter("servlet-context-factory-key"); if (factoryKey == null) { factoryKey = QUARTZ_FACTORY_KEY; cfg.getServletContext().setAttribute(factoryKey, factory); String servletCtxtKey = cfg.getInitParameter("scheduler-context-servlet-context-key"); if (servletCtxtKey != null) { log("Storing the ServletContext in the scheduler context at key: " + servletCtxtKey); scheduler.getContext().put(servletCtxtKey, cfg.getServletContext()); throw new ServletException(e);
@Test public void testNotFound() throws ServletException, IOException { StaticContentServlet servlet = new StaticContentServlet(); ServletContext context = mock(ServletContext.class); when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("image/jpeg"); ServletConfig config = mock(ServletConfig.class); when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root"))); when(config.getInitParameter("root")).thenReturn(getFileSystemRoot()); when(config.getServletContext()).thenReturn(context); servlet.init(config); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn("GET"); when(request.getPathInfo()).thenReturn("/missing.jpg"); when(request.getRequestURI()).thenReturn("/foo/missing.jpg"); when(request.getContextPath()).thenReturn("/foo"); HttpServletResponse response = mock(HttpServletResponse.class); servlet.service(request, response); verify(response).sendError(HttpServletResponse.SC_NOT_FOUND, "/foo/missing.jpg"); }
@Override protected void doPortalInit() throws Exception { ServletContext servletContext = servletConfig.getServletContext(); ClassLoader classLoader = (ClassLoader)servletContext.getAttribute( PluginContextListener.PLUGIN_CLASS_LOADER); String servletClass = servletConfig.getInitParameter("servlet-class"); servlet = (Servlet)InstanceFactory.newInstance( classLoader, servletClass); servlet.init(servletConfig); }
servletConfig.getInitParameter(OLAP_DRIVER_CLASS_NAME_PARAM); final String olap4jDriverConnectionString = servletConfig.getInitParameter(OLAP_DRIVER_CONNECTION_STRING_PARAM); final String olap4jUsePreConfiguredDiscoverDatasourcesRes = servletConfig.getInitParameter( OLAP_DRIVER_PRECONFIGURED_DISCOVER_DATASOURCES_RESPONSE); boolean hardcodedDiscoverDatasources = servletConfig.getInitParameter( OLAP_DRIVER_IDLE_CONNECTIONS_TIMEOUT_MINUTES); final int idleConnectionsCleanupTimeoutMs = servletConfig.getInitParameter( OLAP_DRIVER_MAX_NUM_CONNECTIONS_PER_USER); int maxNumConnectionsPerUser = + "[" + olap4jDriverClassName + "]"; LOGGER.error(msg, ex); throw new ServletException(msg, ex);
try { String configFile = cfg.getInitParameter("config-file"); String shutdownPref = cfg.getInitParameter("shutdown-on-unload"); String shutdownWaitPref = cfg.getInitParameter("wait-on-shutdown"); if (shutdownPref != null) { waitOnShutdown = Boolean.valueOf(shutdownWaitPref).booleanValue(); .getInitParameter("start-scheduler-on-load"); String startDelayS = cfg.getInitParameter("start-delay-seconds"); try { if(startDelayS != null && startDelayS.trim().length() > 0) String factoryKey = cfg.getInitParameter("servlet-context-factory-key"); if (factoryKey == null) { factoryKey = QUARTZ_FACTORY_KEY; cfg.getServletContext().setAttribute(factoryKey, factory); String servletCtxtKey = cfg.getInitParameter("scheduler-context-servlet-context-key"); if (servletCtxtKey != null) { log("Storing the ServletContext in the scheduler context at key: " + servletCtxtKey); scheduler.getContext().put(servletCtxtKey, cfg.getServletContext()); throw new ServletException(e);
@Test public void testDirectoryListingForbidden() throws ServletException, IOException { StaticContentServlet servlet = new StaticContentServlet(); ServletContext context = mock(ServletContext.class); when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("image/png"); ServletConfig config = mock(ServletConfig.class); when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root"))); when(config.getInitParameter("root")).thenReturn(getFileSystemRoot()); when(config.getServletContext()).thenReturn(context); servlet.init(config); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn("GET"); when(request.getPathInfo()).thenReturn("/"); // Attempt directory listing when(request.getRequestURI()).thenReturn("/foo/"); // Attempt directory listing when(request.getContextPath()).thenReturn("/foo"); ServletOutputStream stream = mock(ServletOutputStream.class); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(stream); servlet.service(request, response); verify(response).sendError(HttpServletResponse.SC_FORBIDDEN, "/foo/"); }
protected void registerServletContextResolver(ServletConfig sc) { if (Boolean.valueOf(sc.getInitParameter(IGNORE_SERVLET_CONTEXT_RESOLVER))) { return; } ResourceManager resourceManager = bus.getExtension(ResourceManager.class); resourceManager.addResourceResolver(new ServletContextResourceResolver(sc.getServletContext())); }
protected void serveStaticContent(HttpServletRequest request, HttpServletResponse response, String pathInfo) throws ServletException { InputStream is = getResourceAsStream(pathInfo); if (is == null) { throw new ServletException("Static resource " + pathInfo + " is not available"); } try { int ind = pathInfo.lastIndexOf("."); if (ind != -1 && ind < pathInfo.length()) { String type = getStaticResourceContentType(pathInfo.substring(ind + 1)); if (type != null) { response.setContentType(type); } } String cacheControl = getServletConfig().getInitParameter(STATIC_CACHE_CONTROL); if (cacheControl != null) { response.setHeader("Cache-Control", cacheControl.trim()); } ServletOutputStream os = response.getOutputStream(); IOUtils.copyAndCloseInput(is, os); os.flush(); } catch (IOException ex) { throw new ServletException("Static resource " + pathInfo + " can not be written to the output stream"); } }