Java 类javax.servlet.ServletConfig 实例源码

项目:alfresco-remote-api    文件:CMISServletDispatcher.java   
public void init()
{
    Endpoint endpoint = new Endpoint(getBinding(), version);
    registry.registerDispatcher(endpoint, this);

    try
    {
        // fake the CMIS servlet
        ServletConfig config = getServletConfig();
        this.servlet = getServlet();
        servlet.init(config);
    }
    catch(ServletException e)
    {
        throw new AlfrescoRuntimeException("Failed to initialise CMIS servlet dispatcher", e);
    }
}
项目:e-identification-tupas-idp-public    文件:ShibbolethExtAuthnHandler.java   
public void init(ServletConfig config) throws ServletException {
    try {
        WebApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
        final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();
        beanFactory.autowireBean(this);
    }
    catch (Exception e) {
        logger.error("Error initializing ShibbolethExtAuthnHandler", e);
    }
}
项目:swaggy-jenkins    文件:ViewApi.java   
public ViewApi(@Context ServletConfig servletContext) {
   ViewApiService delegate = null;

   if (servletContext != null) {
      String implClass = servletContext.getInitParameter("ViewApi.implementation");
      if (implClass != null && !"".equals(implClass.trim())) {
         try {
            delegate = (ViewApiService) Class.forName(implClass).newInstance();
         } catch (Exception e) {
            throw new RuntimeException(e);
         }
      } 
   }

   if (delegate == null) {
      delegate = ViewApiServiceFactory.getViewApi();
   }

   this.delegate = delegate;
}
项目:elastest-instrumentation-manager    文件:AgentApi.java   
public AgentApi(@Context ServletConfig servletContext) {
   AgentApiService delegate = null;

   if (servletContext != null) {
      String implClass = servletContext.getInitParameter("AgentApi.implementation");
      if (implClass != null && !"".equals(implClass.trim())) {
         try {
            delegate = (AgentApiService) Class.forName(implClass).newInstance();
         } catch (Exception e) {
            throw new RuntimeException(e);
         }
      } 
   }

   if (delegate == null) {
      delegate = AgentApiServiceFactory.getAgentApi();
   }

   this.delegate = delegate;
}
项目:elastest-instrumentation-manager    文件:AgentconfigurationApi.java   
public AgentconfigurationApi(@Context ServletConfig servletContext) {
   AgentconfigurationApiService delegate = null;

   if (servletContext != null) {
      String implClass = servletContext.getInitParameter("AgentconfigurationApi.implementation");
      if (implClass != null && !"".equals(implClass.trim())) {
         try {
            delegate = (AgentconfigurationApiService) Class.forName(implClass).newInstance();
         } catch (Exception e) {
            throw new RuntimeException(e);
         }
      } 
   }

   if (delegate == null) {
      delegate = AgentconfigurationApiServiceFactory.getAgentconfigurationApi();
   }

   this.delegate = delegate;
}
项目:apache-tomcat-7.0.73-with-comment    文件:TagHandlerPool.java   
protected void init(ServletConfig config) {
    int maxSize = -1;
    String maxSizeS = getOption(config, OPTION_MAXSIZE, null);
    if (maxSizeS != null) {
        try {
            maxSize = Integer.parseInt(maxSizeS);
        } catch (Exception ex) {
            maxSize = -1;
        }
    }
    if (maxSize < 0) {
        maxSize = Constants.MAX_POOL_SIZE;
    }
    this.handlers = new Tag[maxSize];
    this.current = -1;
    instanceManager = InstanceManagerFactory.getInstanceManager(config);
}
项目:parabuild-ci    文件:ContainerUtil.java   
/**
 * Create a {@link DefaultContainer}, allowing users to upgrade to a child
 * of DefaultContainer using an {@link ServletConfig} init parameter of
 * <code>org.directwebremoting.Container</code>. Note that while the
 * parameter name is the classname of {@link Container}, currently the only
 * this can only be used to create children that inherit from
 * {@link DefaultContainer}. This restriction may be relaxed in the future.
 * Unlike {@link #setupDefaultContainer(DefaultContainer, ServletConfig)},
 * this method does not call any setup methods.
 * @param servletConfig The source of init parameters
 * @return An unsetup implementaion of DefaultContainer
 * @throws ServletException If the specified class could not be found
 * @see ServletConfig#getInitParameter(String)
 */
