Example usage for javax.servlet.http HttpServletRequest getSession

List of usage examples for javax.servlet.http HttpServletRequest getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getSession.

Prototype

public HttpSession getSession();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:com.esd.ps.WorkerController.java

/**
 * ?/* w  w  w . java  2  s .  co m*/
 * 
 * @param request
 * @return
 */
public static String url(HttpServletRequest request) {
    String url = request.getSession().getServletContext().getRealPath(Constants.SLASH);
    url = url + Constants.WORKERTEMP;
    File f = new File(url);
    if (f.exists()) {
        return url;
    }
    f.mkdir();
    return url;
}

From source file:nl.knmi.adaguc.services.oauth2.OAuth2Handler.java

/**
 * Sets session parameters for the impactportal
 * //from   w  ww.  j a  v a 2s  .  c  om
 * @param request
 * @param userInfo
 * @throws JSONException
 */
public static void setSessionInfo(HttpServletRequest request, UserInfo userInfo) throws JSONException {
    request.getSession().setAttribute("openid_identifier", userInfo.user_openid);
    request.getSession().setAttribute("user_identifier", userInfo.user_identifier);
    request.getSession().setAttribute("emailaddress", userInfo.user_email);
    request.getSession().setAttribute("certificate", userInfo.certificate);
    request.getSession().setAttribute("oauth_access_token", userInfo.oauth_access_token);
    request.getSession().setAttribute("login_method", "oauth2");

    try {
        makeUserCertificate(User.makePosixUserId(userInfo.user_identifier));
        Token token = TokenManager.registerToken(UserManager.getUser(userInfo.user_identifier));
        ObjectMapper om = new ObjectMapper();
        String result = om.writeValueAsString(token);
        Debug.println(result);
        JSONObject accessToken = new JSONObject(result);
        // accessToken.put("domain",
        // url.substring(0,url.lastIndexOf("/")).replaceAll("https://",
        // ""));
        if (accessToken.has("error")) {
            Debug.errprintln("Error getting user cert: " + accessToken.toString());
            request.getSession().setAttribute("services_access_token", accessToken.toString());
        } else {
            Debug.println("makeUserCertificate succeeded: " + accessToken.toString());
            request.getSession().setAttribute("services_access_token", accessToken.get("token"));
            // request.getSession().setAttribute("backend", MainServicesConfigurator.getServerExternalURL());
            Debug.println("makeUserCertificate succeeded: " + accessToken);
        }

    } catch (Exception e) {
        request.getSession().setAttribute("services_access_token", null);
        Debug.errprintln("makeUserCertificate Failed");
        Debug.printStackTrace(e);
    }
}

From source file:com.gtwm.pb.servlets.AppController.java

/**
 * Invalidate the user's session//from   w w  w.j a v  a  2  s.  com
 */
private static void logout(HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.invalidate();
}

From source file:jp.go.nict.langrid.servicesupervisor.ServiceSupervisor.java

@SuppressWarnings("unused")
private static HttpServletRequest invoke2(FilterChain chain, HttpServletRequest request,
        HttpServletResponse response, String gridId, String serviceId) throws ServletException, IOException {
    final String sid = serviceId;
    HttpServletRequestWrapper wrequest = new HttpServletRequestWrapper(request) {
        @Override// w  ww  .j a va 2s.  co m
        public String getRequestURI() {
            String u = super.getRequestURI();
            int i = u.lastIndexOf('/');
            u = u.substring(0, i);
            return u + "/Translation?serviceName=" + sid;
        }

        @Override
        public String getPathInfo() {
            return "/Translation";
        }
    };
    request.getSession().getServletContext()
            .getRequestDispatcher("/axisServices/Translation?serviceName=" + serviceId)
            .include(wrequest, response);
    return wrequest;
}

From source file:com.zlfun.framework.excel.ExcelUtils.java

