List of usage examples for javax.servlet FilterConfig getServletContext
public ServletContext getServletContext();
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponseTest.java
@Test public void testStreamResponse() throws IOException, MimeTypeParseException { UrlRewriteProcessor rewriter = EasyMock.createNiceMock(UrlRewriteProcessor.class); EasyMock.expect(rewriter.getConfig()).andReturn(null).anyTimes(); ServletContext context = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(context.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)) .andReturn(rewriter).anyTimes(); FilterConfig config = EasyMock.createNiceMock(FilterConfig.class); EasyMock.expect(config.getInitParameter(UrlRewriteServletFilter.RESPONSE_BODY_FILTER_PARAM)) .andReturn("test-filter").anyTimes(); EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes(); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.replay(rewriter, context, config, request, response); UrlRewriteResponse rewriteResponse = new UrlRewriteResponse(config, request, response); String content = "content to test gzip streaming"; testStreamResponseGzip(content, rewriteResponse, false); testStreamResponseGzip(content, rewriteResponse, true); }
From source file:org.vulpe.controller.filter.VulpeFilterDispatcher.java
/** * Initiate URL Rewrite Filter.//from w w w. jav a 2 s . c o m * * @param filterConfig * @throws ServletException */ private void initURLRewrite(final FilterConfig filterConfig) throws ServletException { URL_REWRITE_FILTER.init(filterConfig); final ServletContext context = filterConfig.getServletContext(); String confPath = filterConfig.getInitParameter("confPath"); if (StringUtils.isEmpty(confPath)) { confPath = UrlRewriteFilter.DEFAULT_WEB_CONF_PATH; } URL confUrl = null; try { confUrl = context.getResource(confPath); } catch (MalformedURLException e) { LOG.debug(e.getMessage()); } String confUrlStr = null; if (confUrl != null) { confUrlStr = confUrl.toString(); } final InputStream inputStream = context.getResourceAsStream(confPath); final Conf conf = new Conf(context, inputStream, confPath, confUrlStr, false); URL_REWRITER = new UrlRewriter(conf); }
From source file:io.milton.servlet.SpringMiltonFilter.java
@Override public void init(FilterConfig fc) throws ServletException { log.info("init"); initSpringApplicationContext(fc);//ww w.j ava2 s. c o m servletContext = fc.getServletContext(); String sExcludePaths = fc.getInitParameter(EXCLUDE_PATHS_SYSPROP); if (sExcludePaths != null) { log.info("init: exclude paths: " + sExcludePaths); excludeMiltonPaths = sExcludePaths.split(","); } else { log.info("init: exclude paths property has not been set in filter init param " + EXCLUDE_PATHS_SYSPROP); } Object milton = context.getBean("milton.http.manager"); if (milton instanceof HttpManager) { this.httpManager = (HttpManager) milton; } else if (milton instanceof HttpManagerBuilder) { HttpManagerBuilder builder = (HttpManagerBuilder) milton; ResourceFactory rf = builder.getMainResourceFactory(); if (rf instanceof AnnotationResourceFactory) { AnnotationResourceFactory arf = (AnnotationResourceFactory) rf; if (arf.getViewResolver() == null) { ViewResolver viewResolver = new JspViewResolver(servletContext); arf.setViewResolver(viewResolver); } } this.httpManager = builder.buildHttpManager(); } // init mail server if (context.containsBean("milton.mail.server")) { log.info("init mailserver..."); Object oMailServer = context.getBean("milton.mail.server"); if (oMailServer instanceof MailServer) { mailServer = (MailServer) oMailServer; } else if (oMailServer instanceof MailServerBuilder) { MailServerBuilder builder = (MailServerBuilder) oMailServer; mailServer = builder.build(); } else { throw new RuntimeException("Unsupported type: " + oMailServer.getClass() + " expected " + MailServer.class + " or " + MailServerBuilder.class); } log.info("starting mailserver"); mailServer.start(); } log.info("Finished init"); }
From source file:org.romaframework.web.RomaWebFilter.java
public void init(FilterConfig iConfig) throws ServletException { synchronized (getClass()) { long timeMillis = System.currentTimeMillis(); log.info("[RomaWebFilter.init] Starting up Roma v." + GlobalConstants.VERSION + "..."); // SET APPLICATION ABSOLUTE PATH String absolutePath = iConfig.getServletContext().getRealPath(Utility.PATH_SEPARATOR_STRING); log.info("[RomaWebFilter.init] ContextRoot: " + absolutePath); RomaApplicationContext.setApplicationPath(absolutePath); RomaApplicationContext.setResourceAccessor(new ServletResourceAccessor(iConfig.getServletContext())); // CONFIGURE ROMA APPLICATION CONTEXT try {/*from ww w.jav a2 s . com*/ RomaApplicationContext.getInstance().startup(); } catch (Exception e) { log.error("Error on starting up Roma", e); } timeMillis = System.currentTimeMillis() - timeMillis; log.info("[RomaWebFilter.init] Startup completed in " + new SimpleDateFormat("mm:ss.S").format(new Date(timeMillis)) + "."); } }
From source file:org.ecside.filter.ECSideFilter.java
public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; servletContext = filterConfig.getServletContext(); servletRealPath = servletContext.getRealPath("/"); initEncoding();/*from w w w. j a v a 2 s . c o m*/ initProperties(); String responseHeadersSetBeforeDoFilter = filterConfig .getInitParameter("responseHeadersSetBeforeDoFilter"); if (StringUtils.isNotBlank(responseHeadersSetBeforeDoFilter)) { ECSideFilter.responseHeadersSetBeforeDoFilter = Boolean.valueOf( responseHeadersSetBeforeDoFilter).booleanValue(); } }
From source file:org.craftercms.cstudio.share.servlet.ShareAuthenticationFilter.java
public void init(FilterConfig filterConfig) { this.servletContext = filterConfig.getServletContext(); ApplicationContext context = WebApplicationContextUtils .getRequiredWebApplicationContext(this.servletContext); /* retrieve the connector service */ this.connectorService = (ConnectorService) context.getBean("connector.service"); /* retrieve the cookie manager */ this.cookieManager = (CookieManager) context.getBean("rlCookieManager"); /* retrieve the user preference manager */ this.userPreferenceManager = (UserPreferenceManager) context.getBean("rlUserPreferenceManager"); this.enableRememberLastPage = new Boolean(filterConfig.getInitParameter("enableRememberLastPage")); this.defaultLastPage = filterConfig.getInitParameter("defaultRememberLastPage"); }
From source file:org.glite.slcs.acl.impl.XMLFileAccessControlList.java
public void init(FilterConfig filterConfig) throws SLCSException { // initialize the AttributeDefintions from the servlet context ServletContext context = filterConfig.getServletContext(); AttributeDefinitionsFactory.initialize(context); String filename = filterConfig.getInitParameter(ACLFILE_CONFIG_PARAM); LOG.info(ACLFILE_CONFIG_PARAM + "=" + filename); if (filename == null) { LOG.info("Parameter '" + ACLFILE_CONFIG_PARAM + "' is not defined, trying parameter '" + ACLFILE_CONTEXT_PARAM + "'"); String contextKey = filterConfig.getInitParameter(ACLFILE_CONTEXT_PARAM); LOG.info(ACLFILE_CONTEXT_PARAM + "=" + contextKey); if (contextKey != null) { filename = context.getInitParameter(contextKey); if (filename == null) { throw new SLCSConfigurationException( "Filter parameter ContextParamACLFile references a undefined Context parameter."); }/*from w w w. j a va2 s . c o m*/ LOG.debug("ACL filename=" + filename); } else { throw new SLCSConfigurationException("Filter parameter ACLFile or ContextParamACLFile not defined"); } } // load the XML file aclXMLConfiguration_ = createACLXMLConfiguration(filename); // create the access control rules list accessControlRules_ = createACLAccessControlRules(aclXMLConfiguration_); // deals with the FileConfigurationMonitor String monitoringInterval = filterConfig.getInitParameter("ACLFileMonitoringInterval"); if (monitoringInterval != null) { LOG.info("ACLFileMonitoringInterval=" + monitoringInterval); File file = aclXMLConfiguration_.getFile(); aclConfigurationMonitor_ = FileConfigurationMonitor.createFileConfigurationMonitor(file, monitoringInterval, this); // and start aclConfigurationMonitor_.start(); } }
From source file:org.ajax4jsf.resource.InternetResourceService.java
public void init(FilterConfig config) throws ServletException { filterConfig = config;/* ww w . j a va2 s .c o m*/ ServletContext servletContext = config.getServletContext(); if ("false".equalsIgnoreCase(config.getInitParameter(ENABLE_CACHING_PARAMETER))) { setCacheEnabled(false); // this.cacheEnabled = false; // this.cacheAdmin = null; } else { // this.cacheAdmin = ServletCacheAdministrator.getInstance( // servletContext, cacheProperties); try { CacheManager cacheManager = CacheManager.getInstance(); Map<String, String> env = new ServletContextInitMap(servletContext); CacheFactory cacheFactory = cacheManager.getCacheFactory(env); this.cache = cacheFactory.createCache(env, this, this); } catch (CacheException e) { throw new FacesException(e.getMessage(), e); } } // Create Resource-specific Faces Lifecycle instance. lifecycleClass = servletContext.getInitParameter(RESOURCE_LIFECYCLE_PARAMETER); if (lifecycleClass != null) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); try { Class<?> clazz = classLoader.loadClass(lifecycleClass); lifecycle = (ResourceLifecycle) clazz.newInstance(); } catch (Exception e) { throw new FacesException("Error create instance of resource Lifecycle " + lifecycleClass, e); } } else { lifecycle = new ResourceLifecycle(); } webXml = new WebXml(); webXml.init(servletContext, filterConfig.getFilterName()); if (log.isDebugEnabled()) { log.debug("Resources service initialized"); } }
From source file:io.milton.servlet.SpringMiltonFilter.java
@SuppressWarnings("resource") protected void initSpringApplicationContext(FilterConfig fc) { final WebApplicationContext rootContext = WebApplicationContextUtils .getWebApplicationContext(fc.getServletContext()); StaticApplicationContext parent;/*from www . jav a2 s .com*/ if (rootContext != null) { log.info("Found a root spring context, and using it"); parent = new StaticApplicationContext(rootContext); } else { log.info("No root spring context"); parent = new StaticApplicationContext(); } final FilterConfigWrapper configWrapper = new FilterConfigWrapper(fc); parent.getBeanFactory().registerSingleton("config", configWrapper); parent.getBeanFactory().registerSingleton("servletContext", fc.getServletContext()); File webRoot = new File(fc.getServletContext().getRealPath("/")); parent.getBeanFactory().registerSingleton("webRoot", webRoot); log.info("Registered root webapp path in: webroot=" + webRoot.getAbsolutePath()); parent.refresh(); final String configClass = fc.getInitParameter("contextConfigClass"); final String sFiles = fc.getInitParameter("contextConfigLocation"); ConfigurableApplicationContext ctx = null; if (StringUtils.isNotBlank(configClass)) { try { Class<?> clazz = Class.forName(configClass); final AnnotationConfigApplicationContext annotationCtx = new AnnotationConfigApplicationContext(); annotationCtx.setParent(parent); annotationCtx.register(clazz); annotationCtx.refresh(); ctx = annotationCtx; } catch (ClassNotFoundException e) { ctx = null; log.error("Unable to create a child context for Milton", e); } } else { String[] contextFiles; if (sFiles != null && sFiles.trim().length() > 0) { contextFiles = sFiles.split(" "); } else { contextFiles = new String[] { "applicationContext.xml" }; } try { ctx = new ClassPathXmlApplicationContext(contextFiles, parent); } catch (BeansException e) { log.error("Unable to create a child context for Milton", e); } } if (ctx == null) { log.warn("No child context available, only using parent context"); context = parent; } else { context = ctx; } }
From source file:com.versatus.jwebshield.filter.SecurityTokenFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { String file = filterConfig.getInitParameter("configFile"); if (file != null) { UrlExclusionList urlExList = new UrlExclusionList(); filterConfig.getServletContext().setAttribute(SecurityConstant.CSRF_CHECK_URL_EXCL_LIST_ATTR_NAME, urlExList);//from w w w.jav a 2 s . c o m try { XMLConfiguration config = new XMLConfiguration(file); List<Object> exclusionList = config.getList("urlExclusions"); tokenTimeout = config.getInteger("tokenTimeout", 1800); checkReferer = config.getBoolean("checkReferer", true); csrfCookieName = config.getString(SecurityConstant.CSRFCOOKIENAME_PARAM); if (exclusionList != null) { for (Object obj : exclusionList) { urlExList.addUrl((String) obj); } } logger.info("init: exclusionList=" + exclusionList); logger.info("init: urlExList=" + urlExList); logger.info("init: csrfCookieName=" + csrfCookieName); } catch (Exception cex) { logger.error("init: unable to load configFile " + file, cex); } } else { logger.error("init: No configFile specified"); } }