public static DefaultContainer createDefaultContainer(ServletConfig servletConfig) throws ServletException
{
    try
    {
        String typeName = servletConfig.getInitParameter(Container.class.getName());
        if (typeName == null)
        {
            return new DefaultContainer();
        }

        log.debug("Using alternate Container implementation: " + typeName);
        Class type = LocalUtil.classForName(typeName);
        return (DefaultContainer) type.newInstance();
    }
    catch (Exception ex)
    {
        throw new ServletException(ex);
    }
}
项目:dropwizard-prometheus    文件:PrometheusServlet.java   
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    final ServletContext context = config.getServletContext();
    if (null == registry) {
        final Object registryAttr = context.getAttribute(METRICS_REGISTRY);
        if (registryAttr instanceof MetricRegistry) {
            this.registry = (MetricRegistry) registryAttr;
        } else {
            throw new ServletException("Couldn't find a MetricRegistry instance.");
        }
    }

    filter = (MetricFilter) context.getAttribute(METRIC_FILTER);
    if (filter == null) {
        filter = MetricFilter.ALL;
    }

    this.allowedOrigin = context.getInitParameter(ALLOWED_ORIGIN);
}
项目:dremio-oss    文件:IndexServlet.java   
@Override
public void init(ServletConfig servletConfig) throws ServletException {
  this.servletConfig = servletConfig;

  //templateCfg.setClassForTemplateLoading(getClass(), "/");
  Resource baseResource;
  try {
    baseResource = Resource.newResource(servletConfig.getInitParameter("resourceBase"));
  } catch (MalformedURLException e) {
    throw new ServletException(e);
  }
  templateCfg.setTemplateLoader(new ResourceTemplateLoader(baseResource));
  templateCfg.setDefaultEncoding("UTF-8");

  // Sets how errors will appear.
  // During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER
  // is better.
  // cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
}
项目:swaggy-jenkins    文件:BlueApi.java   
public BlueApi(@Context ServletConfig servletContext) {
   BlueApiService delegate = null;

   if (servletContext != null) {
      String implClass = servletContext.getInitParameter("BlueApi.implementation");
      if (implClass != null && !"".equals(implClass.trim())) {
         try {
            delegate = (BlueApiService) Class.forName(implClass).newInstance();
         } catch (Exception e) {
            throw new RuntimeException(e);
         }
      } 
   }

   if (delegate == null) {
      delegate = BlueApiServiceFactory.getBlueApi();
   }

   this.delegate = delegate;
}
项目:joai-project    文件:SchemaViewerServlet.java   
public void init(ServletConfig conf) 
         throws ServletException {
System.out.println(getDateStamp() + " SchemaViewerServlet starting");
String initErrorMsg = "";
try {
    super.init(conf);
} catch (Throwable exc) {
    initErrorMsg = "SchemaViewerServlet Initialization Error:\n  " + exc;
    prtlnErr (initErrorMsg);
}

ServletContext servletContext = getServletContext();

MetadataVocab vocab = (MetadataVocab)servletContext.getAttribute( "MetadataVocab" );
if (vocab == null) {
    throw new ServletException ("MetadataVocab not found in servlet context");
}

// set up remote searcher
/* RemoteSearcher rs = (RemoteSearcher) servletContext.getAttribute ("RemoteSearcher");
if (rs == null) {
    throw new ServletException ("RemoteSearcher not found in servlet context");
} */

System.out.println(getDateStamp() + " SchemaViewerServlet initialized.");
  }
