Example usage for javax.servlet ServletConfig getServletName

List of usage examples for javax.servlet ServletConfig getServletName

Introduction

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

Prototype

public String getServletName();

Source Link

Document

Returns the name of this servlet instance.

Usage

From source file:org.apache.pulsar.proxy.server.AdminProxyHandler.java

@Override
protected HttpClient createHttpClient() throws ServletException {
    ServletConfig config = getServletConfig();

    HttpClient client = newHttpClient();

    client.setFollowRedirects(true);//from   www  .j av  a  2 s.c o  m

    // Must not store cookies, otherwise cookies of different clients will mix.
    client.setCookieStore(new HttpCookieStore.Empty());

    Executor executor;
    String value = config.getInitParameter("maxThreads");
    if (value == null || "-".equals(value)) {
        executor = (Executor) getServletContext().getAttribute("org.eclipse.jetty.server.Executor");
        if (executor == null)
            throw new IllegalStateException("No server executor for proxy");
    } else {
        QueuedThreadPool qtp = new QueuedThreadPool(Integer.parseInt(value));
        String servletName = config.getServletName();
        int dot = servletName.lastIndexOf('.');
        if (dot >= 0)
            servletName = servletName.substring(dot + 1);
        qtp.setName(servletName);
        executor = qtp;
    }

    client.setExecutor(executor);

    value = config.getInitParameter("maxConnections");
    if (value == null)
        value = "256";
    client.setMaxConnectionsPerDestination(Integer.parseInt(value));

    value = config.getInitParameter("idleTimeout");
    if (value == null)
        value = "30000";
    client.setIdleTimeout(Long.parseLong(value));

    value = config.getInitParameter("requestBufferSize");
    if (value != null)
        client.setRequestBufferSize(Integer.parseInt(value));

    value = config.getInitParameter("responseBufferSize");
    if (value != null)
        client.setResponseBufferSize(Integer.parseInt(value));

    try {
        client.start();

        // Content must not be decoded, otherwise the client gets confused.
        client.getContentDecoderFactories().clear();

        // Pass traffic to the client, only intercept what's necessary.
        ProtocolHandlers protocolHandlers = client.getProtocolHandlers();
        protocolHandlers.clear();
        protocolHandlers.put(new RedirectProtocolHandler(client));

        return client;
    } catch (Exception x) {
        throw new ServletException(x);
    }
}

From source file:org.apache.tapestry.ApplicationServlet.java

/**
 *  Reads the application specification when the servlet is
 *  first initialized.  All {@link IEngine engine instances}
 *  will have access to the specification via the servlet.
 * /*from   w  w  w.  ja va2s  .c  o m*/
 *  @see #getApplicationSpecification()
 *  @see #constructApplicationSpecification()
 *  @see #createResourceResolver()
 *
 **/

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

    _resolver = createResourceResolver();

    _specification = constructApplicationSpecification();

    _attributeName = "org.apache.tapestry.engine:" + config.getServletName();
}

From source file:org.codice.proxy.http.HttpProxyCamelHttpTransportServlet.java

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

    String ignore = config.getInitParameter("ignoreDuplicateServletName");
    Boolean bool = ObjectConverter.toBoolean(ignore);
    if (bool != null) {
        ignoreDuplicateServletName = bool;
    } else {/*from   ww  w . java 2  s. c  o  m*/
        // always log so people can see it easier
        String msg = "Invalid parameter value for init-parameter ignoreDuplicateServletName with value: "
                + ignore;
        LOG.error(msg);
        throw new ServletException(msg);
    }

    String name = config.getServletName();
    String contextPath = config.getServletContext().getContextPath();

    if (httpRegistry == null) {
        httpRegistry = DefaultHttpRegistry.getHttpRegistry(name);
        CamelServlet existing = httpRegistry.getCamelServlet(name);
        if (existing != null) {
            String msg = "Duplicate ServetName detected: " + name + ". Existing: " + existing + " This: "
                    + this.toString() + ". Its advised to use unique ServletName per Camel application.";
            // always log so people can see it easier
            if (isIgnoreDuplicateServletName()) {
                LOG.warn(msg);
            } else {
                LOG.error(msg);
                throw new ServletException(msg);
            }
        }
        httpRegistry.register(this);
    }

    LOG.info("Initialized CamelHttpTransportServlet[name={}, contextPath={}]", getServletName(), contextPath);
}

From source file:org.jahia.services.atmosphere.AtmosphereServlet.java

@Override
public void init(final ServletConfig sc) throws ServletException {
    ServletConfig scFacade;/*from  ww w . j  av  a2  s  .  c  om*/

    String asyncSupport = SettingsBean.getInstance().getAtmosphereAsyncSupport();
    // override asyncSupport only if explicitly set via jahia.properties or not set at all
    if (StringUtils.isNotEmpty(asyncSupport) || sc.getInitParameter(PROPERTY_COMET_SUPPORT) == null) {
        final String implName = StringUtils.defaultIfBlank(asyncSupport, DEFAULT_ASYNC_SUPPORT);
        scFacade = new ServletConfig() {
            @Override
            public String getInitParameter(String name) {
                return PROPERTY_COMET_SUPPORT.equals(name) ? implName : sc.getInitParameter(name);
            }

            @Override
            public Enumeration<String> getInitParameterNames() {
                ArrayList<String> names = Lists.newArrayList(PROPERTY_COMET_SUPPORT);
                CollectionUtils.addAll(names, sc.getInitParameterNames());
                return Collections.enumeration(names);
            }

            @Override
            public ServletContext getServletContext() {
                return sc.getServletContext();
            }

            @Override
            public String getServletName() {
                return sc.getServletName();
            }
        };
    } else {
        scFacade = sc;
    }

    super.init(scFacade);
}

