Example usage for javax.servlet ServletContext setAttribute

List of usage examples for javax.servlet ServletContext setAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletContext setAttribute.

Prototype

public void setAttribute(String name, Object object);

Source Link

Document

Binds an object to a given attribute name in this ServletContext.

Usage

From source file:org.apache.juddi.v3.client.config.WebHelperTest.java

@Test(expected = ConfigurationException.class)
public void testGetUDDIClientNoConfig() throws Exception {
    System.out.println("testGetUDDIClientNoConfig");

    String random = UUID.randomUUID().toString();
    ServletContext req = createNiceMock(ServletContext.class);

    req.setAttribute(JUDDI_CLIENT_NAME, null);
    expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 1);
    req.setAttribute(UDDI_CLIENT_CONFIG_FILE, random);
    expect(req.getInitParameter(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(random).times(0, 1);

    //using default config
    //     expect(req.getInitParameter(WebHelper.UDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //   expect(req.getInitParameter(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(null).times(0, 2);
    // expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_TRANSPORT)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //using default config
    // expect(req.getAttribute(WebHelper.UDDI_CLIENT_NAME)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.UDDI_CLIENT_CONFIG_FILE)).andReturn(null).times(0, 2);
    //expect(req.getAttribute(WebHelper.JUDDI_CLIENT_TRANSPORT)).andReturn(null).times(0, 2);

    replay(req);/*from w ww  . j a v  a  2 s  .c  om*/

    UDDIClient result = WebHelper.getUDDIClient(req);
    Assert.assertNotNull(result);
}

From source file:com.easyjf.container.impl.SpringContainer.java

/**
 * servletSpring WebApplicationContext//from  w  ww.  ja  v  a 2s  .  c om
 * @param servletContext
 */
public void registerWebContext(ServletContext servletContext) {
    servletContext.setAttribute("org.springframework.web.context.WebApplicationContext.ROOT",
            this.getFactory());
}

From source file:com.mycompany.hcsparta_web.StartListener.java

@Override
public void contextInitialized(ServletContextEvent ev) {
    log.info("webov aplikace inicializovna");
    ServletContext servletContext = ev.getServletContext();
    ApplicationContext springContext = new AnnotationConfigApplicationContext(SpringConfig.class);

    servletContext.setAttribute("playerManager",
            springContext.getBean("playerManager", PlayerManagerImpl.class));
    PlayerManagerImpl pl = (PlayerManagerImpl) servletContext.getAttribute("playerManager");
    pl.initFunction();/*from w  w w.jav a  2 s  .co  m*/

    servletContext.setAttribute("matchManager", springContext.getBean("matchManager", MatchManagerImpl.class));

    log.info("vytvoeny manaery");

}

From source file:com.openkm.servlet.admin.LogCatServlet.java

/**
 * Purge log/* w ww  . j  a  va 2s. co m*/
 */
@SuppressWarnings("unchecked")
private void purge(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("purge({}, {})", request, response);
    for (File lf : (Collection<File>) FileUtils.listFiles(logFolder, null, false)) {
        if (lf.getName().matches(".+[0-9][0-9]-[0-9][0-9]-[0-9][0-9].*")) {
            lf.delete();
        }
    }

    ServletContext sc = getServletContext();
    sc.setAttribute("files", FileUtils.listFiles(logFolder, null, false));
    sc.getRequestDispatcher("/admin/logcat.jsp").forward(request, response);

    // Activity log
    UserActivity.log(request.getRemoteUser(), "ADMIN_LOGCAT_PURGE", null, null, null);

    log.debug("view: void");
}

From source file:org.springframework.test.context.support.AbstractGenericWebContextLoader.java

/**
 * TODO [SPR-9864] Document configureWebResources().
 *///from w w w.j  ava2s.  c o m
protected void configureWebResources(GenericWebApplicationContext context,
        WebMergedContextConfiguration webMergedConfig) {

    String resourceBasePath = webMergedConfig.getResourceBasePath();
    ResourceLoader resourceLoader = resourceBasePath.startsWith(ResourceLoader.CLASSPATH_URL_PREFIX)
            ? new DefaultResourceLoader()
            : new FileSystemResourceLoader();

    ServletContext servletContext = new MockServletContext(resourceBasePath, resourceLoader);
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
    context.setServletContext(servletContext);
}

From source file:org.jasig.cas.web.report.StatisticsController.java

@Override
public void setServletContext(final ServletContext servletContext) {
    servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY, this.metricsRegistry);
    servletContext.setAttribute(MetricsServlet.SHOW_SAMPLES, Boolean.TRUE);
    servletContext.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, this.healthCheckRegistry);
}

