Example usage for javax.servlet.http HttpSession getServletContext

List of usage examples for javax.servlet.http HttpSession getServletContext

Introduction

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

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns the ServletContext to which this session belongs.

Usage

From source file:com.mobileman.projecth.web.controller.InitController.java

private static void initApplication(HttpServletRequest request) {
    // workaround for OpenSessionInView spring class
    webApplicationContext = RequestContextUtils.getWebApplicationContext(request);
    OpenSessionFilter.setWebApplicationContext(webApplicationContext);
    //load menus// w  w w.  j  ava 2  s. c  om
    HttpSession session = request.getSession();
    session.getServletContext().setAttribute("menu", new Menu(request));
    //session timeout seconds
    session.getServletContext().setAttribute("session_timeout_seconds", session.getMaxInactiveInterval());
}

From source file:com.orchestra.portale.utils.InsertUtils.java

public static String delimg(HttpServletRequest request, String id, String nameimg) {
    String esito = "";
    HttpSession session = request.getSession();
    ServletContext sc = session.getServletContext();
    File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "poi" + File.separator + "img"
            + File.separator + id);

    File img = new File(dir.getAbsolutePath() + File.separator + nameimg);
    if (img.delete())
        esito = "OK";
    else//from   w  w  w  . jav a  2 s.  co  m
        esito = "ERRORE";

    return esito;
}

From source file:org.oscarehr.admin.traceability.GenerateTraceabilityUtil.java

public static Map<String, String> buildTraceMap(HttpServletRequest request) throws Exception {
    Map<String, String> traceMap = new HashMap<String, String>();
    HttpSession session = request.getSession();
    ServletContext servletContext = session.getServletContext();
    String realPath = servletContext.getRealPath("/");
    Iterator<File> iterator = FileUtils.iterateFiles(new File(realPath), null, true);
    while (iterator.hasNext()) {
        File f_ = iterator.next();
        FileInputStream fi_ = new FileInputStream(f_);
        String path = f_.getAbsolutePath();
        path = path.replace(realPath, "");
        traceMap.put(path, DigestUtils.sha256Hex(fi_));
        fi_.close();//from  w  w w  . j ava  2  s  . c  o  m
    }

    return traceMap;
}

From source file:com.acc.filter.FilterSpringUtil.java

/**
 * Returns the Spring bean with name <code>beanName</code> and of type <code>beanClass</code>. If no bean could be
 * resolved for the specified name, the bean is looked up using type.
 * /*  ww  w  .  j a v  a2  s.c o m*/
 * @param <T>
 *           type of the bean
 * @param httpRequest
 *           the http request
 * @param beanName
 *           name of the bean or <code>null</code> if it should be automatically resolved using type
 * @param beanClass
 *           expected type of the bean
 * @return the bean matching the given arguments or <code>null</code> if no bean could be resolved
 * 
 */
public static <T> T getSpringBean(final HttpServletRequest httpRequest, final String beanName,
        final Class<T> beanClass) {
    final HttpSession session = httpRequest.getSession();
    final ServletContext servletContext = session.getServletContext();
    return getSpringBean(servletContext, beanName, beanClass);
}

From source file:org.jdal.vaadin.VaadinUtils.java

public static ServletContext getServletContext() {
    HttpSession session = getSession();

    return session != null ? session.getServletContext() : null;
}

From source file:org.openmrs.web.user.CurrentUsers.java

/**
 * Get the current list of map of users stored in the session
 * /*from   w  ww .  java  2s .  co  m*/
 * @param httpSession the current session
 * @return map of users logged in
 */
@SuppressWarnings("unchecked")
private static Map<String, String> getCurrentUsers(HttpSession httpSession) {
    Map<String, String> currentUsers = (Map<String, String>) httpSession.getServletContext()
            .getAttribute(WebConstants.CURRENT_USERS);
    if (currentUsers == null) {
        currentUsers = init(httpSession.getServletContext());
    }
    return currentUsers;
}

From source file:org.polymap.core.workbench.dnd.DndUploadServlet.java

public static File getUploadTempDir(final HttpSession session) {
    ServletContext context = session.getServletContext();
    StringBuffer path = new StringBuffer();
    File tempDir = (File) context.getAttribute(CONTEXT_TEMP_DIR);
    File result = new File(tempDir.getAbsolutePath(), session.getId());
    if (!result.exists()) {
        result.mkdir();//w w w.  jav  a 2  s . co  m
    }
    return result;
}

From source file:org.kitodo.production.plugin.importer.massimport.UghUtils.java

/**
 * The function open() opens a file. In a user session context, the file is
 * taken from the web applications deployment directory
 * (/WEB-INF/classes), if not, it is taken from the CONFIG_DIR specified in
 * the CONFIG_FILE.//  ww  w.  j  a v a  2 s .c o  m
 * <p/>
 * TODO: Community needs to decide: Is this behaviour really what we want?
 * Shouldnt it <em>always</em> be the configured directory?
 *
 * @param fileName
 *            File to open
 * @return a BufferedReader for reading the file
 * @throws FileNotFoundException
 *             if the file does not exist, is a directory rather than a
 *             regular file, or for some other reason cannot be opened for
 *             reading
 * @throws UnsupportedEncodingException
 *             If the named charset is not supported
 */
private static BufferedReader open(String fileName) throws IOException {
    String path = ConfigCore.getKitodoConfigDirectory();
    FacesContext context = FacesContext.getCurrentInstance();
    if (context != null) {
        HttpSession session = (HttpSession) context.getExternalContext().getSession(false);
        path = FilenameUtils.concat(session.getServletContext().getRealPath("/WEB-INF"), "classes");
    }
    String file = FilenameUtils.concat(path, fileName);
    return new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
}

From source file:org.eclipse.rwt.widgets.upload.servlet.FileUploadServlet.java

public static File getUploadTempDir(final HttpSession session) {
    ServletContext context = session.getServletContext();
    StringBuffer path = new StringBuffer();
    File tempDir = (File) context.getAttribute(CONTEXT_TEMP_DIR);
    path.append(tempDir.getAbsolutePath());
    path.append(File.separatorChar);
    path.append(session.getId());// w w w .ja v a 2s  .  c om
    File result = new File(path.toString());
    if (!result.exists()) {
        result.mkdir();
    }
    return result;
}

From source file:org.jenkinsci.plugins.ssegateway.Util.java

public static Map<String, String> getSessionInfo(HttpSession session) {
    Map<String, String> info = new HashMap<>();
    info.put("sessionid", session.getId());
    info.put("cookieName", session.getServletContext().getSessionCookieConfig().getName());
    return info;/*from   w ww  . ja  v  a2  s.  c  o m*/
}