Java Code Examples for javax.servlet.ServletConfig#getServletContext()
The following examples show how to use
javax.servlet.ServletConfig#getServletContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VaadinServlet.java From usergrid with Apache License 2.0 | 6 votes |
private static ServletConfig getServletConfig(final ServletConfig servletConfig) { return new ServletConfig() { @Override public String getServletName() { return servletConfig.getServletName(); } @Override public ServletContext getServletContext() { return servletConfig.getServletContext(); } @Override public String getInitParameter(String s) { return PARAMS.get(s); } @Override public Enumeration<String> getInitParameterNames() { return PARAMS.keys(); } }; }
Example 2
Source File: CaptureOperationsServlet.java From fosstrak-epcis with GNU Lesser General Public License v2.1 | 6 votes |
/** * Loads the application properties and populates a java.util.Properties * instance. * * @param servletConfig * The ServletConfig used to locate the application property * file. * @return The application properties. */ private Properties loadApplicationProperties(ServletConfig servletConfig) { // read application properties from servlet context ServletContext ctx = servletConfig.getServletContext(); String path = ctx.getRealPath("/"); String appConfigFile = ctx.getInitParameter(APP_CONFIG_LOCATION); Properties properties = new Properties(); try { InputStream is = new FileInputStream(path + appConfigFile); properties.load(is); is.close(); LOG.info("Loaded application properties from " + path + appConfigFile); } catch (IOException e) { LOG.error("Unable to load application properties from " + path + appConfigFile, e); } return properties; }
Example 3
Source File: Bootstrap.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public void init(ServletConfig config) throws ServletException { Info info = new Info() .title("OpenAPI Server") .description("This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\") .termsOfService("") .contact(new Contact() .email("")) .license(new License() .name("Apache-2.0") .url("https://www.apache.org/licenses/LICENSE-2.0.html")); ServletContext context = config.getServletContext(); Swagger swagger = new Swagger().info(info); new SwaggerContextService().withServletConfig(config).updateSwagger(swagger); }
Example 4
Source File: Bootstrap.java From openapi-generator with Apache License 2.0 | 6 votes |
@Override public void init(ServletConfig config) throws ServletException { Info info = new Info() .title("OpenAPI Server") .description("This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\") .termsOfService("") .contact(new Contact() .email("")) .license(new License() .name("Apache-2.0") .url("https://www.apache.org/licenses/LICENSE-2.0.html")); ServletContext context = config.getServletContext(); Swagger swagger = new Swagger().info(info); new SwaggerContextService().withServletConfig(config).updateSwagger(swagger); }
Example 5
Source File: ContentAcknowledgmentServlet.java From nifi with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override public void init(final ServletConfig config) throws ServletException { final ServletContext context = config.getServletContext(); this.processor = (Processor) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_PROCESSOR); this.logger = (ComponentLog) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_LOGGER); this.authorizedPattern = (Pattern) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_AUTHORITY_PATTERN); this.flowFileMap = (ConcurrentMap<String, FlowFileEntryTimeWrapper>) context.getAttribute(ListenHTTP.CONTEXT_ATTRIBUTE_FLOWFILE_MAP); }
Example 6
Source File: JspServletWrapper.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public JspServletWrapper(ServletConfig config, Options options, String jspUri, JspRuntimeContext rctxt) { this.isTagFile = false; this.config = config; this.options = options; this.jspUri = jspUri; unloadByCount = options.getMaxLoadedJsps() > 0 ? true : false; unloadByIdle = options.getJspIdleTimeout() > 0 ? true : false; unloadAllowed = unloadByCount || unloadByIdle ? true : false; ctxt = new JspCompilationContext(jspUri, options, config.getServletContext(), this, rctxt); }
Example 7
Source File: DispatcherServlet.java From myspring with MIT License | 5 votes |
@Override public void init(ServletConfig config) throws ServletException { Object oldCxt = config.getServletContext().getAttribute(ContextLoaderListener.ROOT_CXT_ATTR); this.context = oldCxt == null ? new WebApplicationContext() : (WebApplicationContext)oldCxt; ServletContext sc = config.getServletContext(); //注册JSP的Servlet,视图才能重定向 ServletRegistration jspServlet = sc.getServletRegistration("jsp"); jspServlet.addMapping(CommonUtis.JSP_PATH_PREFIX + "*"); }
Example 8
Source File: TagHandlerPool.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
protected static String getOption( ServletConfig config, String name, String defaultV) { if( config == null ) return defaultV; String value=config.getInitParameter(name); if( value != null ) return value; if( config.getServletContext() ==null ) return defaultV; value=config.getServletContext().getInitParameter(name); if( value!=null ) return value; return defaultV; }
Example 9
Source File: VelocityDispatchServlet.java From sakai with Educational Community License v2.0 | 5 votes |
@Override public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext context = config.getServletContext(); inlineDispatcher = new VelocityInlineDispatcher(); inlineDispatcher.init(context); }
Example 10
Source File: WebContextThreadStack.java From validator-web with Apache License 2.0 | 5 votes |
/** * Make the current thread know what the current request is. * @param servletConfig The servlet configuration object used by a servlet container * @param request The incoming http request * @param response The outgoing http reply * @see #disengageThread() */ public static void engageThread(ServletConfig servletConfig, HttpServletRequest request, HttpServletResponse response) { try { WebContext ec = new DefaultWebContext(request, response, servletConfig, servletConfig.getServletContext()); engageThread(ec); } catch (Exception ex) { log.fatal("Failed to create an ExecutionContext", ex); } }
Example 11
Source File: ServletRegistration.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void destroy() { final Servlet servlet = dispatcher.getServlet(); final ServletConfig cfg = servlet.getServletConfig(); final ServletContext context = cfg != null ? cfg.getServletContext() : null; servlet.destroy(); if (context != null) { contextManager.ungetServletContext(context); } registrations.removeServlet(servlet); }
Example 12
Source File: StaticWebApplicationContext.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public void setServletConfig(ServletConfig servletConfig) { this.servletConfig = servletConfig; if (servletConfig != null && this.servletContext == null) { this.servletContext = servletConfig.getServletContext(); } }
Example 13
Source File: SipGatewayManager.java From JVoiceXML with GNU Lesser General Public License v2.1 | 5 votes |
private SipURI getLocalInterface(final ServletConfig config) { final ServletContext context = config.getServletContext(); SipURI result = null; @SuppressWarnings("unchecked") final List<SipURI> uris = (List<SipURI>)context.getAttribute(OUTBOUND_INTERFACES); for(final SipURI uri : uris) { final String transport = uri.getTransportParam(); if("udp".equalsIgnoreCase(transport)) { result = uri; } } return result; }
Example 14
Source File: DumpIbisConsole.java From iaf with Apache License 2.0 | 4 votes |
public void init(ServletConfig config) { servletContext = config.getServletContext(); }
Example 15
Source File: AbstractHttpServlet.java From groovy with Apache License 2.0 | 4 votes |
/** * Overrides the generic init method to set some debug flags. * * @param config the servlet configuration provided by the container * @throws ServletException if init() method defined in super class * javax.servlet.GenericServlet throws it */ public void init(ServletConfig config) throws ServletException { /* * Never forget super.init()! */ super.init(config); /* * Grab the servlet context. */ this.servletContext = config.getServletContext(); // Get verbosity hint. String value = config.getInitParameter("verbose"); if (value != null) { this.verbose = Boolean.valueOf(value); } // get encoding value = config.getInitParameter("encoding"); if (value != null) { this.encoding = value; } // And now the real init work... if (verbose) { log("Parsing init parameters..."); } 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 = ""; } int flags = 0; // TODO : Parse pattern compile flags (literal names). String flagsStr = config.getInitParameter(INIT_PARAM_RESOURCE_NAME_REGEX_FLAGS); if (flagsStr != null && flagsStr.length() > 0) { flags = Integer.decode(flagsStr.trim());//throws NumberFormatException } resourceNamePattern = Pattern.compile(regex, flags); this.resourceNameReplacement = replacement; 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); // nothing else to do here } /* * If verbose, log the parameter values. */ if (verbose) { log("(Abstract) init done. Listing some parameter name/value pairs:"); log("verbose = " + verbose); // this *is* verbose! ;) log("reflection = " + reflection); log("logGROOVY861 = " + logGROOVY861); log(INIT_PARAM_RESOURCE_NAME_REGEX + " = " + resourceNamePattern);//toString == pattern log("resource.name.replacement = " + resourceNameReplacement); } }
Example 16
Source File: ControllerServlet2.java From sakai with Educational Community License v2.0 | 4 votes |
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); ServletContext sc = servletConfig.getServletContext(); wac = WebApplicationContextUtils.getWebApplicationContext(sc); if (wac == null) { throw new ServletException("Unable to get WebApplicationContext "); } searchBeanFactory = (SearchBeanFactory) wac.getBean("search-searchBeanFactory"); if (searchBeanFactory == null) { throw new ServletException("Unable to get search-searchBeanFactory "); } sessionManager = (SessionManager) wac.getBean(SessionManager.class.getName()); if (sessionManager == null) { throw new ServletException("Unable to get " + SessionManager.class.getName()); } ServerConfigurationService serverConfigurationService = (ServerConfigurationService) wac.getBean(ServerConfigurationService.class.getName()); if (serverConfigurationService == null) { throw new ServletException("Unable to get " + ServerConfigurationService.class.getName()); } serverUrl = serverConfigurationService.getServerUrl(); searchBeanFactory.setContext(sc); inlineMacros = MACROS; InputStream is = null; try { vengine = new VelocityEngine(); vengine.setApplicationAttribute(ServletContext.class.getName(), sc); vengine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new SLF4JLogChute()); Properties p = new Properties(); is = this.getClass().getResourceAsStream("searchvelocity.config"); p.load(is); vengine.init(p); vengine.getTemplate(inlineMacros); } catch (Exception ex) { throw new ServletException(ex); } finally { if (is !=null) { try { is.close(); } catch (IOException e) { log.debug("exception thrown in Finally block"); } } } contentTypes.put("opensearch", "application/opensearchdescription+xml"); contentTypes.put("sakai.src", "application/opensearchdescription+xml" ); contentTypes.put("rss20", "text/xml" ); }
Example 17
Source File: cfchartServlet.java From openbd-core with GNU General Public License v3.0 | 4 votes |
public void init(ServletConfig config) throws ServletException { super.init(config); thisServletContext = config.getServletContext(); }
Example 18
Source File: JspServlet.java From packagedrone with Eclipse Public License 1.0 | 4 votes |
public void init(ServletConfig config) throws ServletException { super.init(config); this.config = config; this.context = config.getServletContext(); // Initialize the JSP Runtime Context options = new EmbeddedServletOptions(config, context); rctxt = new JspRuntimeContext(context,options); // START SJSWS 6232180 // Determine which HTTP methods to service ("*" means all) httpMethodsString = config.getInitParameter("httpMethods"); if (httpMethodsString != null && !httpMethodsString.equals("*")) { httpMethodsSet = new HashSet<String>(); StringTokenizer tokenizer = new StringTokenizer( httpMethodsString, ", \t\n\r\f"); while (tokenizer.hasMoreTokens()) { httpMethodsSet.add(tokenizer.nextToken()); } } // END SJSWS 6232180 // START GlassFish 750 taglibs = new ConcurrentHashMap<String, TagLibraryInfo>(); context.setAttribute(Constants.JSP_TAGLIBRARY_CACHE, taglibs); tagFileJarUrls = new ConcurrentHashMap<String, URL>(); context.setAttribute(Constants.JSP_TAGFILE_JAR_URLS_CACHE, tagFileJarUrls); // END GlassFish 750 if (log.isLoggable(Level.FINEST)) { log.finest(Localizer.getMessage("jsp.message.scratch.dir.is", options.getScratchDir().toString())); log.finest(Localizer.getMessage("jsp.message.dont.modify.servlets")); } this.jspProbeEmitter = (JspProbeEmitter) config.getServletContext().getAttribute( "org.glassfish.jsp.monitor.probeEmitter"); }
Example 19
Source File: ControllerServlet2.java From sakai with Educational Community License v2.0 | 4 votes |
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); ServletContext sc = servletConfig.getServletContext(); wac = WebApplicationContextUtils.getWebApplicationContext(sc); if (wac == null) { throw new ServletException("Unable to get WebApplicationContext "); } searchBeanFactory = (SearchBeanFactory) wac.getBean("search-searchBeanFactory"); if (searchBeanFactory == null) { throw new ServletException("Unable to get search-searchBeanFactory "); } sessionManager = (SessionManager) wac.getBean(SessionManager.class.getName()); if (sessionManager == null) { throw new ServletException("Unable to get " + SessionManager.class.getName()); } ServerConfigurationService serverConfigurationService = (ServerConfigurationService) wac.getBean(ServerConfigurationService.class.getName()); if (serverConfigurationService == null) { throw new ServletException("Unable to get " + ServerConfigurationService.class.getName()); } serverUrl = serverConfigurationService.getServerUrl(); searchBeanFactory.setContext(sc); inlineMacros = MACROS; InputStream is = null; try { vengine = new VelocityEngine(); vengine.setApplicationAttribute(ServletContext.class.getName(), sc); vengine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new SLF4JLogChute()); Properties p = new Properties(); is = this.getClass().getResourceAsStream("searchvelocity.config"); p.load(is); vengine.init(p); vengine.getTemplate(inlineMacros); } catch (Exception ex) { throw new ServletException(ex); } finally { if (is !=null) { try { is.close(); } catch (IOException e) { log.debug("exception thrown in Finally block"); } } } contentTypes.put("opensearch", "application/opensearchdescription+xml"); contentTypes.put("sakai.src", "application/opensearchdescription+xml" ); contentTypes.put("rss20", "text/xml" ); }
Example 20
Source File: HALoadBalancerServlet.java From database with GNU General Public License v2.0 | 4 votes |
/** * {@inheritDoc} * <p> * Extended to setup the as-configured {@link IHALoadBalancerPolicy}. * <p> * Note: If the deployment is does not support HA replication (e.g., either * not HA or HA with replicationFactor:=1), then we still want to be able to * forward to the local service. * * @throws ServletException * * @see <a href="http://trac.blazegraph.com/ticket/965" > Cannot run queries in * LBS mode with HA1 setup </a> */ @Override public void init() throws ServletException { super.init(); final ServletConfig servletConfig = getServletConfig(); // // Get the as-configured prefix to be stripped from requests. // prefix = servletConfig.getInitParameter(InitParams.PREFIX); prefix = BigdataStatics.getContextPath() + PATH_LBS; final ServletContext servletContext = servletConfig.getServletContext(); final IIndexManager indexManager = BigdataServlet .getIndexManager(servletContext); if (((AbstractJournal) indexManager).isHAJournal() && ((AbstractJournal) indexManager).getQuorum() != null && ((AbstractJournal) indexManager).getQuorum() .replicationFactor() > 1) { { // Get the as-configured policy. final IHALoadBalancerPolicy policy = newInstance(// servletConfig, // HALoadBalancerServlet.class,// owningClass IHALoadBalancerPolicy.class,// InitParams.POLICY, InitParams.DEFAULT_POLICY); // Set the as-configured policy. setLBSPolicy(policy); } { final IHARequestURIRewriter rewriter = newInstance(// servletConfig,// HALoadBalancerServlet.class, // owningClass IHARequestURIRewriter.class,// InitParams.REWRITER, InitParams.DEFAULT_REWRITER); setRewriter(rewriter); } } servletContext.setAttribute(BigdataServlet.ATTRIBUTE_LBS_PREFIX, prefix); addServlet(servletContext, this/*servlet*/); if (log.isInfoEnabled()) log.info(servletConfig.getServletName() + " @ " + prefix + " :: policy=" + policyRef.get() + ", rewriter=" + rewriterRef.get()); }