Example usage for javax.servlet ServletConfig getServletContext

List of usage examples for javax.servlet ServletConfig getServletContext

Introduction

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

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:eionet.eunis.servlets.DownloadServlet.java

/**
 * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
 *//*from w w w  . j  av a2s  .  c  o  m*/
@Override
public void init(ServletConfig config) throws ServletException {

    super.init(config);
    appHome = config.getServletContext().getInitParameter(Constants.APP_HOME_INIT_PARAM);
}

From source file:org.projectforge.business.teamcal.servlet.CalendarAboServlet.java

@Override
public void init(final ServletConfig config) throws ServletException {
    super.init(config);
    springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(config.getServletContext());
    final AutowireCapableBeanFactory beanFactory = springContext.getAutowireCapableBeanFactory();
    beanFactory.autowireBean(this);
}

From source file:org.mot.core.MyOpenTraderCore.java

/**
 * The init method is the main starting point for both, the servlet (war) and the main method
 * in case it is executed from the command line...
 * //from   ww w. j a v a 2  s  .  c  o  m
 * @see Servlet#init(ServletConfig)
 */
public void init(ServletConfig config) throws ServletException {
    // TODO Auto-generated method stub

    logger.info("*** Initializing Interactive Broker CORE Servlet ...");
    String pathToConfigDir = config.getServletContext().getRealPath("/WEB-INF/conf");
    startWorkers(pathToConfigDir, null);

}

From source file:net.sourceforge.vulcan.web.ProjectFileServlet.java

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

    final WebApplicationContext wac = WebApplicationContextUtils
            .getRequiredWebApplicationContext(config.getServletContext());

    projectManager = (ProjectManager) wac.getBean(Keys.PROJECT_MANAGER);
    buildManager = (BuildManager) wac.getBean(Keys.BUILD_MANAGER);
}

From source file:org.iterx.miru.support.servlet.HttpDispatcherServlet.java

public void init(ServletConfig servletConfig) throws ServletException {

    try {//w  ww  .  j av  a2 s. c o m
        DispatcherApplicationContext applicationContext;
        ApplicationContext parentApplicationContext;
        HandlerChainFactory handlerChainFactory;
        ServletContext servletContext;
        String parameter;

        servletContext = servletConfig.getServletContext();

        parentApplicationContext = (ApplicationContext) servletContext
                .getAttribute((DispatcherApplicationContext.class).getName());
        applicationContext = ((parentApplicationContext != null)
                ? new ServletDispatcherApplicationContext(parentApplicationContext, servletContext)
                : new ServletDispatcherApplicationContext(servletContext));

        if ((parameter = servletConfig.getInitParameter(ServletDispatcherApplicationContext.BEANS)) != null
                && applicationContext instanceof Loadable) {
            URL url;

            if ((url = (servletContext.getResource(parameter))) != null)
                ((Loadable) applicationContext).load(new UriStreamResource(url.toURI()));
            else
                throw new IOException("Invalid stream [" + parameter + "]");
        }

        handlerChainFactory = applicationContext.getHandlerChainFactory();
        if ((parameter = servletConfig.getInitParameter(ServletDispatcherApplicationContext.CHAINS)) != null
                && handlerChainFactory instanceof Loadable) {
            URL url;

            if ((url = (servletContext.getResource(parameter))) != null)
                ((Loadable) handlerChainFactory).load(new UriStreamResource(url.toURI()));
            else
                throw new IOException("Invalid stream [" + parameter + "]");
        }

        if (dispatcher == null
                && (dispatcher = (Dispatcher<HttpServletRequestContext, HttpServletResponseContext>) applicationContext
                        .getBeanOfType(Dispatcher.class)) == null)
            dispatcher = new Dispatcher<HttpServletRequestContext, HttpServletResponseContext>();

        dispatcher.setHandlerChainMap(handlerChainFactory.getHandlerChains());
        processingContextFactory = applicationContext.getProcessingContextFactory();
    } catch (Exception e) {
        LOGGER.error("Initialisation failed.", e);
        throw new ServletException("Initialisation failed.", e);
    }
}

From source file:servlets.JoinGroupHandler.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {//from  w w  w  . j  a va 2 s.c  om
        dataSource = (DataSource) ((Context) new InitialContext().lookup("java:/comp/env"))
                .lookup("jdbc/bibsonomy");
        projectHome = config.getServletContext().getInitParameter("projectHome");
        projectName = config.getServletContext().getInitParameter("projectName");
    } catch (NamingException ex) {
        throw new ServletException("Cannot retrieve java:/comp/env/bibsonomy", ex);
    }
}

