Java Code Examples for javax.servlet.ServletConfig#getInitParameter()

The following examples show how to use javax.servlet.ServletConfig#getInitParameter() . 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: EmbeddedServletOptions.java    From packagedrone with Eclipse Public License 1.0 6 votes vote down vote up
private boolean getBoolean(ServletConfig config, 
                           boolean init, String param) {

    String sParam = config.getInitParameter(param);
    if (sParam != null) {
        if (sParam.equalsIgnoreCase("true")) {
            return true;
        }
        if (sParam.equalsIgnoreCase("false")) {
            return false;
        }
        if (log.isLoggable(Level.WARNING)) {
           log.warning(Localizer.getMessage("jsp.warning.boolean", param,
                   (init? "true": "false")));
        }
    }
    return init;
}
 
Example 2
Source File: GenericWebServiceServlet.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
public void init(ServletConfig sc) throws ServletException {
	// Setting this property because otherwise a file named
	// "wsdl.properties" will be read from the JRE, which is not possible
	// due to restrictive permissions
	System.setProperty("javax.wsdl.factory.WSDLFactory", "com.ibm.wsdl.factory.WSDLFactoryImpl");

	if (this.bus == null) {
		loadBus(sc);
	}
	loader = bus.getExtension(ClassLoader.class);
	ResourceManager resourceManager = bus.getExtension(ResourceManager.class);
	resourceManager.addResourceResolver(new ServletContextResourceResolver(sc.getServletContext()));

	if (destinationRegistry == null) {
		this.destinationRegistry = getDestinationRegistryFromBus(this.bus);
	}
	this.controller = createServletController(sc);

	redirectList = parseListSequence(sc.getInitParameter(REDIRECTS_PARAMETER));
	redirectQueryCheck = Boolean.valueOf(sc.getInitParameter(REDIRECT_QUERY_CHECK_PARAMETER));
	dispatcherServletName = sc.getInitParameter(REDIRECT_SERVLET_NAME_PARAMETER);
	dispatcherServletPath = sc.getInitParameter(REDIRECT_SERVLET_PATH_PARAMETER);
}
 
Example 3
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public StoreApi(@Context ServletConfig servletContext) {
   StoreApiService delegate = null;

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

   if (delegate == null) {
      delegate = StoreApiServiceFactory.getStoreApi();
   }

   this.delegate = delegate;
}
 
Example 4
Source File: AnotherFakeApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public AnotherFakeApi(@Context ServletConfig servletContext) {
   AnotherFakeApiService delegate = null;

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

   if (delegate == null) {
      delegate = AnotherFakeApiServiceFactory.getAnotherFakeApi();
   }

   this.delegate = delegate;
}
 
Example 5
Source File: StoreApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
public StoreApi(@Context ServletConfig servletContext) {
   StoreApiService delegate = null;

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

   if (delegate == null) {
      delegate = StoreApiServiceFactory.getStoreApi();
   }

   this.delegate = delegate;
}
 
Example 6
Source File: StartupUtil.java    From validator-web with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 7
Source File: ProxyRepositoryServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void init(ServletConfig config) throws ServletException {
	super.init(config);
	lastModified = System.currentTimeMillis();
	if (config.getInitParameter(DEFAULT_PATH_PARAM) == null) {
		throw new MissingInitParameterException(DEFAULT_PATH_PARAM);
	}
	Enumeration<String> names = config.getInitParameterNames();
	while (names.hasMoreElements()) {
		String path = names.nextElement();
		if (path.startsWith("/")) {
			try {
				servlets.put(path, createServlet(path));
			} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
				throw new ServletException(e);
			}
		}
	}
}
 
Example 8
Source File: HttpServletBean.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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, ", "));
	}
}
 
Example 9
Source File: ShiroKaptchaServlet.java    From phone with Apache License 2.0 6 votes vote down vote up
@Override
public void init(ServletConfig conf) throws ServletException
{
	super.init(conf);

	// Switch off disk based caching.
	ImageIO.setUseCache(false);

	Enumeration<?> initParams = conf.getInitParameterNames();
	while (initParams.hasMoreElements())
	{
		String key = (String) initParams.nextElement();
		String value = conf.getInitParameter(key);
		this.props.put(key, value);
	}

	Config config = new Config(this.props);
	this.kaptchaProducer = config.getProducerImpl();
	this.sessionKeyValue = config.getSessionKey();
	this.sessionKeyDateValue = config.getSessionDate();
}
 
