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

The following examples show how to use javax.servlet.ServletConfig#getServletName() . 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: HttpServletBean.java    From spring-analysis-note 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 2
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 3
Source File: HttpServletBean.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 = (!CollectionUtils.isEmpty(requiredProperties) ?
			new HashSet<String>(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 4
Source File: HttpServletBean.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * 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, ", "));
	}
}
 
Example 5
Source File: VaadinServlet.java    From usergrid with Apache License 2.0 6 votes vote down vote up
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 6
Source File: ServletHttpHandlerAdapter.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private String getServletPath(ServletConfig config) {
	String name = config.getServletName();
	ServletRegistration registration = config.getServletContext().getServletRegistration(name);
	if (registration == null) {
		throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'");
	}

	Collection<String> mappings = registration.getMappings();
	if (mappings.size() == 1) {
		String mapping = mappings.iterator().next();
		if (mapping.equals("/")) {
			return "";
		}
		if (mapping.endsWith("/*")) {
			String path = mapping.substring(0, mapping.length() - 2);
			if (!path.isEmpty() && logger.isDebugEnabled()) {
				logger.debug("Found servlet mapping prefix '" + path + "' for '" + name + "'");
			}
			return path;
		}
	}

	throw new IllegalArgumentException("Expected a single Servlet mapping: " +
			"either the default Servlet mapping (i.e. '/'), " +
			"or a path based mapping (e.g. '/*', '/foo/*'). " +
			"Actual mappings: " + mappings + " for Servlet '" + name + "'");
}
 
Example 7
Source File: ServletHttpHandlerAdapter.java    From java-technology-stack with MIT License 5 votes vote down vote up
private String getServletPath(ServletConfig config) {
	String name = config.getServletName();
	ServletRegistration registration = config.getServletContext().getServletRegistration(name);
	if (registration == null) {
		throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'");
	}

	Collection<String> mappings = registration.getMappings();
	if (mappings.size() == 1) {
		String mapping = mappings.iterator().next();
		if (mapping.equals("/")) {
			return "";
		}
		if (mapping.endsWith("/*")) {
			String path = mapping.substring(0, mapping.length() - 2);
			if (!path.isEmpty() && logger.isDebugEnabled()) {
				logger.debug("Found servlet mapping prefix '" + path + "' for '" + name + "'");
			}
			return path;
		}
	}

	throw new IllegalArgumentException("Expected a single Servlet mapping: " +
			"either the default Servlet mapping (i.e. '/'), " +
			"or a path based mapping (e.g. '/*', '/foo/*'). " +
			"Actual mappings: " + mappings + " for Servlet '" + name + "'");
}
 
Example 8
Source File: KSBDispatcherServlet.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * This is a workaround after upgrading to CXF 2.7.0 whereby we could no longer just call "setHideServiceList" on
 * the ServletController. Instead, it is now reading this information from the ServletConfig, so wrapping the base
 * ServletContext to return true or false for hide service list depending on whether or not we are in dev mode.
 */
protected ServletConfig getCXFServletConfig(final ServletConfig baseServletConfig) {
    // disable handling of URLs ending in /services which display CXF generated service lists if we are not in dev mode
    final String shouldHide = Boolean.toString(!ConfigContext.getCurrentContextConfig().getDevMode().booleanValue());
    return new ServletConfig() {
        private static final String HIDE_SERVICE_LIST_PAGE_PARAM = "hide-service-list-page";
        @Override
        public String getServletName() {
            return baseServletConfig.getServletName();
        }
        @Override
        public ServletContext getServletContext() {
            return baseServletConfig.getServletContext();
        }
        @Override
        public String getInitParameter(String parameter) {
            if (HIDE_SERVICE_LIST_PAGE_PARAM.equals(parameter)) {
                return shouldHide;
            }
            return baseServletConfig.getInitParameter(parameter);
        }
        @Override
        public Enumeration<String> getInitParameterNames() {
            List<String> initParameterNames = EnumerationUtils.toList(baseServletConfig.getInitParameterNames());
            initParameterNames.add(HIDE_SERVICE_LIST_PAGE_PARAM);
            return new Vector<String>(initParameterNames).elements();
        }
    };
}
 
