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.intermine.web.logic.session.SessionMethods.java

/**
 * Sets the blocking error codes into the servlet context.
 *
 * @param servletContext the ServletContext
 * @param errorKey the Map of error codes and replacement value
 *//*from  w  w  w. ja v  a2  s .c om*/
public static void setErrorOnInitialiser(ServletContext servletContext, Map<String, String> errorKey) {
    servletContext.setAttribute(Constants.INITIALISER_KEY_ERROR, errorKey);
}

From source file:org.intermine.web.logic.session.SessionMethods.java

/**
 * Sets the origins of the web properties on the servlet context.
 *
 * @param servletContext The context of the web application.
 * @param origins A map tracing the origin of each property.
 *//* ww  w.  ja va  2 s .  c  o m*/
public static void setPropertiesOrigins(ServletContext servletContext, Map<String, List<String>> origins) {
    servletContext.setAttribute(Constants.PROPERTIES_ORIGINS, origins);
}

From source file:com.concursive.connect.web.controller.hooks.InitHook.java

/**
 * Description of the Method//from  w w  w.j a  v  a2s.c  o  m
 *
 * @param config Description of the Parameter
 */
public void beginInit(ServletConfig config) {
    LOG.info("Initializing framework...");
    ServletContext context = config.getServletContext();
    ApplicationPrefs prefs = new ApplicationPrefs(context);
    context.setAttribute(Constants.APPLICATION_PREFS, prefs);
}

From source file:org.firstopen.custom.event.agent.Initializer.java

public void contextInitialized(ServletContextEvent event) {
    ServletContext servletContext = event.getServletContext();
    log.debug("Initializing Singularity...");

    try {/*from ww w.  j ava 2s .c o m*/
        servletContext.setAttribute(Constants.EVENT_MONITOR_KEY, new EventMonitorBean());

        log.debug("Initialization complete...");

    } catch (InfrastructureException e) {

        log.error("unable to initialize context", e);
    }

}

From source file:org.jbpm.bpel.tutorial.invoice.ComputePricePT_Impl.java

public void initiatePriceCalculation(CustomerInfo customerInfo, PurchaseOrder purchaseOrder)
        throws RemoteException {
    ServletContext servletContext = endpointContext.getServletContext();
    servletContext.setAttribute(ORDER_ID_ATTR, new Integer(purchaseOrder.getOrderId()));
    // In our system the part number is the unit price!
    servletContext.setAttribute(LINE_PRICE_ATTR,
            new Float(purchaseOrder.getQuantity() * purchaseOrder.getPartNumber()));
}

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

/**
 * Test of getUDDIClient method, of class WebHelper.
 *///w  w  w  .j  a  v a2s  .  c o m
@Test
public void testGetUDDIClient() throws Exception {
    System.out.println("getUDDIClient");

    ServletContext req = createNiceMock(ServletContext.class);
    req.setAttribute(JUDDI_CLIENT_NAME, null);
    expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).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);

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

From source file:com.threewks.thundr.jpa.JpaModule.java

protected final PersistenceManagerRegistry initializePersistenceManagerRegistry(
        UpdatableInjectionContext injectionContext) {
    PersistenceManagerRegistry registry = new PersistenceManagerRegistryImpl();
    injectionContext.inject(registry).as(PersistenceManagerRegistry.class);

    for (Map.Entry<String, String> persistenceManagerAndUnit : getPersistenceUnitNames(injectionContext)
            .entrySet()) {//from w  w w. j  a  va 2s. c o m
        String persistenceManagerName = persistenceManagerAndUnit.getKey();
        String persistenceUnitName = persistenceManagerAndUnit.getValue();
        PersistenceManager persistenceManager = new PersistenceManagerImpl(persistenceUnitName);
        registry.register(persistenceManagerName, persistenceManager);
        injectionContext.inject(persistenceManager).named(persistenceManagerName).as(PersistenceManager.class);
        Logger.info("Registered persistence manager %s against persistence unit %s", persistenceManagerName,
                persistenceUnitName);
    }

    // Put reference into servlet context to provide context listener with access to call
    // PersistenceManagerRegister#clear() on shutdown.
    ServletContext context = injectionContext.get(ServletContext.class);
    context.setAttribute(PersistenceManagerRegistry, registry);

    return registry;
}

From source file:com.ikon.servlet.admin.CheckTextExtractionServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("doGet({}, {})", request, response);
    request.setCharacterEncoding("UTF-8");
    updateSessionManager(request);//  www  . j  ava2s . c  o m

    ServletContext sc = getServletContext();
    sc.setAttribute("repoPath", "/" + Repository.ROOT);
    sc.setAttribute("docUuid", null);
    sc.setAttribute("text", null);
    sc.setAttribute("time", null);
    sc.setAttribute("mimeType", null);
    sc.setAttribute("extractor", null);
    sc.getRequestDispatcher("/admin/check_text_extraction.jsp").forward(request, response);
}

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

@Test
public void testGetUDDIClientRandom() throws Exception {
    System.out.println("testGetUDDIClientRandom");

    String random = UUID.randomUUID().toString();
    ServletContext req = createNiceMock(ServletContext.class);
    req.setAttribute(UDDI_CLIENT_NAME, random);
    req.setAttribute(JUDDI_CLIENT_NAME, null);
    expect(req.getInitParameter(WebHelper.JUDDI_CLIENT_NAME)).andReturn(null).times(0, 1);
    expect(req.getInitParameter(WebHelper.UDDI_CLIENT_NAME)).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 ww w . j av  a2 s . co  m

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

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

/**
 * List logs/*from w  w  w  . j  av  a  2s.c  om*/
 */
private void list(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    log.debug("list({}, {})", request, response);
    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_LIST", null, null, logFolder.getPath());

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