下面列出了javax.servlet.jsp.tagext.JspTag#javax.servlet.ServletConfig 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
@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);
}
}
@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 );
}
/**
* 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, ", "));
}
}
@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";
}
}
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;
}
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;
}
@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);
}
}
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);
}
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);
}
/**
* 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);
}
}
@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;
}
};
}
@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);
}
}
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);
}
}
/**
* {@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);
}
/**
* @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);
}
}
}
/**
* 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);
}
}
@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();
}
@Override
public void init(ServletConfig config) throws ServletException
{
super.init(config);
ServletContext context = config.getServletContext();
inlineDispatcher = new VelocityInlineDispatcher();
inlineDispatcher.init(context);
}
/**
* 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);
}
@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);
}
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();
}
}
@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();
}
/** {@inheritDoc} */
@Override
public void init(ServletConfig config) {
this.servletConfig = config;
httpAuth = new HttpAuth();
LOG.debug("JavaMelody report servlet initialized");
}
/**
* 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));
}
@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);
}
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);
}
}