Example 9
Source File: FerretData.java    From sample.ferret with Apache License 2.0 5 votes vote down vote up
public FerretData(final ServletConfig servletConfig, final ServletContext servletContext,
        final HttpServletRequest httpServletRequest) {
    requestedUrl = httpServletRequest.getRequestURL().toString();
    servletName = servletConfig.getServletName();
    requestData = new RequestData(httpServletRequest);

    servletContextAttributes = getServletContextAttributes(servletContext);
}
 
Example 10
Source File: FakeServletConfig.java    From validator-web with Apache License 2.0 4 votes vote down vote up
/**
 * Copy the values from another {@link ServletConfig} so we can modify them.
 * @param servletConfig
 */
public FakeServletConfig(ServletConfig servletConfig) {
    this.name = servletConfig.getServletName();
    this.servletContext = servletConfig.getServletContext();
    this.initParameters = getInitParametersInServletConfig(servletConfig);
}
 
Example 11
Source File: OneConfig.java    From hasor with Apache License 2.0 4 votes vote down vote up
public OneConfig(ServletConfig config, Supplier<AppContext> appContext) {
    this();
    this.resourceName = config.getServletName();
    this.appContext = appContext;
    this.putConfig(config, true);
}
 
Example 12
Source File: Logger.java    From webstart with MIT License 4 votes vote down vote up
/**
 * Initialize logging object. It reads the logLevel and pathLevel init parameters.
 * Default is logging level FATAL, and logging using the ServletContext.log
 *
 * @param config    TODO
 * @param resources TODO
 */
public Logger( ServletConfig config, ResourceBundle resources )
{
    _resources = resources;
    _servletContext = config.getServletContext();
    _servletName = config.getServletName();
    _logFile = config.getInitParameter( LOG_PATH );
    if ( _logFile != null )
    {
        _logFile = _logFile.trim();
        if ( _logFile.length() == 0 )
        {
            _logFile = null;
        }
    }
    String level = config.getInitParameter( LOG_LEVEL );
    if ( level != null )
    {
        level = level.trim().toUpperCase();
        if ( level.equals( NONE_KEY ) )
        {
            _loggingLevel = NONE;
        }
        if ( level.equals( FATAL_KEY ) )
        {
            _loggingLevel = FATAL;
        }
        if ( level.equals( WARNING_KEY ) )
        {
            _loggingLevel = WARNING;
        }
        if ( level.equals( INFORMATIONAL_KEY ) )
        {
            _loggingLevel = INFORMATIONAL;
        }
        if ( level.equals( DEBUG_KEY ) )
        {
            _loggingLevel = DEBUG;
        }
    }
}
 
Example 13
Source File: SynchronizationServlet.java    From ontopia with Apache License 2.0 4 votes vote down vote up
@Override
public void init(ServletConfig config) throws ServletException {
  super.init(config);
  log.info("Initializing synchronization servlet.");

  try {
    // no default starttime
    Date time = null;
    long delay = 180*1000;
    String timeval = config.getInitParameter("start-time");
    if (timeval != null) {
      Date d = df.parse(timeval);
      Calendar c0 = Calendar.getInstance();
      Calendar c = Calendar.getInstance();
      c.set(Calendar.HOUR_OF_DAY, 1);
      c.set(Calendar.MINUTE, 0);
      c.add(Calendar.MILLISECOND, (int)d.getTime());
      if (c.before(c0))
        c.add(Calendar.HOUR_OF_DAY, 24);
      time = c.getTime();
      log.info("Setting synchronization start time to {} ms.", time);
    } else {
      // default delay is 180 sec.
      delay = getLongProperty(config, "delay", delay);
      log.info("Setting synchronization delay to {} ms.", delay);
    }
    
    // default interval is 24 hours.
    long interval = getLongProperty(config, "interval", 1000*60*60*24);
    log.info("Setting synchronization interval to {} ms.", interval);
    
    // load relation mapping file
    String mapping = config.getInitParameter("mapping");
    if (mapping == null)
      throw new OntopiaRuntimeException("Servlet init-param 'mapping' must be specified.");
    
    // get relation names (comma separated)
    Collection<String> relnames = null;
    String relations = config.getInitParameter("relations");
    if (relations != null)
      relnames = Arrays.asList(StringUtils.split(relations, ","));
    
    // get hold of the topic map
    String tmid = config.getInitParameter("topicmap");
    if (tmid == null)
      throw new OntopiaRuntimeException("Servlet init-param 'topicmap' must be specified.");
    TopicMapRepositoryIF rep = NavigatorUtils.getTopicMapRepository(config.getServletContext());
    TopicMapReferenceIF ref = rep.getReferenceByKey(tmid);
    
    // make sure delay is at least 10 seconds to make sure that it doesn't
    // start too early
    if (time == null)
      task = new SynchronizationTask(config.getServletName(),
                                     (delay < 10000 ? 10000 : delay),
                                     interval);
    else 
      task = new SynchronizationTask(config.getServletName(), time, interval);
    
    task.setRelationMappingFile(mapping);
    task.setRelationNames(relnames);
    task.setTopicMapReference(ref);
    task.setBaseLocator(null);
    
  } catch (Exception e) {
    throw new ServletException(e);
  }
}
 