From source file:com.jsquant.listener.JsquantContextListener.java

public void contextInitialized(ServletContextEvent sce) {
    contextDestroyed(sce);//ww w  . j a  v  a  2 s  . c o  m
    ServletContext context = sce.getServletContext();

    String fileCachePath = getFileCachePath(context);
    context.setAttribute(ATTR_FILE_CACHE, new FileCache(fileCachePath));

    HttpParams params = new BasicHttpParams();
    //params.setParameter("http.useragent", "Mozilla/5.0");
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "UTF-8");
    final SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
    final HttpClient httpClient = new DefaultHttpClient(manager, params);
    //HttpHost proxy = new HttpHost("someproxy.com", 80);
    //httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    context.setAttribute(ATTR_HTTP_CLIENT, httpClient);
}

From source file:com.corejsf.UploadFilter.java

public void init(FilterConfig config) throws ServletException {
    repositoryPath = ServerConfigurationService.getString("samigo.answerUploadRepositoryPath",
            "${sakai.home}/samigo/answerUploadRepositoryPath/");

    try {/*from w w w.jav a2 s.c  om*/
        String paramValue = ServerConfigurationService.getString("samigo.sizeThreshold", "1024");
        if (paramValue != null)
            sizeThreshold = Integer.parseInt(paramValue);

        paramValue = ServerConfigurationService.getString("samigo.sizeMax", "40960");
        if (paramValue != null)
            sizeMax = Long.parseLong(paramValue);

        paramValue = ServerConfigurationService.getString("samigo.saveMediaToDb", "true");
        if (paramValue != null)
            saveMediaToDb = paramValue;

        //System.out.println("**** repositoryPath="+repositoryPath);
        //System.out.println("**** sabeMediaToDb="+saveMediaToDb);
        //System.out.println("**** sizeThreshold="+sizeThreshold);
        //System.out.println("**** sizeMax="+sizeMax);
    } catch (NumberFormatException ex) {
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
    ServletContext context = config.getServletContext();
    context.setAttribute("FILEUPLOAD_REPOSITORY_PATH", repositoryPath);
    context.setAttribute("FILEUPLOAD_SIZE_THRESHOLD", Integer.valueOf(sizeThreshold));
    context.setAttribute("FILEUPLOAD_SIZE_MAX", Long.valueOf(sizeMax));
    context.setAttribute("FILEUPLOAD_SAVE_MEDIA_TO_DB", saveMediaToDb);
}

From source file:org.mobicents.servlet.sip.example.InitializationListener.java

public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();

    File tempWriteDir = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
    servletContext.setAttribute("audioFilePath",
            FILE_PROTOCOL + tempWriteDir.getAbsolutePath() + File.separatorChar);
    // map acting as a registrar
    servletContext.setAttribute("registeredUsersMap", new HashMap<String, String>());
}

From source file:org.red5.server.scheduling.ApplicationSchedulingService.java

/**
 * Sets the scheduler factory in the servlet context.
 * //  w w  w  .  j av a 2s . c o  m
 * @param servletContext
 */
public void setServletAttribute(ServletContext servletContext) {
    log.debug("Storing the scheduler factory in the servlet context");
    servletContext.setAttribute(QUARTZ_FACTORY_KEY, factory);
}