Example 10
Source File: ApiApi.java    From swaggy-jenkins with MIT License 6 votes vote down vote up
public ApiApi(@Context ServletConfig servletContext) {
   ApiApiService delegate = null;

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

   if (delegate == null) {
      delegate = ApiApiServiceFactory.getApiApi();
   }

   this.delegate = delegate;
}
 
Example 11
Source File: TransformationServlet.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void init(final ServletConfig config) throws ServletException {
	super.init(config);
	cookies = new CookieHandler(config, this);

	if (config != null) {
		if (config.getInitParameter(TRANSFORMATIONS) == null) {
			throw new MissingInitParameterException(TRANSFORMATIONS);
		}
		final Enumeration<?> names = config.getInitParameterNames();
		while (names.hasMoreElements()) {
			final String name = (String) names.nextElement();
			if (name.startsWith("default-")) {
				defaults.put(name.substring("default-".length()), config.getInitParameter(name));
			}
		}
	}
}
 
Example 12
Source File: XtextResourcesServlet.java    From xtext-web with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void init(ServletConfig config) throws ServletException {
	super.init(config);
	String disableCache = config.getInitParameter("disableCache");
	if (disableCache != null) {
		this.disableCache = Boolean.parseBoolean(disableCache);
	}
}
 
Example 13
Source File: TagHandlerPool.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
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 14
Source File: CXFNonSpringJaxrsServlet.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected boolean isAppResourceLifecycleASingleton(Application app, ServletConfig servletConfig) {
    String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM);
    if (scope == null) {
        scope = (String)app.getProperties().get(SERVICE_SCOPE_PARAM);
    }
    return SERVICE_SCOPE_SINGLETON.equals(scope);
}
 
Example 15
Source File: ViewProctorSpecificationServlet.java    From proctor with Apache License 2.0 5 votes vote down vote up
@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);
    final String proctorSpecPathParameter = config.getInitParameter("proctorSpecPath");
    if (StringUtils.isNotBlank(proctorSpecPathParameter)) {
        proctorSpecPath = proctorSpecPathParameter;
    }
}
 
Example 16
Source File: GatewayServlet.java    From hadoop-mini-clusters with Apache License 2.0 5 votes vote down vote up
private static GatewayFilter createFilter( ServletConfig servletConfig ) throws ServletException {
    GatewayFilter filter;
    InputStream stream;
    String location = servletConfig.getInitParameter( GATEWAY_DESCRIPTOR_LOCATION_PARAM );
    if( location != null ) {
        stream = servletConfig.getServletContext().getResourceAsStream( location );
        if( stream == null ) {
            stream = servletConfig.getServletContext().getResourceAsStream( "/WEB-INF/" + location );
        }
    } else {
        stream = servletConfig.getServletContext().getResourceAsStream( GATEWAY_DESCRIPTOR_LOCATION_DEFAULT );
    }
    filter = createFilter( stream );
    return filter;
}
 
Example 17
Source File: FakeServletConfig.java    From validator-web with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private Map<String, String> getInitParametersInServletConfig(ServletConfig servletConfig) {
    Map<String , String> initParameters = new HashMap<String, String>();
    Enumeration<String> params = servletConfig.getInitParameterNames();
    while (params.hasMoreElements()) {
        String name = params.nextElement();
        String value = servletConfig.getInitParameter(name);
        initParameters.put(name, value);
    }
    return Collections.unmodifiableMap(initParameters);
}
 
Example 18
Source File: WorkbenchGateway.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void init(final ServletConfig config) throws ServletException {
	super.init(config);
	if (getDefaultServerPath() == null) {
		throw new MissingInitParameterException(DEFAULT_SERVER);
	}
	if (config.getInitParameter(TRANSFORMATIONS) == null) {
		throw new MissingInitParameterException(TRANSFORMATIONS);
	}
	this.cookies = new CookieHandler(config);
	this.serverValidator = new ServerValidator(config);
}
 
Example 19
Source File: AccountServlet.java    From tutorials with MIT License 4 votes vote down vote up
public void init(ServletConfig config) throws ServletException {
    accountType = config.getInitParameter("type");
}
 
Example 20
Source File: CrossDomainManager.java    From yawp with MIT License 4 votes vote down vote up
private String getExposeHeadersFromConfig(ServletConfig config) {
    return config.getInitParameter(CROSS_DOMAIN_EXPOSE_HEADERS_PARAM);
}