类javax.servlet.ServletConfig源码实例Demo

下面列出了怎么用javax.servlet.ServletConfig的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: JaxRSProviders   文件: CXFNonSpringJaxrsServlet.java
protected Map<Class<?>, ResourceProvider> getResourceProviders(ServletConfig servletConfig,
        Map<Class<?>, Map<String, List<String>>> resourceClasses) throws ServletException {
    String scope = servletConfig.getInitParameter(SERVICE_SCOPE_PARAM);
    if (scope != null && !SERVICE_SCOPE_SINGLETON.equals(scope)
        && !SERVICE_SCOPE_REQUEST.equals(scope)) {
        throw new ServletException("Only singleton and prototype scopes are supported");
    }
    boolean isPrototype = SERVICE_SCOPE_REQUEST.equals(scope);
    Map<Class<?>, ResourceProvider> map = new HashMap<>();
    for (Map.Entry<Class<?>, Map<String, List<String>>> entry : resourceClasses.entrySet()) {
        Class<?> c = entry.getKey();
        map.put(c, isPrototype ? new PerRequestResourceProvider(c)
                               : new SingletonResourceProvider(
                                     createSingletonInstance(c, entry.getValue(), servletConfig),
                                     true));
    }
    return map;
}
 
源代码2 项目: scipio-erp   文件: CmsMediaServlet.java
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    this.useCacheDefault = UtilMisc.booleanValue(config.getInitParameter("useCache"), true);
    String useCacheParam = config.getInitParameter("useCacheParam");
    if (useCacheParam != null && !"true".equals(useCacheParam)) {
        if (useCacheParam.isEmpty() || "false".equals(useCacheParam)) {
            this.useCacheParam = null;
        } else {
            this.useCacheParam = useCacheParam;
        }
    }
    if (Debug.infoOn()) {
        Debug.logInfo("Cms: Media servlet settings for servlet '" + config.getServletName() + "' of webapp '"
                + config.getServletContext().getContextPath() + "': [" 
                + "useCache=" + this.useCacheDefault + ", useCacheParam="
                + (this.useCacheParam != null ? this.useCacheParam : "(disabled)")+ "]", module);
    }
}
 
源代码3 项目: swagger-aem   文件: Bootstrap.java
@Override
public void init(ServletConfig config) throws ServletException {
  Info info = new Info()
    .title("OpenAPI Server")
    .description("Swagger AEM is an OpenAPI specification for Adobe Experience Manager (AEM) API")
    .termsOfService("")
    .contact(new Contact()
      .email("[email protected]"))
    .license(new License()
      .name("")
      .url("http://unlicense.org"));

  ServletContext context = config.getServletContext();
  Swagger swagger = new Swagger().info(info);

  new SwaggerContextService().withServletConfig(config).updateSwagger(swagger);
}
 
@Test
public void testInterceptionServlet_noKarafEtc_forbidden() throws Exception {

	// Mocks
	HttpServletResponse resp = Mockito.mock( HttpServletResponse.class );
	HttpServletRequest req = Mockito.mock( HttpServletRequest.class );
	Mockito.when( req.getServletPath()).thenReturn( "invalid-resource" );

	ServletConfig sc = Mockito.mock( ServletConfig.class );
	ServletContext ctx = Mockito.mock( ServletContext.class );
	Mockito.when( sc.getServletContext()).thenReturn( ctx );

	// Initialization
	WebAdminInterceptionServlet servlet = new WebAdminInterceptionServlet();
	servlet.init( sc );
	servlet.karafEtc = "";

	// Execution
	servlet.doGet( req, resp );

	// Assertions
	Mockito.verify( req, Mockito.atLeast( 1 )).getServletPath();
	Mockito.verify( resp, Mockito.only()).sendError( HttpServletResponse.SC_FORBIDDEN );
}
 