项目:lams    文件:TagHandlerPool.java   
protected void init( ServletConfig config ) {
    int maxSize=-1;
    String maxSizeS=getOption(config, OPTION_MAXSIZE, null);
    if( maxSizeS != null ) {
        try {
            maxSize=Integer.parseInt(maxSizeS);
        } catch( Exception ex) {
            maxSize=-1;
        }
    }
    if( maxSize <0  ) {
        maxSize=Constants.MAX_POOL_SIZE;
    }
    this.handlers = new Tag[maxSize];
    this.current = -1;
    instanceManager = InstanceManagerFactory.getInstanceManager(config);
}
项目:validator-web    文件:StartupUtil.java   
private static void scanValidationComponents(DefaultContainer container, ServletConfig servletConfig) {
    String scanPackage = servletConfig.getInitParameter(SCAN_PACKAGE_INIT_PARAMETER);
    if (scanPackage == null) {
        return;
    }

    ClassPathScanner scanner = new ClassPathScanner();
    scanner.addIncludeFilter(new ValidationScriptMappingTypeFilter());
    Set<Class<?>> classes = scanner.scan(scanPackage);

    for (Class<?> beanClass : classes) {
        try {
            Object bean = ClassUtils.newInstance(beanClass);
            String beanName = generateBeanName(beanClass, container);
            container.addBean(beanName, bean);
        } catch (Exception e) {
            log.error("Unable to instantiate class [" + beanClass.getName() + "].", e);
        }
    }
}
项目:rockscript    文件:Servlet.java   
@Override
public void init(ServletConfig servletConfig) throws ServletException {
  super.init(servletConfig);

  if (engine==null) {
    Map<String,String> configurationProperties = readConfigurationProperties(servletConfig);
    engine = createEngine(configurationProperties);
  }

  engine.start();

  log.debug(" ____            _     ____            _       _    ");
  log.debug("|  _ \\ ___   ___| | __/ ___|  ___ _ __(_)_ __ | |_  ");
  log.debug("| |_) / _ \\ / __| |/ /\\___ \\ / __| '__| | '_ \\| __| ");
  log.debug("|  _ < (_) | (__|   <  ___) | (__| |  | | |_) | |_  ");
  log.debug("|_| \\_\\___/ \\___|_|\\_\\|____/ \\___|_|  |_| .__/ \\__| ");
  log.debug("                                        |_|         ");

  setGson(engine.getGson());

  engine
    .getRequestHandlers()
    .forEach(requestHandler->requestHandler(requestHandler));

  defaultResponseHeader("Access-Control-Allow-Origin", "*");
}
项目:Equella    文件:SRWServletExt.java   
@Override
public void init() throws ServletException
{
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    final ServletConfig config = super.getServletConfig();
    super.init();

    // We do so we don't have specify a 'database' on the URL path
    // eg. http://localhost:8988/dev/first/srw/
    srwInfo = new SRWServletInfo()
    {
        @Override
        public String getDBName(HttpServletRequest request)
        {
            return DB_NAME;
        }
    };
    srwInfo.init(config);
    srwInfo.getProperties().put("defaultSchema", EquellaSRWDatabase.DEFAULT_SCHEMA.getTleId()); //$NON-NLS-1$
    srwInfo.getProperties().put("db." + DB_NAME + ".class", EquellaSRWDatabase.class.getName()); //$NON-NLS-1$ //$NON-NLS-2$
}
项目:parabuild-ci    文件:DwrGuiceServlet.java   
/**
 * Copies DWR configuration values from the Guice bindings into 
 * {@code servletConfig} to make these values accessible to the 
 * standard DWR servlet configuration machinery.
 */
