Example usage for javax.servlet ServletConfig getInitParameter

List of usage examples for javax.servlet ServletConfig getInitParameter

Introduction

In this page you can find the example usage for javax.servlet ServletConfig getInitParameter.

Prototype

public String getInitParameter(String name);

Source Link

Document

Gets the value of the initialization parameter with the given name.

Usage

From source file:com.vaadin.grails.terminal.gwt.server.GrailsAwareGAEApplicationServlet.java

/**
 * Called by the servlet container to indicate to a servlet that the servlet
 * is being placed into service./*  w  w w  . j  a v a 2 s  . co m*/
 * <p/>
 * This implementation caches the application class name (not the class
 * itself) to use to acquire the Application class from the Grails
 * classloader at runtime.
 * 
 * @param servletConfig
 *            the object containing the servlet's configuration and
 *            initialization parameters
 * @throws ServletException
 *             if an exception has occurred that interferes with the
 *             servlet's normal operation.
 */
@SuppressWarnings("unchecked")
@Override
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    // Gets the application class name
    final String applicationClassName = servletConfig.getInitParameter("application");
    if (applicationClassName == null) {
        throw new ServletException(
                "The 'application' servlet init parameter was not specified.  This parameter "
                        + "must be specified with a value of a fully qualified class name of a class that extends "
                        + "com.vaadin.Application.");
    }

    this.applicationClassName = applicationClassName;
    // make sure it exists at startup:
    try {
        getApplicationClass();
    } catch (UnavailableClassException e) {
        throw new ServletException("Failed to load application class: " + this.applicationClassName, e);
    }
}

From source file:be.fedict.eid.applet.service.AppletServiceServlet.java

public static void injectInitParams(ServletConfig config, MessageHandler<?> messageHandler)
        throws ServletException, IllegalArgumentException, IllegalAccessException {
    Class<?> messageHandlerClass = messageHandler.getClass();
    Field[] fields = messageHandlerClass.getDeclaredFields();
    for (Field field : fields) {
        InitParam initParamAnnotation = field.getAnnotation(InitParam.class);
        if (null == initParamAnnotation) {
            continue;
        }//from w  ww.  j  a  v a  2 s.  c o m
        String initParamName = initParamAnnotation.value();
        Class<?> fieldType = field.getType();
        field.setAccessible(true);
        if (ServiceLocator.class.equals(fieldType)) {
            /*
             * We always inject a service locator.
             */
            ServiceLocator<Object> fieldValue = new ServiceLocator<Object>(initParamName, config);
            field.set(messageHandler, fieldValue);
            continue;
        }
        String initParamValue = config.getInitParameter(initParamName);
        if (initParamAnnotation.required() && null == initParamValue) {
            throw new ServletException("missing required init-param: " + initParamName + " for message handler:"
                    + messageHandlerClass.getName());
        }
        if (null == initParamValue) {
            continue;
        }
        if (Boolean.TYPE.equals(fieldType)) {
            LOG.debug("injecting boolean: " + initParamValue);
            Boolean fieldValue = Boolean.parseBoolean(initParamValue);
            field.set(messageHandler, fieldValue);
            continue;
        }
        if (String.class.equals(fieldType)) {
            field.set(messageHandler, initParamValue);
            continue;
        }
        if (InetAddress.class.equals(fieldType)) {
            InetAddress inetAddress;
            try {
                inetAddress = InetAddress.getByName(initParamValue);
            } catch (UnknownHostException e) {
                throw new ServletException("unknown host: " + initParamValue);
            }
            field.set(messageHandler, inetAddress);
            continue;
        }
        if (Long.class.equals(fieldType)) {
            Long fieldValue = Long.parseLong(initParamValue);
            field.set(messageHandler, fieldValue);
            continue;
        }
        throw new ServletException("unsupported init-param field type: " + fieldType.getName());
    }
}

From source file:nl.b3p.gis.viewer.services.HibernateUtil.java

/**
 * Initializes the servlet.//  w w  w .j  ava  2s  .  co m
 *
 * @param config
 * @throws javax.servlet.ServletException
 */
@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    try {
        String value = config.getInitParameter("kburl");
        if (value != null && value.length() > 0) {
            kburl = value;
        }
        value = config.getInitParameter("internalKbUrl");
        if (value != null && value.length() > 0) {
            internalKbUrl = value;
        }
        value = config.getInitParameter("check_login_kaartenbalie");
        if (value != null && value.equalsIgnoreCase("false")) {
            checkLoginKaartenbalie = false;
        }
        value = config.getInitParameter("use_kaartenbalie_cluster");
        if (value != null && value.equalsIgnoreCase("false")) {
            useKaartenbalieCluster = false;
        }
        value = config.getInitParameter("anonymous_user");
        if (value != null && value.length() > 0) {
            ANONYMOUS_USER = value;
        }
        value = config.getInitParameter("gebruikers_rol");
        if (value != null && value.length() > 0) {
            GEBRUIKERS_ROL = value;
        }
        value = config.getInitParameter("themabeheerders_rol");
        if (value != null && value.length() > 0) {
            THEMABEHEERDERS_ROL = value;
        }
        value = config.getInitParameter("loginKbUrl");
        if (value != null && value.length() > 0) {
            loginKbUrl = value;
        }

        if (config.getInitParameter("cacheOnDisk") != null) {
            cacheOnDisk = Boolean.parseBoolean(config.getInitParameter("cacheOnDisk"));
        }
        if (config.getInitParameter("cacheOnDiskPath") != null) {
            cacheOnDiskPath = config.getInitParameter("cacheOnDiskPath");
        }
    } catch (Exception e) {
        throw new ServletException(e);
    }
}