Example 14
Source File: XmlHttpProxyServlet.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ctx = config.getServletContext();
    // set the response content type
    if (ctx.getInitParameter("responseContentType") != null) {
        defaultContentType = ctx.getInitParameter("responseContentType");
    }
    // allow for resources dir over-ride at the xhp level otherwise allow
    // for the jmaki level resources
    if (ctx.getInitParameter("jmaki-xhp-resources") != null) {
        resourcesDir = ctx.getInitParameter("jmaki-xhp-resources");
    } else if (ctx.getInitParameter("jmaki-resources") != null) {
        resourcesDir = ctx.getInitParameter("jmaki-resources");
    }
    // allow for resources dir over-ride
    if (ctx.getInitParameter("jmaki-classpath-resources") != null) {
        classpathResourcesDir = ctx.getInitParameter("jmaki-classpath-resources");
    }
    String requireSessionString = ctx.getInitParameter("requireSession");
    if (requireSessionString == null) requireSessionString = ctx.getInitParameter("jmaki-requireSession");
    if (requireSessionString != null) {
        if ("false".equals(requireSessionString)) {
            requireSession = false;
            getLogger().severe("XmlHttpProxyServlet: intialization. Session requirement disabled.");
        } else if ("true".equals(requireSessionString)) {
            requireSession = true;
            getLogger().severe("XmlHttpProxyServlet: intialization. Session requirement enabled.");
        }
    }
    String xdomainString = ctx.getInitParameter("allowXDomain");
    if (xdomainString == null) xdomainString = ctx.getInitParameter("jmaki-allowXDomain");
    if (xdomainString != null) {
        if ("true".equals(xdomainString)) {
            allowXDomain = true;
            getLogger().severe("XmlHttpProxyServlet: intialization. xDomain access is enabled.");
        } else if ("false".equals(xdomainString)) {
            allowXDomain = false;
            getLogger().severe("XmlHttpProxyServlet: intialization. xDomain access is disabled.");
        }
    }
    String createSessionString = ctx.getInitParameter("jmaki-createSession");
    if (createSessionString != null) {
        if ("true".equals(createSessionString)) {
            createSession = true;
            getLogger().severe("XmlHttpProxyServlet: intialization. create session is enabled.");
        } else if ("false".equals(xdomainString)) {
            createSession = false;
            getLogger().severe("XmlHttpProxyServlet: intialization. create session is disabled.");
        }
    }
    // if there is a proxyHost and proxyPort specified create an HttpClient with the proxy
    String proxyHost = ctx.getInitParameter("proxyHost");
    String proxyPortString = ctx.getInitParameter("proxyPort");
    if (proxyHost != null && proxyPortString != null) {
        int proxyPort = 8080;
        try {
            proxyPort= new Integer(proxyPortString).intValue();
            xhp = new XmlHttpProxy(proxyHost, proxyPort);
        } catch (NumberFormatException nfe) {
            getLogger().severe("XmlHttpProxyServlet: intialization error. The proxyPort must be a number");
            throw new ServletException("XmlHttpProxyServlet: intialization error. The proxyPort must be a number");
        }
    } else {
        xhp = new XmlHttpProxy();
    }

    // config override
    String servletName = config.getServletName();
    String configName = config.getInitParameter("config.name");
    configResource = configName!=null ? configName : DEFAULT_CONFIG;
    //System.out.println("Configure "+servletName + " through "+configResource);
}