Example usage for javax.servlet.http HttpSession getId

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

Introduction

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

Prototype

public String getId();

Source Link

Document

Returns a string containing the unique identifier assigned to this session.

Usage

From source file:Controller.UserController.java

@RequestMapping(value = "/RemoveFromWishList/{packageID}", method = RequestMethod.GET)
public String removeFromWishlist(@PathVariable int packageID, HttpSession session, ModelMap map,
        HttpServletRequest request) {/*from   w  ww  .  ja  v  a 2s .  c  o m*/
    try {
        tripperService.removeWishlist(packageID, session);
        if (request.getParameter("language") != null) {
            return "redirect:/Tripper/BucketList" + "?language=" + request.getParameter("language");
        } else {
            return "redirect:/Tripper/BucketList";
        }

    } catch (Exception e) {
        String content = "Function: UserController - removeFromWishlist\n" + "***Input***\n" + "packageID: "
                + packageID + "\n" + "**********\n" + "****Error****\n" + e.getMessage() + "\n" + "**********";
        map.addAttribute("errorID", session.getId());
        map.addAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";

    }

}

From source file:Controller.UserController.java

@RequestMapping(value = "/BucketList")
public String getBucketList(HttpServletRequest request) {
    try {//  www  .  j a  v  a 2 s . c o  m
        HttpSession session = request.getSession(true);
        AccountSession account = (AccountSession) session.getAttribute("account");
        List<PackagesViewDTO> bucketList = packageService.getBucketList(account.getId());
        Gson gson = new Gson();
        request.setAttribute("BucketList", gson.toJson(bucketList));
        request.setAttribute("page", "bucketPackages");
        return "tripper/bucketList";
    } catch (Exception e) {
        HttpSession session = request.getSession(true);
        String content = "Function: UserController - getBucketList\n" + "****Error****\n" + e.getMessage()
                + "\n" + "**********";
        request.setAttribute("errorID", session.getId());
        request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }
}

From source file:Controller.UserController.java

@RequestMapping(value = "/BookingList")
public String getBookingList(HttpServletRequest request) {
    try {//from  w w  w.j  av a 2  s  .  c om
        HttpSession session = request.getSession(true);
        AccountSession account = (AccountSession) session.getAttribute("account");
        List<BookingDTO> booking = tripperService.getBookingListForTripper(account.getId());
        Gson gson = new Gson();
        request.setAttribute("BookingList", gson.toJson(booking));
        request.setAttribute("page", "tripperBookings");
        return "tripper/booking";
    } catch (Exception e) {
        HttpSession session = request.getSession(true);
        String content = "Function: UserController - getBookingList\n" + "****Error****\n" + e.getMessage()
                + "\n" + "**********";
        request.setAttribute("errorID", session.getId());
        request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }

}

From source file:com.adito.security.DefaultLogonController.java

public User getUser(HttpSession session, String logonTicket) throws SecurityErrorException {
    if (logonTicket == null) {
        logonTicket = (String) session.getAttribute(Constants.LOGON_TICKET);
    }//from  ww  w. j  a v  a 2s  .c  om
    if (logonTicket == null) {
        throw new SecurityErrorException(SecurityErrorException.ERR_INVALID_TICKET,
                "No ticket was provided or found in the session object (" + session.getId() + ")");
    }
    SessionInfo info = (SessionInfo) logons.get(logonTicket);
    if (info == null) {
        throw new SecurityErrorException(SecurityErrorException.ERR_INVALID_TICKET,
                "No session info. object could be found for the ticket (" + session.getId() + ")");
    }
    User user = info.getUser();
    return user;
}

From source file:gov.nih.nci.security.upt.actions.CommonDBAction.java

/**
* Added this method to handle pre-popup search results.
*//*from   w  w w .  j av  a2s  . co m*/