@Override public void init(ServletConfig servletConfig) throws ServletException
{
    // Save this for later use by destroy.
    this.servletContext = servletConfig.getServletContext();

    // Set the current context thread-locally so our internal classes can
    // look up the Injector and use it in turn to look up further objects.
    pushServletContext(this.servletContext);
    try
    {      
        // Since ServletConfig is immutable, we use a modifiable 
        // decoration of the real servlet configuration and pass 
        // that to the init method of the superclass.
        ModifiableServletConfig config = new ModifiableServletConfig(servletConfig);

        // Apply settings configured at bind-time.
        setInitParameters(config);

        // Use our internal manager classes to replace and delegate to
        // any user-specified or default implementations, after adding
        // additional creators and converters registered at bind-time.
        configureDelegatedTypes(config);

        // Normal DwrServlet initialization happens here using the
        // modified ServletConfig instead of the one we were passed.
        super.init(config);

        // Objects with (non-global) application scope are initialized
        // eagerly.
        initApplicationScoped();            
    }
    finally
    {
        // Clean up the ThreadLocal we just used.
        popServletContext();
    }
}
项目:java-web-services-training    文件:CountriesServlet.java   
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    // Prepare list of Country objects
    countries.add(new Country("IDN", "Indonesia"));
    countries.add(new Country("MYS", "Malaysia"));
}
项目:pentaho-8-reporting-for-java-developers    文件:PentahoServlet.java   
@Override
public void init(
  ServletConfig config) 
  throws ServletException 
{

  super.init(config);
  ClassicEngineBoot.getInstance().start();

}
项目:parabuild-ci    文件:ContainerUtil.java   
/**
 * Take a DefaultContainer and setup the default beans
 * @param container The container to configure
 * @param servletConfig The servlet configuration (null to ignore)
 * @throws InstantiationException If we can't instantiate a bean
 * @throws IllegalAccessException If we have access problems creating a bean
 */
public static void setupFromServletConfig(DefaultContainer container, ServletConfig servletConfig) throws InstantiationException, IllegalAccessException
{
    Enumeration en = servletConfig.getInitParameterNames();
    while (en.hasMoreElements())
    {
        String name = (String) en.nextElement();
        String value = servletConfig.getInitParameter(name);
        container.addParameter(name, value);
    }
}
项目:lams    文件:CGIServlet.java   
/**
 * Sets instance variables.
 * <P>
 * Modified from Craig R. McClanahan's InvokerServlet
 * </P>
 *
 * @param config                    a <code>ServletConfig</code> object
 *                                  containing the servlet's
 *                                  configuration and initialization
 *                                  parameters
 *
 * @exception ServletException      if an exception has occurred that
 *                                  interferes with the servlet's normal
 *                                  operation
 */
public void init(ServletConfig config) throws ServletException {

    super.init(config);

    // Verify that we were not accessed using the invoker servlet
    String servletName = getServletConfig().getServletName();
    if (servletName == null)
        servletName = "";
    if (servletName.startsWith("org.apache.catalina.INVOKER."))
        throw new UnavailableException
            ("Cannot invoke CGIServlet through the invoker");

    // Set our properties from the initialization parameters
    if (getServletConfig().getInitParameter("debug") != null)
        debug = Integer.parseInt(getServletConfig().getInitParameter("debug"));
    cgiPathPrefix = getServletConfig().getInitParameter("cgiPathPrefix");
    boolean passShellEnvironment = 
        Boolean.valueOf(getServletConfig().getInitParameter("passShellEnvironment")).booleanValue();

    if (passShellEnvironment) {
        shellEnv.putAll(System.getenv());
    }

    if (getServletConfig().getInitParameter("executable") != null) {
        cgiExecutable = getServletConfig().getInitParameter("executable");
    }

    if (getServletConfig().getInitParameter("parameterEncoding") != null) {
        parameterEncoding = getServletConfig().getInitParameter("parameterEncoding");
    }

}
项目:pentaho-8-reporting-for-java-developers    文件:PentahoServlet.java   
@Override
public void init(
  ServletConfig config) 
  throws ServletException 
{

  super.init(config);
  ClassicEngineBoot.getInstance().start();

}
项目:uflo    文件:UfloServlet.java   
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    WebApplicationContext applicationContext=getWebApplicationContext(config);
    Collection<ServletHandler> handlers=applicationContext.getBeansOfType(ServletHandler.class).values();
    for(ServletHandler handler:handlers){
        String url=handler.url();
        if(handlerMap.containsKey(url)){
            throw new RuntimeException("Handler ["+url+"] already exist.");
        }
        handlerMap.put(url, handler);
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:TagHandlerPool.java   
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;
}
项目:parabuild-ci    文件:StartupUtil.java   
/**
 * We have some special logging classes to maintain an optional dependence
 * on commons-logging. This sets the servlet for when this is not available.
 * @param servletConfig The servlet configuration
 * @param servlet The servlet that we are running under
 */