From source file:org.wso2.carbon.governance.generic.ui.clients.ManageGenericArtifactServiceClient.java

public ManageGenericArtifactServiceClient(ServletConfig config, HttpSession session) throws RegistryException {
    this.session = session;
    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    epr = backendServerURL + "ManageGenericArtifactService";

    try {// ww w .j  a  va2s  .  c o m
        stub = new ManageGenericArtifactServiceStub(configContext, epr);

        ServiceClient client = stub._getServiceClient();
        Options option = client.getOptions();
        option.setManageSession(true);
        option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

    } catch (AxisFault axisFault) {
        String msg = "Failed to initiate ManageGenericArtifactServiceClient. " + axisFault.getMessage();
        log.error(msg, axisFault);
        throw new RegistryException(msg, axisFault);
    }
}

From source file:com.productone.spring.ServerOsgiBundleXmlWebApplicationContext.java

/**
 * {@inheritDoc}//from   w w  w  .j a  v a  2s  . co  m
 */
public void setServletConfig(ServletConfig servletConfig) {
    this.servletConfig = servletConfig;
    if (servletConfig != null) {
        if (getServletContext() == null) {
            setServletContext(servletConfig.getServletContext());
        }
        if (getNamespace() == null) {
            setNamespace(servletConfig.getServletName() + DEFAULT_NAMESPACE_SUFFIX);
        }
    }
}

From source file:com.google.zxing.web.DecodeServlet.java

@Override
public void init(ServletConfig servletConfig) throws ServletException {
    Logger logger = Logger.getLogger("com.google.zxing");
    ServletContext context = servletConfig.getServletContext();
    logger.addHandler(new ServletContextLogHandler(context));
    File repository = (File) context.getAttribute("javax.servlet.context.tempdir");
    FileCleaningTracker fileCleaningTracker = FileCleanerCleanup.getFileCleaningTracker(context);
    diskFileItemFactory = new DiskFileItemFactory(1 << 16, repository);
    diskFileItemFactory.setFileCleaningTracker(fileCleaningTracker);

    URL blockURL = context.getClassLoader().getResource("/private/uri-block-substrings.txt");
    if (blockURL == null) {
        blockedURLSubstrings = Collections.emptyList();
    } else {/*from w w w . j  a v  a2  s .  co  m*/
        try {
            blockedURLSubstrings = Resources.readLines(blockURL, StandardCharsets.UTF_8);
        } catch (IOException ioe) {
            throw new ServletException(ioe);
        }
        log.info("Blocking URIs containing: " + blockedURLSubstrings);
    }
}

From source file:org.seasar.mayaa.impl.AutoPageBuilder.java

/**
 * ??/*from   w w w .  j a  v a2 s. co m*/
 * Engine????????
 * ???autoBuild?false?????????
 *
 * contextPath?"/mayaa"???"/"??"/"???
 *
 * @param servletConfig ServletConfig
 * @param contextPath 
 */
public void init(ServletConfig servletConfig, String contextPath) {
    Engine engine = ProviderUtil.getEngine();
    boolean autoBuild = ObjectUtil.booleanValue(engine.getParameter(OPTION_AUTO_BUILD), false);
    if (autoBuild && (ParameterAware.IS_SECURE_WEB == false)) {
        _servletContext = servletConfig.getServletContext();
        _contextPath = prepareContextPath(contextPath, engine);
        _repeat = ObjectUtil.booleanValue(engine.getParameter(OPTION_AUTO_BUILD_REPRAT), REPEAT_DEFAULT);
        _wait = ObjectUtil.numberValue(engine.getParameter(OPTION_AUTO_BUILD_WAIT), new Integer(WAIT_DEFAULT))
                .intValue() * 1000;
        _renderMate = ObjectUtil.booleanValue(engine.getParameter(OPTION_AUTO_BUILD_RENDER_MATE),
                RENDER_MATE_DEFAULT);

        String filters = engine.getParameter(OPTION_AUTO_BUILD_FILE_FILTERS);
        if (filters != null) {
            _fileFilters = filters.split(";");
        } else {
            _fileFilters = new String[] { ".html" };
        }
        _thread = new Thread(this) {
            {
                setDaemon(true);
                setName("mayaa.AutoPageBuilder");
                setPriority(Thread.MIN_PRIORITY);
                start();
            }
        };
        LOG.info("mayaa.AutoPageBuilder start");
    }
}