源代码5 项目: spring4-understanding   文件: HttpServletBean.java
/**
 * Create new ServletConfigPropertyValues.
 * @param config 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 = (requiredProperties != null && !requiredProperties.isEmpty()) ?
			new HashSet<String>(requiredProperties) : null;

	Enumeration<String> en = config.getInitParameterNames();
	while (en.hasMoreElements()) {
		String property = en.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 (missingProps != null && missingProps.size() > 0) {
		throw new ServletException(
			"Initialization from ServletConfig for servlet '" + config.getServletName() +
			"' failed; the following required properties were missing: " +
			StringUtils.collectionToDelimitedString(missingProps, ", "));
	}
}
 
源代码6 项目: webmvc   文件: PlacesProxyServlet.java
@Override
public void init() throws ServletException {
	super.init();
	ServletConfig config = getServletConfig();
       placesUrl = config.getInitParameter("PlacesUrl");
       apiKey = config.getInitParameter("GoogleApiKey");
       // Allow override with system property
       try {
       	placesUrl = System.getProperty("PlacesUrl", placesUrl);
       	apiKey = System.getProperty("GoogleApiKey", apiKey);
       } catch (SecurityException e) {
       }
       if (null == placesUrl) {
       	placesUrl = "https://maps.googleapis.com/maps/api/place/search/json";
       }
}
 
源代码7 项目: swaggy-jenkins   文件: ApiApi.java
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;
}
 
源代码8 项目: openapi-generator   文件: FakeApi.java
public FakeApi(@Context ServletConfig servletContext) {
   FakeApiService delegate = null;

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

   if (delegate == null) {
      delegate = FakeApiServiceFactory.getFakeApi();
   }

   this.delegate = delegate;
}
 
源代码9 项目: java-docs-samples   文件: AbstractRestServlet.java
@Override
public void init(ServletConfig servletConfig) throws ServletException {
  // First try the servlet context init-param.
  String source = "InitParameter";
  key = servletConfig.getInitParameter(APPKEY);
  if (key == null || key.startsWith("${")) {
    source = "System Property";
    key = System.getProperty(APPKEY);
  }
  if (key == null || key.startsWith("${")) {
    source = "Environment Variable";
    key = System.getenv(APPKEY_ENV);
  }
  if (key == null) {
    throw new UnavailableException("Places App Key not set");
  }
  if (key.startsWith("${")) {
    throw new UnavailableException("Places App Key not expanded from " + source);
  }
}
 
源代码10 项目: BIMserver   文件: GenericWebServiceServlet.java
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);
}
 
源代码11 项目: Tomcat7.0.67   文件: 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);
}
 
源代码12 项目: sakai   文件: MessageForumsFilePickerServlet.java
/**
 * Initialize the servlet.
 * 
 * @param config
 *        The servlet config.
 * @throws ServletException
 */
public void init(ServletConfig config) throws ServletException {
  super.init(config);
  
  try {
    //load service level dependecies from the ComponentManager
    siteService = (SiteService) ComponentManager.get("org.sakaiproject.site.api.SiteService");
    accessProviderManager = (HttpServletAccessProviderManager) ComponentManager
      .get("org.sakaiproject.entitybroker.access.HttpServletAccessProviderManager");
    forumManager = (DiscussionForumManager) ComponentManager
      .get("org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager");
    
    //register forum Entity prefixes for direct servlet request handling
    if (accessProviderManager != null) {
      accessProviderManager.registerProvider("forum_topic", this);
      accessProviderManager.registerProvider("forum", this);
      accessProviderManager.registerProvider("forum_message", this);
    }
    //mark initialization of dependecies as complete
    if (siteService != null && forumManager != null)
      initComplete = true;
  } catch (Exception e) {
    log.error(e.getMessage(), e);
  }
}
 
源代码13 项目: tomcatsrc   文件: PerThreadTagHandlerPool.java
@Override
protected void init(ServletConfig config) {
    maxSize = Constants.MAX_POOL_SIZE;
    String maxSizeS = getOption(config, OPTION_MAXSIZE, null);
    if (maxSizeS != null) {
        maxSize = Integer.parseInt(maxSizeS);
        if (maxSize < 0) {
            maxSize = Constants.MAX_POOL_SIZE;
        }
    }

    perThread = new ThreadLocal<PerThreadData>() {
        @Override
        protected PerThreadData initialValue() {
            PerThreadData ptd = new PerThreadData();
            ptd.handlers = new Tag[maxSize];
            ptd.current = -1;
            perThreadDataVector.addElement(ptd);
            return ptd;
        }
    };
}
 