public String loadOriginalSearchResult(BaseDBForm baseDBForm) throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();

    if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) {
        if (logDB.isDebugEnabled())
            logDB.debug("||" + baseDBForm.getFormName()
                    + "|loadSearchResult|Failure|No Session or User Object Forwarding to the Login Page||");
        return ForwardConstants.LOGIN_PAGE;
    }

    if (session.getAttribute(DisplayConstants.CREATE_WORKFLOW) != null) {
        session.removeAttribute(DisplayConstants.CREATE_WORKFLOW);
        //session.removeAttribute(DisplayConstants.SEARCH_RESULT);
        return ForwardConstants.LOAD_HOME_SUCCESS;
    } else {
        if (session.getAttribute(DisplayConstants.ORIGINAL_SEARCH_RESULT) != null) {
            session.setAttribute(DisplayConstants.SEARCH_RESULT,
                    session.getAttribute(DisplayConstants.ORIGINAL_SEARCH_RESULT));
            session.removeAttribute(DisplayConstants.ORIGINAL_SEARCH_RESULT);
        }
    }

    if (logDB.isDebugEnabled())
        logDB.debug(session.getId() + "|"
                + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|"
                + baseDBForm.getFormName() + "|loadSearchResult|Success|Loading the Search Result Page||");
    return ForwardConstants.LOAD_SEARCH_RESULT_SUCCESS;
}

From source file:com.uniquesoft.uidl.servlet.UploadServlet.java

/**
 * Method executed each time the client asks the server for the progress status.
 * It uses the listener to generate the adequate response
 * /*from w w  w  . j  av a 2s. com*/
 * @param request
 * @param fieldname
 * @return a map of tag/values to be rendered 
 */
protected Map<String, String> getUploadStatus(HttpServletRequest request, String fieldname,
        Map<String, String> ret) {

    perThreadRequest.set(request);

    HttpSession session = request.getSession();

    if (ret == null) {
        ret = new HashMap<String, String>();
    }

    long currentBytes = 0;
    long totalBytes = 0;
    long percent = 0;
    AbstractUploadListener listener = getCurrentListener(request);
    if (listener != null) {
        if (listener.getException() != null) {
            if (listener.getException() instanceof UploadCanceledException) {
                ret.put(TAG_CANCELED, "true");
                ret.put(TAG_FINISHED, TAG_CANCELED);
                logger.error("UPLOAD-SERVLET (" + session.getId() + ") getUploadStatus: " + fieldname
                        + " canceled by the user after " + listener.getBytesRead() + " Bytes");
            } else {
                String errorMsg = getMessage("server_error", listener.getException().getMessage());
                ret.put(TAG_ERROR, errorMsg);
                ret.put(TAG_FINISHED, TAG_ERROR);
                logger.error("UPLOAD-SERVLET (" + session.getId() + ") getUploadStatus: " + fieldname
                        + " finished with error: " + listener.getException().getMessage());
            }
        } else {
            currentBytes = listener.getBytesRead();
            totalBytes = listener.getContentLength();
            percent = totalBytes != 0 ? currentBytes * 100 / totalBytes : 0;
            // logger.debug("UPLOAD-SERVLET (" + session.getId() + ") getUploadStatus: " + fieldname + " " + currentBytes + "/" + totalBytes + " " + percent + "%");
            ret.put(TAG_PERCENT, "" + percent);
            ret.put(TAG_CURRENT_BYTES, "" + currentBytes);
            ret.put(TAG_TOTAL_BYTES, "" + totalBytes);
            if (listener.isFinished()) {
                ret.put(TAG_FINISHED, "ok");
            }
        }
    } else if (getMySessionFileItems(request) != null) {
        if (fieldname == null) {
            ret.put(TAG_FINISHED, "ok");
            logger.debug("UPLOAD-SERVLET (" + session.getId() + ") getUploadStatus: " + request.getQueryString()
                    + " finished with files: " + session.getAttribute(getSessionFilesKey(request)));
        } else {
            List<FileItem> sessionFiles = getMySessionFileItems(request);
            for (FileItem file : sessionFiles) {
                if (file.isFormField() == false && file.getFieldName().equals(fieldname)) {
                    ret.put(TAG_FINISHED, "ok");
                    ret.put(UConsts.PARAM_FILENAME, fieldname);
                    logger.debug("UPLOAD-SERVLET (" + session.getId() + ") getUploadStatus: " + fieldname
                            + " finished with files: " + session.getAttribute(getSessionFilesKey(request)));
                }
            }
        }
    } else {
        logger.debug("UPLOAD-SERVLET (" + session.getId() + ") getUploadStatus: no listener in session");
        ret.put("wait", "listener is null");
    }
    if (ret.containsKey(TAG_FINISHED)) {
        removeCurrentListener(request);
    }

    perThreadRequest.set(null);
    return ret;
}