public static void setupLogging(ServletConfig servletConfig, HttpServlet servlet)
{
    ServletLoggingOutput.setExecutionContext(servlet);
    String logLevel = servletConfig.getInitParameter(ContainerUtil.INIT_LOGLEVEL);
    if (logLevel != null)
    {
        ServletLoggingOutput.setLevel(logLevel);
    }
}
项目:pentaho-8-reporting-for-java-developers    文件:PentahoServlet.java   
@Override
public void init(
  ServletConfig config) 
  throws ServletException 
{

  super.init(config);
  ClassicEngineBoot.getInstance().start();

}
项目:parabuild-ci    文件:DefaultWebContextBuilder.java   
public void set(HttpServletRequest request, HttpServletResponse response, ServletConfig config, ServletContext context, Container container)
{
    try
    {
        WebContext ec = new DefaultWebContext(request, response, config, context, container);
        user.set(ec);
    }
    catch (Exception ex)
    {
        log.fatal("Failed to create an ExecutionContext", ex);
    }
}
项目:validator-web    文件:WebContextThreadStack.java   
/**
 * 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);
    }
}
项目:sgroup    文件:ProductServlet.java   
/**
     * 带参数的初始化,只执行一次
     * @param config web.xml的配置
     * @throws ServletException
     */
    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
//        读取编码格式
//        charset = config.getInitParameter("charset");

    }
项目:lazycat    文件:TagHandlerPool.java   
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;
}
项目:joai-project    文件:CommCoreServlet.java   
/**
 *  Intialize the StandardsSuggestionService and place it in the ServletContext
 *  where it can be found by the Rest Service Clases.
 *
 * @param  config                Description of the Parameter
 * @exception  ServletException  Description of the Exception
 */
public void init(ServletConfig config)
     throws ServletException {
    log.info (getDateStamp() + " CommCoreServlet starting");
    String initErrorMsg = "";
    try {
        super.init(config);
    } catch (Throwable exc) {
        initErrorMsg = "CommCoreServlet Initialization Error:\n  " + exc;
        log.error (initErrorMsg);
    }

    // initialize the AdnStandardsManager
    String commCoreStandardsPath = getAbsolutePath ((String)getServletContext().getInitParameter("commCoreStandardsPath"));
    if (commCoreStandardsPath == null) {
        throw new ServletException("init parameter \"commCoreStandardsPath\" not found in servlet context");
    }
    CommCoreServiceHelper commCoreServiceHelper = null;
    try {
        commCoreServiceHelper = new CommCoreServiceHelper(commCoreStandardsPath); 
    } catch (Exception e) {
        log.error("Failed to initialize StdDocument.", e);
    }

    if (commCoreServiceHelper != null)
        getServletContext().setAttribute("commCoreServiceHelper", commCoreServiceHelper);
    else
        throw new ServletException ("Failed to initialize StdDocument");

    log.info (getDateStamp() + " CommCoreServlet completed.\n");
}
项目:bootstrap    文件:BackendProxyServletTest.java   
@Test(expected = UnavailableException.class)
public void getRequiredInitParameter() throws ServletException {
    final ServletConfig servletConfig = Mockito.mock(ServletConfig.class);

    Mockito.when(servletConfig.getServletName()).thenReturn("a");
    Mockito.when(servletContext.getContextPath()).thenReturn("context");
    Mockito.when(servletConfig.getServletContext()).thenReturn(servletContext);
    Mockito.when(servletConfig.getInitParameter("prefix")).thenReturn("prefix");
    Mockito.when(servletConfig.getInitParameter("maxThreads")).thenReturn("6");
    servlet.init(servletConfig);
}
项目:lazycat    文件:JspServletWrapper.java   
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);
    }
