Refine search
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; }
/** * 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()); }
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; }
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));
@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);
@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"); }
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); s = sc.getInitParameter(PROPERTY_SESSION_SUPPORT); if (s == null) { s = sc.getServletContext().getInitParameter(PROPERTY_SESSION_SUPPORT); boolean sessionSupport = Boolean.valueOf(s) || SessionSupport.initializationHint; config.setSupportSession(sessionSupport); if (sessionSupport && (sc.getServletContext().getMajorVersion() < 3 || !SessionSupport.initializationHint)) { logger.warn("SessionSupport error. Make sure you also define {} as a listener in web.xml, see https://github.com/Atmosphere/atmosphere/wiki/Enabling-HttpSession-Support", SessionSupport.class.getName());
@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/"); }
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(); cfg.getServletContext().setAttribute(factoryKey, factory); log("Storing the ServletContext in the scheduler context at key: " + servletCtxtKey); scheduler.getContext().put(servletCtxtKey, cfg.getServletContext());
when(config.getInitParameter("root")).thenReturn(getFileSystemRoot()); when(config.getServletContext()).thenReturn(context);
this.servletContext = config.getServletContext(); 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");
when(config.getInitParameter("root")).thenReturn(getFileSystemRoot() + "/foo.txt"); when(config.getServletContext()).thenReturn(context);
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(); cfg.getServletContext().setAttribute(factoryKey, factory); log("Storing the ServletContext in the scheduler context at key: " + servletCtxtKey); scheduler.getContext().put(servletCtxtKey, cfg.getServletContext());
when(config.getInitParameter("root")).thenReturn(getFileSystemRoot()); when(config.getServletContext()).thenReturn(context);
@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); }
@Test public void testGetNotModified() 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(IMAGE_RESOURCE); when(request.getRequestURI()).thenReturn("/foo" + IMAGE_RESOURCE); when(request.getContextPath()).thenReturn("/foo"); when(request.getDateHeader("If-Modified-Since")).thenReturn(getResourceAsFile(IMAGE_RESOURCE).lastModified()); ServletOutputStream stream = mock(ServletOutputStream.class); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(stream); servlet.service(request, response); verify(response).setStatus(HttpServletResponse.SC_NOT_MODIFIED); verifyZeroInteractions(stream); }
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())); }
public ResteasyServletConfig(ServletConfig config) { this.classLoader = Thread.currentThread().getContextClassLoader(); this.servletName = config.getServletName(); this.servletContext = config.getServletContext(); this.initParams = new HashMap<>(); Enumeration e = config.getInitParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); initParams.put(name, config.getInitParameter(name)); } }
@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"); _subcontext = servletConfig.getInitParameter("sub-context"); if (_subcontext == null) { _subcontext = getServletName(); } servlet = (Servlet)InstanceFactory.newInstance( classLoader, servletClass); if (!(servlet instanceof HttpServlet)) { throw new IllegalArgumentException( "servlet-class is not an instance of " + HttpServlet.class.getName()); } servlet.init(servletConfig); PortalDelegatorServlet.addDelegate(_subcontext, (HttpServlet)servlet); }
@Override protected void loadBus(ServletConfig servletConfig) { ApplicationContext wac = WebApplicationContextUtils. getWebApplicationContext(servletConfig.getServletContext()); String configLocation = servletConfig.getInitParameter("config-location"); if (configLocation == null) { try { InputStream is = servletConfig.getServletContext().getResourceAsStream("/WEB-INF/cxf-servlet.xml"); if (is != null && is.available() > 0) { is.close(); String busParam = servletConfig.getInitParameter(BUS_PARAMETER); String busName = busParam == null ? "cxf" : busParam.trim();