public static <T> List<T> httpInput(HttpServletRequest request, Class<T> clazz) {
    List<T> result = new ArrayList<T>();
    //??  /*w  w w.j ava2s .  c o  m*/
    DiskFileItemFactory factory = new DiskFileItemFactory();
    //??  
    String path = request.getSession().getServletContext().getRealPath("/");
    factory.setRepository(new File(path));
    // ??   
    factory.setSizeThreshold(1024 * 1024);
    ServletFileUpload upload = new ServletFileUpload(factory);

    try {
        //?  
        List<FileItem> list = (List<FileItem>) upload.parseRequest(request);

        for (FileItem item : list) {
            //????  
            String name = item.getFieldName();

            //? ??  ?  
            if (item.isFormField()) {
                //? ??????   
                String value = item.getString();

                request.setAttribute(name, value);
            } //? ??    
            else {
                /**
                 * ?? ??
                 */
                //???  
                String value = item.getName();
                //????  

                fill(clazz, result, value, item.getInputStream());

                //??
            }
        }

    } catch (FileUploadException ex) {
        // TODO Auto-generated catch block      excel=null;
        Logger.getLogger(ExcelUtils.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {

        Logger.getLogger(ExcelUtils.class.getName()).log(Level.SEVERE, null, ex);
    }
    return result;
}

From source file:com.sr.controller.LogoutMonevController.java

@RequestMapping(value = "do")
public String logout(HttpServletRequest request) {
    request.getSession().invalidate();
    return "redirect:/home";
}

From source file:com.easyjf.web.core.FrameworkEngine.java

/**
 * ?requestform// w w w.  j  a v a 2 s  .co  m
 * 
 * @param request
 * @param formName
 * @return ??Form
 */
public static WebForm creatWebForm(HttpServletRequest request, String formName, Module module) {
    Map textElement = new HashMap();
    Map fileElement = new HashMap();
    String contentType = request.getContentType();
    String reMethod = request.getMethod();
    if ((contentType != null) && (contentType.startsWith("multipart/form-data"))
            && (reMethod.equalsIgnoreCase("post"))) {
        //  multipart/form-data
        File file = new File(request.getSession().getServletContext().getRealPath("/temp"));
        if (!file.exists()) {
            file.getParentFile().mkdirs();
        }
        DiskFileItemFactory factory = new DiskFileItemFactory();
        factory.setSizeThreshold(webConfig.getUploadSizeThreshold());
        factory.setRepository(file);
        ServletFileUpload sf = new ServletFileUpload(factory);
        sf.setSizeMax(webConfig.getMaxUploadFileSize());
        sf.setHeaderEncoding(request.getCharacterEncoding());
        List reqPars = null;
        try {
            reqPars = sf.parseRequest(request);
            for (int i = 0; i < reqPars.size(); i++) {
                FileItem it = (FileItem) reqPars.get(i);
                if (it.isFormField()) {
                    textElement.put(it.getFieldName(), it.getString(request.getCharacterEncoding()));// ??
                } else {
                    fileElement.put(it.getFieldName(), it);// ???
                }
            }
        } catch (Exception e) {
            logger.error(e);
        }
    } else if ((contentType != null) && contentType.equals("text/xml")) {
        StringBuffer buffer = new StringBuffer();
        try {
            String s = request.getReader().readLine();
            while (s != null) {
                buffer.append(s + "\n");
                s = request.getReader().readLine();
            }
        } catch (Exception e) {
            logger.error(e);
        }
        textElement.put("xml", buffer.toString());
    } else {
        textElement = request2map(request);
    }
    // logger.debug("????");
    WebForm wf = findForm(formName);
    wf.setValidate(module.isValidate());// ?validate?Form
    if (wf != null) {
        wf.setFileElement(fileElement);
        wf.setTextElement(textElement);
    }
    return wf;
}

From source file:gov.nih.nci.caIMAGE.util.NewDropdownUtil.java

private static synchronized List getTextFileDropdown(HttpServletRequest inRequest, String inDropdownKey)
        throws Exception {
    log.trace("Entering NewDropdownUtil.getTextFileDropdown");

    List theReturnList = new ArrayList<Object>();

    if (ourFileBasedLists.containsKey(inDropdownKey)) {
        log.debug("Dropdown already cached");
        List theCachedList = (List) ourFileBasedLists.get(inDropdownKey);
        theReturnList.addAll(theCachedList);
    } else {/* w  w  w  .  jav a2s.  c o  m*/
        String theFilename = inRequest.getSession().getServletContext().getRealPath("/config/dropdowns") + "/"
                + inDropdownKey;

        List theList = readListFromFile(theFilename);

        // Built a list. Add to static hash
        if (theList.size() != 0) {
            log.debug("Caching new dropdown: " + theList);
            ourFileBasedLists.put(inDropdownKey, theList);
            theReturnList.addAll(theList);
        }
    }

    log.trace("Exiting NewDropdownUtil.getTextFileDropdown");
    return theReturnList;
}

From source file:edu.lfa.df.controller.DefaultController.java

@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(HttpServletRequest req) {
    req.getSession().invalidate();
    return "redirect:/";
}

From source file:edu.lfa.webapp.controller.DefaultController.java

@RequestMapping(value = "/logout", method = RequestMethod.GET)
public String logout(HttpServletRequest req) {
    req.getSession().invalidate();
    return "index";
}