Example usage for javax.servlet ServletContext getAttribute

List of usage examples for javax.servlet ServletContext getAttribute

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

Usage

From source file:org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.java

public DefaultGrailsApplicationAttributes(ServletContext context) {
    this.context = context;
    if (context != null) {
        appContext = (ApplicationContext) context.getAttribute(APPLICATION_CONTEXT);
    }//  w  w  w  . j  ava2 s  .co  m
    initBeans();
}

From source file:com.skilrock.lms.web.loginMgmt.RolesInterceptor.java

public boolean isSessionValid(HttpSession session) {
    HttpSession sessionNew = null;//from  w  w w  . j a  v  a2 s  .  co m
    ServletContext sc = ServletActionContext.getServletContext();
    Map currentUserSessionMap = (Map) sc.getAttribute("LOGGED_IN_USERS");
    UserInfoBean userBean = (UserInfoBean) session.getAttribute("USER_INFO");
    if (userBean == null) {

        return false;
    }
    if (currentUserSessionMap != null && userBean != null) {
        sessionNew = (HttpSession) currentUserSessionMap.get(userBean.getUserName());
    }
    // logger.debug("In Else If New is --"+sessionNew+" Session Current
    // --"+session);
    // logger.debug("The User in Map are"+currentUserSessionMap );
    if (sessionNew != null) {
        if (!sessionNew.equals(session)) {
            session.removeAttribute("USER_INFO");
            session.invalidate();
            session = null;
            return false;
        }
    }
    return true;

}

From source file:cn.vlabs.umt.ui.actions.ManageUserAction.java

public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws IOException {
    String query = request.getParameter("q");
    if (query != null) {
        ServletContext context = getServlet().getServletContext();
        BeanFactory factory = (BeanFactory) context.getAttribute(Attributes.APPLICATION_CONTEXT_KEY);
        UserService us = (UserService) factory.getBean("UserService");
        Collection<User> users = us.search(query, 0, 10);

        //JSON/*from w  ww  . j  a  v  a2s.  c om*/
        StringBuffer json = new StringBuffer();
        boolean first = true;
        json.append("[");
        if (users != null) {
            for (User user : users) {
                if (!first) {
                    json.append(",");
                } else {
                    first = false;
                }
                json.append("{u:'" + user.getUmtId() + "'");
                json.append(", t:'" + user.getTrueName() + "'}");
            }
        }
        json.append("]");

        //?SON
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/json");
        PrintWriter writer = response.getWriter();
        writer.print(json.toString());
        writer.flush();
        writer.close();
    }
    return null;
}

From source file:eu.celarcloud.jcatascopia.api.subscriptions.SubscriptionsServer.java

/**
 * Returns the given subscription's metadata
 * /*from   w  w w  . j  a  v  a  2  s  .  c  o  m*/
 * @param req
 * @param response
 * @param context
 * @param subID The subscription's id
 * @return a json containing all the subscription's metadata
 */
@GET
@Path("/{subid}")
@Produces(MediaType.APPLICATION_JSON)
public Response getSubscriptionMetadata(@Context HttpServletRequest req, @Context HttpServletResponse response,
        @Context ServletContext context, @PathParam("subid") String subID) {
    IDBInterface dbInterface = (IDBInterface) context.getAttribute("dbInterface");
    SubscriptionObj sub = dbInterface.getSubMeta(subID);

    if (context.getAttribute("debug_mode") != null
            && context.getAttribute("debug_mode").toString().equals("true")) {
        System.out.println("Request to retieve sub metadata: " + sub.getSubID());
        System.out.println(sub.toJSON());
    }

    return Response.status(sub != null ? Response.Status.OK : Response.Status.NOT_FOUND)
            .entity(sub != null ? sub.toJSON() : "Subscripiton with id " + subID + " not found!").build();
}

From source file:de.ingrid.iplug.web.DatatypeContextListener.java

public void contextInitialized(ServletContextEvent servletcontextevent) {
    ServletContext servletContext = servletcontextevent.getServletContext();
    String realPathToDatatypes = servletContext.getRealPath(DATA_TYPES);
    IDataTypeProvider dataTypeProvider = new DataTypeProvider(new File(realPathToDatatypes),
            new DataTypeEditor());
    BeanFactory beanFactory = (BeanFactory) servletContext.getAttribute("beanFactory");
    try {/*  w  w  w.j  ava2s .c  om*/
        beanFactory.addBean("dataTypeProvider", dataTypeProvider);
    } catch (IOException e) {
        LOG.error("can not add plugdescription", e);
    }
}

From source file:org.apache.pluto.driver.PortalStartupListener.java

/**
 * Destroyes the portal admin config and removes it from servlet context.
 *
 * @param servletContext the servlet context.
 *//*  ww w .  j av a  2 s . c  o m*/
private void destroyAdminConfiguration(ServletContext servletContext) {
    AdminConfiguration adminConfig = (AdminConfiguration) servletContext.getAttribute(ADMIN_CONFIG_KEY);
    if (adminConfig != null) {
        try {
            adminConfig.destroy();
            if (LOG.isInfoEnabled()) {
                LOG.info("Pluto Portal Admin Config destroyed.");
            }
        } catch (DriverConfigurationException ex) {
            LOG.error("Unable to destroy portal admin config: " + ex.getMessage(), ex);
        } finally {
            servletContext.removeAttribute(ADMIN_CONFIG_KEY);
        }
    }
}

From source file:org.grails.web.servlet.DefaultGrailsApplicationAttributes.java

public DefaultGrailsApplicationAttributes(ServletContext context) {
    this.context = context;
    if (context != null) {
        appContext = (ApplicationContext) context.getAttribute(APPLICATION_CONTEXT);
        if (appContext == null) {
            appContext = Holders.findApplicationContext();
        }/*  ww  w  .j ava2  s .com*/
    }
}

From source file:org.apache.pluto.driver.PortalStartupListener.java

/**
 * Destroyes the portal driver config and removes it from servlet context.
 *
 * @param servletContext the servlet context.
 *///www  . j  av a 2  s. c om
private void destroyDriverConfiguration(ServletContext servletContext) {
    DriverConfiguration driverConfig = (DriverConfiguration) servletContext.getAttribute(DRIVER_CONFIG_KEY);
    if (driverConfig != null) {
        try {
            driverConfig.destroy();
            if (LOG.isInfoEnabled()) {
                LOG.info("Pluto Portal Driver Config destroyed.");
            }
        } catch (DriverConfigurationException ex) {
            LOG.error("Unable to destroy portal driver config: " + ex.getMessage(), ex);
        } finally {
            servletContext.removeAttribute(DRIVER_CONFIG_KEY);
        }
    }
}

From source file:org.apache.struts.chain.contexts.ServletActionContext.java

public MessageResources getMessageResources(String key) {
    // Identify the current module
    ServletContext context = getActionServlet().getServletContext();

    // Return the requested message resources instance
    return (MessageResources) context.getAttribute(key + getModuleConfig().getPrefix());
}

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();//w w  w. j  av a  2s  . c  om

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

    log.info("vytvoeny manaery");

}