项目:server    文件:PeerServlet.java   
@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    WebApplicationContext context = getWebApplicationContext();
    service = (JrpcService) context.getBean("Service");
}
项目:openNaEF    文件:DifferenceServlet.java   
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {
        ConfigUtil conf = ConfigUtil.getInstance();
        if (!conf.reload())
            throw new ServletException("Config load error.");
        checkAndCreateDirs(conf.getDebugDumpDir());
        checkAndCreateDirs(conf.getDifferenceSetDir());
        RegularExecution.getInstance().reScheduleAll();
        AAAConfiguration.getInstance().reloadConfiguration();
    } catch (Exception e) {
        log.error("got exception.", e);
    }
}
项目:validator-web    文件:ScriptSupportServlet.java   
@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    try {
        this.container = StartupUtil.createAndSetupDefaultContainer(servletConfig);

        this.servletConfig = servletConfig;
    } catch (Exception ex) {
        log.fatal("init failed", ex);
        throw new ServletException(ex);
    }

    this.processor = this.container.getBean(UrlProcessor.class);
}
项目:parabuild-ci    文件:WebXMLTest.java   
public void testServletParameters() throws Exception {
    WebXMLString wxs = new WebXMLString();
    Properties params = new Properties();
    params.setProperty( "color", "red" );
    params.setProperty( "age", "12" );
    wxs.addServlet( "simple", "/SimpleServlet", SimpleGetServlet.class, params );

    ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) );
    ServletUnitClient client = sr.newClient();
    InvocationContext ic = client.newInvocation( "http://localhost/SimpleServlet" );
    ServletConfig servletConfig = ic.getServlet().getServletConfig();
    assertNull( "init parameter 'gender' should be null", servletConfig.getInitParameter( "gender" ) );
    assertEquals( "init parameter via config", "red", ic.getServlet().getServletConfig().getInitParameter( "color" ) );
    assertEquals( "init parameter directly", "12", ((HttpServlet) ic.getServlet()).getInitParameter( "age" ) );
}
项目:jaffa-framework    文件:JawrServletTest.java   
/**
 * tests Jawr Properties load
 * @throws Exception
    */
//@Test
public void testJawrPropertiesLoad() throws Exception {

    //initialize
    Map<String, String> initParameters = new HashMap<String, String>();
    initParameters.put("configLocation", "/jawr.properties");
    initParameters.put("configPropertiesSourceClass", "org.jaffa.ria.util.PropsFilePropertiesSource");
    initParameters.put("mapping", "/jsJawrPath/");

    ServletContext servletContext = mock(ServletContext.class);
    ServletConfig servletConfig = mock(ServletConfig.class);

    when(servletConfig.getServletContext()).thenReturn(servletContext);
    when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(initParameters.keySet()));
    when(servletConfig.getInitParameter("configLocation")).thenReturn("/jawr.properties");
    when(servletConfig.getInitParameter("configPropertiesSourceClass")).thenReturn("org.jaffa.ria.util.PropsFilePropertiesSource");
    when(servletConfig.getInitParameter("mapping")).thenReturn("/jsJawrPath/");

    when(servletContext.getAttribute("javax.servlet.context.tempdir")).thenReturn(new File("abc"));


    //test
    JawrServlet jawrServlet = new JawrServlet();

    jawrServlet.init(servletConfig);


    //verify
    verify(servletContext).setAttribute(eq(JawrConstant.JS_CONTEXT_ATTRIBUTE), any());

}
项目:myfaces-trinidad    文件:ResourceServlet.java   
/**
 * Override of Servlet.init();
 */
@Override
public void init(
  ServletConfig config
  ) throws ServletException
{
  super.init(config);

  // Acquire our FacesContextFactory instance
  try
  {
    _facesContextFactory = (FacesContextFactory)
              FactoryFinder.getFactory
              (FactoryFinder.FACES_CONTEXT_FACTORY);
  }
  catch (FacesException e)
  {
    Throwable rootCause = e.getCause();
    if (rootCause == null)
    {
      throw e;
    }
    else
    {
      throw new ServletException(e.getMessage(), rootCause);
    }
  }

  // Acquire our Lifecycle instance
  _lifecycle = new _ResourceLifecycle();
  _initDebug(config);
  _loaders = new ConcurrentHashMap<String, ResourceLoader>();
  _loaderErrors = new ConcurrentHashMap<String, Class<?>>();
}
项目:pentaho-8-reporting-for-java-developers    文件:PentahoServlet.java   
@Override
public void init(
  ServletConfig config) 
  throws ServletException 
{

  super.init(config);
  ClassicEngineBoot.getInstance().start();

}