From source file:com.glaf.base.modules.website.springmvc.UserAuthController.java

@ResponseBody
@RequestMapping//from  w w w  . java2 s . c o m
public byte[] auth(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String json = request.getParameter("json");
    JSONObject jsonObject = JSON.parseObject(json);
    JSONObject result = new JSONObject();
    String actorId = jsonObject.getString("x");
    String password = jsonObject.getString("y");
    String email = jsonObject.getString("email");
    if (sysUserService.findByMail(email) != null) {
        result.put("status", 500);
        result.put("message", "?????");
        return result.toJSONString().getBytes("UTF-8");
    }
    SysUser user = sysUserService.findByAccount(actorId);
    int status = 0;
    if (user != null) {
        // ???????
        String pwd = DigestUtil.digestString(password, "MD5");
        if (pwd != null && !user.getPassword().equals(pwd)) {
            status = 500;
            result.put("status", 500);
            result.put("message", "???");
        } else if (user.getBlocked() == 1) {
            status = 500;
            result.put("status", 500);
            result.put("message", "????");
        } else {
            status = 200;
            result.put("status", 200);
            result.put("message", "?");
        }
    } else {
        user = new SysUser();
        user.setAccount(actorId);

        try {
            String pwd = DigestUtil.digestString(password, "MD5");
            user.setPassword(pwd);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        long deptId = 0;
        if (jsonObject.containsKey("deptId")) {
            deptId = Long.parseLong(jsonObject.getString("deptId"));
        }
        user.setDeptId(deptId);

        user.setName(jsonObject.getString("name"));
        if (user.getName() == null) {
            user.setName(actorId);
        }
        user.setMobile(jsonObject.getString("mobile"));
        user.setEmail(jsonObject.getString("email"));
        user.setUserType(0);
        user.setAccountType(2);
        user.setEvection(0);
        user.setCreateTime(new Date());
        user.setLastLoginTime(new Date());
        user.setLastChangePasswordDate(new Date());
        user.setIsChangePassword(0);
        user.setCreateBy("website");
        user.setUpdateBy("website");
        List<String> roleCodes = new java.util.ArrayList<String>();
        roleCodes.add("website");
        try {
            if (complexUserService.createUser(user, roleCodes)) {
                status = 200;
            }
        } catch (Exception ex) {
            status = 500;
            logger.error(ex);
        }
        if (status == 200) {// ??
            result.put("status", 200);
            result.put("message", "?");
        } else if (status == 500) {
            result.put("status", 500);
            result.put("message", "");
        }
    }

    if (status == 200) {

        HttpSession session = request.getSession(true);
        ContextUtil.put(actorId, user);// ??
        RequestUtils.setLoginUser(request, response, "default", actorId);

        java.util.Random random = new java.util.Random();
        String token = org.apache.commons.codec.digest.DigestUtils.md5Hex(actorId)
                + Math.abs(random.nextInt(9999)) + com.glaf.core.util.UUID32.getUUID()
                + Math.abs(random.nextInt(9999));
        result.put("actorId", actorId);
        result.put("token", token);

        try {
            if (user.getLoginCount() != null) {
                user.setLoginCount(user.getLoginCount() + 1);
            } else {
                user.setLoginCount(1);
            }

            // ?
            user.setLastLoginDate(new Date());
            sysUserService.updateUser(user);

            UserOnline online = new UserOnline();
            online.setActorId(user.getActorId());
            online.setName(user.getName());
            online.setCheckDate(new Date());
            online.setLoginDate(new Date());
            online.setLoginIP(RequestUtils.getIPAddress(request));
            online.setSessionId(session.getId());
            userOnlineService.login(online);
        } catch (Exception ex) {
            ex.printStackTrace();
            logger.error(ex);
        }
    }

    return result.toJSONString().getBytes("UTF-8");
}

From source file:Controller.UserController.java

@RequestMapping(value = "/payPaypalSuccess")
String payPaypalSuccess(HttpServletRequest request) {
    try {//  w ww  .  j a va  2  s  . co  m
        String paymentID = request.getParameter("paymentId");
        String payerID = request.getParameter("PayerID");
        int packageID = Integer.parseInt(request.getParameter("packageID"));
        String selectedDate = request.getParameter("selDate");
        int numberOfChilds = Integer.parseInt(request.getParameter("numChild"));
        int numberOfAdults = Integer.parseInt(request.getParameter("numAdult"));
        int accountID = Integer.parseInt(request.getParameter("accountID"));
        boolean verifiyPayment = tripperService.verifyPayment(paymentID, payerID);
        if (verifiyPayment) {
            String code = tripperService.getBookingCode();
            if (tripperService.insertBooking(code, packageID, selectedDate, numberOfChilds, numberOfAdults,
                    accountID)) {
                PackageDTO packgeDTO = tripperService.getPackageForPayment(packageID);
                int providerID = packgeDTO.getProviderID();
                boolean notifyForProvider = providerService
                        .insertNewProviderSystemNotification("{\"URL\":\"Noti/ProviderViewBooking/" + code
                                + "\",\"Message\":\"You have a new booking\"}", false, providerID);
                boolean notifyForTripper = tripperService
                        .insertNewTripperSystemNotification("{\"URL\":\"Noti/TripperViewBooking/" + code
                                + "\",\"Message\":\"You had booked a trip!\"}", false, accountID);
                String providerNoti = providerService.getProviderNewNotification(providerID);
                template.convertAndSend("/topic/Notifications/Provider/" + providerID, providerNoti);
                String tripperNoti = tripperService.getTripperNewNotification(accountID);
                template.convertAndSend("/topic/Notifications/Tripper/" + accountID, tripperNoti);
                return "/tripper/paymentSuccess";
            }
        }
        return "forward:/Common/Error";
    } catch (Exception e) {
        HttpSession session = request.getSession(true);
        String content = "Function: UserController - payPaypalSuccess\n" + "***Input***\n" + "paymentId: "
                + request.getParameter("paymentId") + "\n" + "PayerID: " + request.getParameter("PayerID")
                + "\n" + "packageID: " + request.getAttribute("packageID") + "\n" + "selDate: "
                + request.getAttribute("selDate") + "\n" + "numChild: " + request.getAttribute("numChild")
                + "\n" + "numAdult: " + request.getParameter("numAdult") + "\n" + "accountID: "
                + request.getParameter("accountID") + "\n" + "**********\n" + "****Error****\n" + e.getMessage()
                + "\n" + "**********";
        request.setAttribute("errorID", session.getId());
        request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e));
        return "forward:/Common/Error";
    }

}