From source file:org.kuali.coeus.sys.framework.controller.ConditionalInitDispatcherServlet.java

private String getServletName(ServletConfig config) {
    return (config != null ? config.getServletName() : null);
}

From source file:org.kuali.rice.ksb.messaging.servlet.KSBDispatcherServlet.java

/**
 * 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.
 *///from  w  ww.jav  a  2 s  .  c o  m
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();
        }
    };
}

From source file:org.mobicents.servlet.sip.restcomm.callmanager.gateway.SipGatewayManager.java

@Override
public void init(ServletConfig config) throws ServletException {
    logger.info("initializing ServletConfig:" + config + " ServletName:" + config.getServletName()
            + " InitParameterNames:" + config.getInitParameterNames());
    this.config = config;
    final ServletContext context = config.getServletContext();
    final ServiceLocator services = ServiceLocator.getInstance();
    //      daos = services.get(DaoManager.class);
    //                logger.info("getGatewaysDao:"+daos.getGatewaysDao());
    //      gateways = daos.getGatewaysDao().getGateways();
    clock = (TimerService) config.getServletContext().getAttribute(TIMER_SERVICE);
    sipFactory = (SipFactory) context.getAttribute(SIP_FACTORY);
    final TimerManager timers = services.get(TimerManager.class);
    try {/*from www  .  j ava  2  s .c  om*/
        final SipGatewayManagerTimerListener listener = new SipGatewayManagerTimerListener();
        if (!timers.isRegistered("REGISTER")) {
            timers.register("REGISTER", listener);
        }
    } catch (final TooManyListenersException ignored) {
    }
}

From source file:org.openmrs.web.dwr.OpenmrsDWRServlet.java

/**
 * Overriding the init(ServletConfig) method to save the dwr servlet to the ModuleWebUtil class
 *///from w  w w .j  ava2s.c om
public void init(ServletConfig config) throws ServletException {
    Thread.currentThread().setContextClassLoader(OpenmrsClassLoader.getInstance());

    DwrServletConfig conf = new DwrServletConfig(config.getServletName(), config.getServletContext());
    conf.setInitParameter("debug", "false");
    conf.setInitParameter("config-modules", "/WEB-INF/dwr-modules.xml");

    super.init(conf);
}

From source file:org.opensubsystems.core.util.servlet.WebUtils.java

/**
 * Create debug string containing all parameter names and their values from
 * the config.//w w  w. j  a  v a  2 s.c om
 *
 * @param  scConfig - config to print out
 * @return String - debug string containing all parameter names and their
 *                  values from the config
 */
public static String debug(ServletConfig scConfig) {
    Enumeration enumNames;
    String strParam;
    StringBuilder sbfReturn = new StringBuilder();

    sbfReturn.append("ServletConfig=[ServletName=");
    sbfReturn.append(scConfig.getServletName());
    sbfReturn.append(";");
    for (enumNames = scConfig.getInitParameterNames(); enumNames.hasMoreElements();) {
        strParam = (String) enumNames.nextElement();
        sbfReturn.append("Param=");
        sbfReturn.append(strParam);
        sbfReturn.append(" value=");
        sbfReturn.append(scConfig.getInitParameter(strParam));
        if (enumNames.hasMoreElements()) {
            sbfReturn.append(";");
        }
    }
    sbfReturn.append("]");

    return sbfReturn.toString();
}

From source file:org.seasar.cadhelin.ControllerServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    LOG.info("start cadhelin servlert" + config.getServletName());
    String s = config.getInitParameter("encoding");
    if (s != null) {
        encoding = s;//from w w  w.  j  a  v a2 s.c  o m
    }
    s = config.getInitParameter("viewUrlPattern");
    if (s != null) {
        viewUrlPattern = s;
    }
    container = SingletonS2ContainerFactory.getContainer();
    Object[] objects = container.findAllComponents(Plugin.class);
    if (objects != null && 0 < objects.length) {
        plugins = new Plugin[objects.length];
        System.arraycopy(objects, 0, plugins, 0, plugins.length);
    }
    for (Plugin plugin : plugins) {
        plugin.start(config);
    }
    actionMetadataFactory = new ActionMetadataFactoryImpl(container);
    config.getServletContext().setAttribute(CONTROLLER_METADATA_NAME, actionMetadataFactory);
    if (container.hasComponentDef(ExceptionHandler.class)) {
        exceptionHandlerMetadata = new ExceptionHandlerMetadata(
                container.getComponentDef(ExceptionHandler.class));
    }
    Object[] f = container.findComponents(ActionFilter.class);
    this.filters = new ActionFilter[f.length];
    System.arraycopy(f, 0, filters, 0, filters.length);

}