From source file:org.openlaszlo.servlets.HistoryServlet.java

private String getInitParameter(ServletConfig config, String name, String defaultValue) {
    String value = config.getInitParameter(name);
    mLogger.debug("web.xml value for " + name + " is " + value);
    return (value != null ? value : defaultValue);
}

From source file:org.jboss.datavirt.commons.ui.header.DataVirtHeaderDataJS.java

/**
 * @see javax.servlet.GenericServlet#init()
 *//* ww w .  j  a  v a  2 s .c  o m*/
@Override
public void init() throws ServletException {
    ServletConfig config = getServletConfig();
    appId = config.getInitParameter("app-id");
    if (appId == null || appId.trim().length() == 0) {
        throw new ServletException(
                "Application identifier (app-id) parameter missing from DataVirt Header Data JS servlet.");
    }
    logoutUrl = config.getInitParameter("logout-url");
    if (logoutUrl == null || logoutUrl.trim().length() == 0) {
        logoutUrl = "?GLO=true";
    }
}

From source file:cn.vlabs.duckling.vwb.ui.servlet.SimpleUploaderServlet.java

public void init(ServletConfig config) throws ServletException {

    debug = (new Boolean(config.getInitParameter("debug"))).booleanValue();
    log.debug("---- SimpleUploaderServlet initialization started ----");
    enabled = Boolean.valueOf(config.getInitParameter("enabled"));
    allowedExtensions = parseParams(config.getInitParameter("AllowedExtensionsFile"));
    deniedExtensions = parseParams(config.getInitParameter("DeniedExtensionsFile"));

    log.debug("---- SimpleUploaderServlet initialization completed ----");

}

From source file:com.lushapp.common.web.servlet.StaticContentServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    String cacheManager = config.getInitParameter("CacheManager");
    CacheManager ehcacheManager = (CacheManager) context.getBean(cacheManager);
    String cacheKey = config.getInitParameter("cacheKey");
    contentInfoCache = ehcacheManager.getCache(cacheKey);

    //?mimeTypes, css,.
    mimetypesFileTypeMap = new MimetypesFileTypeMap();
    mimetypesFileTypeMap.addMimeTypes("text/css css");
}

From source file:de.betterform.agent.web.resources.ResourceServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    if ("false".equals(config.getInitParameter("caching"))) {
        caching = false;//  w  ww  . j av  a 2s .c om
        if (LOG.isTraceEnabled()) {
            LOG.trace("Caching of Resources is disabled");
        }
    } else {
        caching = true;

        if (LOG.isTraceEnabled()) {
            LOG.trace("Caching of Resources is enabled - resources are loaded from classpath");
        }
    }
    this.lastModified = getLastModifiedValue();
    String path = null;
    try {
        path = WebFactory.getRealPath("WEB-INF/classes/META-INF/resources", config.getServletContext());
    } catch (XFormsConfigException e) {
        throw new ServletException(e);
    }
    if (path != null && new File(path).exists()) {
        exploded = true;
    }

    initMimeTypes();
    initResourceStreamers();
}

From source file:org.overlord.commons.ui.header.OverlordHeaderDataJS.java

/**
 * @see javax.servlet.GenericServlet#init()
 *///from ww  w . ja v  a  2  s .  c o  m
@Override
public void init() throws ServletException {
    ServletConfig config = getServletConfig();
    appId = config.getInitParameter("app-id"); //$NON-NLS-1$
    if (appId == null || appId.trim().length() == 0) {
        throw new ServletException(
                "Application identifier (app-id) parameter missing from Overlord Header Data JS servlet."); //$NON-NLS-1$
    }
    logoutUrl = config.getInitParameter("logout-url"); //$NON-NLS-1$
    if (logoutUrl == null || logoutUrl.trim().length() == 0) {
        logoutUrl = "?GLO=true"; //$NON-NLS-1$
    }
}

From source file:com.iorga.iraj.servlet.AgglomeratorServlet.java

@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);

    if (config.getInitParameter("mode") != null) {
        mode = Mode.valueOf(config.getInitParameter("mode").toUpperCase());
    }/*from ww  w  .j a v a2 s .c om*/
    if (mode == Mode.DEVELOPMENT) {
        // development mode, activate the watch service
        try {
            watchService = FileSystems.getDefault().newWatchService();
        } catch (final IOException e) {
            throw new ServletException("Problem while activating the watch service", e);
        }
    }

    parseResourcesFromMappings(config);

    if (mode == Mode.DEVELOPMENT) {
        directoryWatcherThread = new Thread(new DirectoryWatcher(), DirectoryWatcher.class.getName());
        directoryWatcherThread.setDaemon(true);
        directoryWatcherThread.start();
    }
}