From source file:com.adito.security.DefaultLogonController.java

public synchronized int addSessionTimeoutBlock(HttpSession session, String reason) {
    Map sessionTimeoutBlocks = (Map) session.getAttribute(Constants.SESSION_TIMEOUT_BLOCKS);
    if (sessionTimeoutBlocks == null) {
        sessionTimeoutBlocks = new HashMap();
        session.setAttribute(Constants.SESSION_TIMEOUT_BLOCKS, sessionTimeoutBlocks);
    }//w w  w.ja v  a2  s.c o m
    sessionTimeoutBlocks.put(String.valueOf(++sessionTimeoutBlockId), reason);
    if (log.isDebugEnabled())
        log.debug("Preventing session timeout on session " + session.getId() + " (id of "
                + sessionTimeoutBlockId + ") because '" + reason + "'. There are now "
                + sessionTimeoutBlocks.size() + " reasons not to timeout the session.");
    session.setMaxInactiveInterval(-1);
    return sessionTimeoutBlockId;
}

From source file:com.adito.security.DefaultLogonController.java

public void resetSessionTimeout(User user, PropertyProfile profile, HttpSession session) {
    try {/*  w ww .j ava2 s  .  c  o  m*/
        Map sessionTimeoutBlocks = (Map) session.getAttribute(Constants.SESSION_TIMEOUT_BLOCKS);
        int minutes = 0;
        if (sessionTimeoutBlocks == null || sessionTimeoutBlocks.size() == 0) {
            minutes = CoreUtil.getUsersProfilePropertyIntOrDefault(session,
                    "webServer.sessionInactivityTimeout", user);
        }
        if (log.isDebugEnabled())
            log.debug("Resetting timeout for session " + session.getId() + " to " + minutes + " minutes");
        session.setMaxInactiveInterval(minutes == 0 ? -1 : minutes * 60);
    } catch (Exception e) {
        log.error("Failed to reset session timeout.", e);
    }
}