源代码14 项目: glowroot   文件: GlowrootServlet.java
@Override
public void init(ServletConfig config) throws ServletException {
    try {
        File centralDir = getCentralDir();
        File propFile = new File(centralDir, "glowroot-central.properties");
        if (!propFile.exists()) {
            Files.copy(config.getServletContext().getResourceAsStream(
                    "/META-INF/glowroot-central.properties"), propFile.toPath());
        }
        centralModule =
                CentralModule.createForServletContainer(centralDir, config.getServletContext());
        commonHandler = centralModule.getCommonHandler();
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
 
源代码15 项目: sakai   文件: ReasonableSakaiServlet.java
public void init(ServletConfig config) {
	try {
		super.init(config);
		ServletContext context = getServletContext();
		Logger.log.info("ReasonableSakaiServlet starting up for context " + context.getRealPath(""));

		WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(context);
		if (wac == null) {
			throw new IllegalStateException(
					"Error acquiring web application context " + "- servlet context not configured correctly");
		}
		rsacbl = (RSACBeanLocator) wac.getBean(RSACBeanLocator.RSAC_BEAN_LOCATOR_NAME);
	} catch (Throwable t) {
		Logger.log.warn("Error initialising SakaiRSF servlet: ", t);
	}
}
 
源代码16 项目: dependency-track   文件: NvdMirrorServlet.java
/**
 * {@inheritDoc}
 */
@Override
public void init(final ServletConfig config) throws ServletException {
    LOGGER.info("Initializing NVD mirror");
    super.init(config);
    super.setDirectory(NistMirrorTask.NVD_MIRROR_DIR);
    super.setAbsolute(true);
}
 
源代码17 项目: UDepLambda   文件: QueryUDP.java
/**
 * @see Servlet#init(ServletConfig)
 */
public void init(ServletConfig config) throws ServletException {
  super.init(config);
  Enumeration<String> enm = config.getInitParameterNames();
  while (enm.hasMoreElements()) {
    String name = enm.nextElement();
    String value = config.getInitParameter(name);
    if (name.endsWith("UdpEndPoint")) {
      udpEndPoints.put(name, value);
    }
  }
}
 
源代码18 项目: sakai   文件: RedirectingAssignmentEntityServlet.java
/**
 * Initialize the servlet.
 * 
 * @param config
 *            The servlet config.
 * @throws ServletException
 */
public void init(ServletConfig config) throws ServletException {
	log.info("init()");
	super.init(config);
	entityBroker = (EntityBroker) ComponentManager
			.get("org.sakaiproject.entitybroker.EntityBroker");
	sessionManager = (SessionManager) ComponentManager
			.get("org.sakaiproject.tool.api.SessionManager");
	accessProviderManager = (EntityViewAccessProviderManager) ComponentManager
			.get("org.sakaiproject.entitybroker.access.EntityViewAccessProviderManager");
	if (accessProviderManager != null) {
		accessProviderManager.registerProvider(
				AssignmentEntityProvider.ENTITY_PREFIX, this);
	}
}
 
源代码19 项目: sakai   文件: WebServlet.java
@Override
public void init(ServletConfig config) throws ServletException
{
	super.init(config);
	
	contentHostingService = ComponentManager.get(ContentHostingService.class);
	userDirectoryService = ComponentManager.get(UserDirectoryService.class);
}
 
@Override
public void init(
  ServletConfig config) 
  throws ServletException 
{

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

}
 
源代码21 项目: sakai   文件: VelocityDispatchServlet.java
@Override
public void init(ServletConfig config) throws ServletException
{
	super.init(config);
	ServletContext context = config.getServletContext();
	inlineDispatcher = new VelocityInlineDispatcher();
	inlineDispatcher.init(context);
}
 
源代码22 项目: aceql-http   文件: ServerSqlManagerInit.java
/**
    * Creates the data sources - this is called only if AceQL is used in Servlet
    * Container
    *
    * @param config
    * @throws IOException
    */
   private void createDataSources(ServletConfig config) throws IOException {
String propertiesFileStr = config.getInitParameter("properties");

if (propertiesFileStr == null || propertiesFileStr.isEmpty()) {
    throw new DatabaseConfigurationException(Tag.PRODUCT_USER_CONFIG_FAIL
	    + " AceQL servlet param-name \"properties\" not set. Impossible to load the AceQL Server properties file.");
}

File propertiesFile = new File(propertiesFileStr);

if (!propertiesFile.exists()) {
    throw new DatabaseConfigurationException(
	    Tag.PRODUCT_USER_CONFIG_FAIL + " properties file not found: " + propertiesFile);
}

System.out.println(SqlTag.SQL_PRODUCT_START + " " + "Using properties file: ");
System.out.println(SqlTag.SQL_PRODUCT_START + "  -> " + propertiesFile);

// Set properties file. Will be used elsewhere
// (for CsvRulesManager load file, per example).
ServerSqlManager.setAceqlServerProperties(propertiesFile);
Properties properties = TomcatStarterUtil.getProperties(propertiesFile);

TomcatStarterUtil.setInitParametersInStore(properties);

// Create the default DataSource if necessary
TomcatStarterUtil.createAndStoreDataSources(properties);

   }
 
@Override
public void init( ServletConfig sc )
    throws ServletException
{
    super.init( sc );
    
    // Registered by CustomWebAppResourcesServiceListener
    ResourcesService  service = ResourcesServicesRegistry.getRegistry().getServices().get( 0 );
    String address = "/resources";
    Endpoint e = javax.xml.ws.Endpoint.publish( address,
                                   new JAXWSResourcesServiceImpl(service) );
    System.err.println(e);

}
 
源代码24 项目: qconfig   文件: UpdatePublicServlet.java
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ApplicationContext context = (ApplicationContext) config.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    if (context == null) {
        throw new ServletException("init failed");
    }
    this.cacheConfigTypeService = context.getBean(CacheConfigTypeService.class);
    this.filePublicStatusDao = context.getBean(FilePublicStatusDao.class);
    Preconditions.checkNotNull(this.cacheConfigTypeService);
}
 
源代码25 项目: JaxRSProviders   文件: CXFNonSpringJaxrsServlet.java
protected void createServerFromApplication(String applicationNames, ServletConfig servletConfig)
    throws ServletException {

    boolean ignoreApplicationPath = isIgnoreApplicationPath(servletConfig);

    String[] classNames = applicationNames.split(getParameterSplitChar(servletConfig));

    if (classNames.length > 1 && ignoreApplicationPath) {
        throw new ServletException("\"" + IGNORE_APP_PATH_PARAM
            + "\" parameter must be set to false for multiple Applications be supported");
    }

    for (String cName : classNames) {
        ApplicationInfo providerApp = createApplicationInfo(cName, servletConfig);

        Application app = providerApp.getProvider();
        JAXRSServerFactoryBean bean = ResourceUtils.createApplication(
                                            app,
                                            ignoreApplicationPath,
                                            getStaticSubResolutionValue(servletConfig),
                                            isAppResourceLifecycleASingleton(app, servletConfig),
                                            getBus());
        String splitChar = getParameterSplitChar(servletConfig);
        setAllInterceptors(bean, servletConfig, splitChar);
        setInvoker(bean, servletConfig);
        setExtensions(bean, servletConfig);
        setDocLocation(bean, servletConfig);
        setSchemasLocations(bean, servletConfig);

        List<?> providers = getProviders(servletConfig, splitChar);
        bean.setProviders(providers);
        List<? extends Feature> features = getFeatures(servletConfig, splitChar);
        bean.setFeatures(features);

        bean.setBus(getBus());
        bean.setApplicationInfo(providerApp);
        bean.create();
    }
}
 
源代码26 项目: ymate-platform-v2   文件: DispatchServlet.java
@Override
public void init(ServletConfig config) throws ServletException {
    __servletContext = config.getServletContext();
    //
    IWebMvcModuleCfg _moduleCfg = WebMVC.get().getModuleCfg();
    __dispatcher = new Dispatcher(_moduleCfg.getDefaultCharsetEncoding(), _moduleCfg.getDefaultContentType(), _moduleCfg.getRequestMethodParam());
    __requestPrefix = _moduleCfg.getRequestPrefix();
}
 
源代码27 项目: javamelody   文件: ReportServlet.java
/** {@inheritDoc} */
@Override
public void init(ServletConfig config) {
	this.servletConfig = config;
	httpAuth = new HttpAuth();
	LOG.debug("JavaMelody report servlet initialized");
}
 
源代码28 项目: java-technology-stack   文件: MockPageContext.java
/**
 * Create new MockServletConfig.
 * @param servletContext the ServletContext that the JSP page runs in
 * @param request the current HttpServletRequest
 * @param response the current HttpServletResponse
 * @param servletConfig the ServletConfig (hardly ever accessed from within a tag)
 */
public MockPageContext(@Nullable ServletContext servletContext, @Nullable HttpServletRequest request,
		@Nullable HttpServletResponse response, @Nullable ServletConfig servletConfig) {

	this.servletContext = (servletContext != null ? servletContext : new MockServletContext());
	this.request = (request != null ? request : new MockHttpServletRequest(servletContext));
	this.response = (response != null ? response : new MockHttpServletResponse());
	this.servletConfig = (servletConfig != null ? servletConfig : new MockServletConfig(servletContext));
}
 
源代码29 项目: light-task-scheduler   文件: H2ConsoleWebServlet.java
@Override
public void init(ServletConfig config) throws ServletException {
    ServletConfigFacade servletConfigFacade = new ServletConfigFacade(config);
    // http://h2database.com/html/features.html#connection_modes
    // http://h2database.com/html/features.html#auto_mixed_mode
    servletConfigFacade.setInitParameter("url", "jdbc:h2:mem:lts_admin;DB_CLOSE_DELAY=-1");
    servletConfigFacade.setInitParameter("user", "lts");
    servletConfigFacade.setInitParameter("password", "lts");
    servletConfigFacade.setInitParameter("webAllowOthers", "true");

    super.init(servletConfigFacade);
}
 
源代码30 项目: steam   文件: CompilePojoServlet.java
public void init(ServletConfig servletConfig) throws ServletException {
  super.init(servletConfig);
  try {
    servletPath = new File(servletConfig.getServletContext().getResource("/").getPath());
    if (VERBOSE) logger.info("servletPath = {}", servletPath);
  }
  catch (MalformedURLException e) {
    logger.error("init failed", e);
  }
}
 
 类所在包
 同包方法