List of usage examples for javax.servlet.http HttpSession getId
public String getId();
From source file:com.twelve.capital.external.feed.util.HttpImpl.java
@Override public String getCompleteURL(HttpServletRequest request) { StringBuffer sb = request.getRequestURL(); if (sb == null) { sb = new StringBuffer(); }// w ww. j a va2 s. c om if (request.getQueryString() != null) { sb.append(StringPool.QUESTION); sb.append(request.getQueryString()); } String proxyPath = PortalUtil.getPathProxy(); if (Validator.isNotNull(proxyPath)) { int x = sb.indexOf(Http.PROTOCOL_DELIMITER) + Http.PROTOCOL_DELIMITER.length(); int y = sb.indexOf(StringPool.SLASH, x); sb.insert(y, proxyPath); } String completeURL = sb.toString(); if (request.isRequestedSessionIdFromURL()) { HttpSession session = request.getSession(); String sessionId = session.getId(); completeURL = PortalUtil.getURLWithSessionId(completeURL, sessionId); } if (_log.isWarnEnabled()) { if (completeURL.contains("?&")) { _log.warn("Invalid url " + completeURL); } } return completeURL; }
From source file:edu.harvard.i2b2.fhir.server.ws.I2b2FhirWS.java
@GET @Path("{resourceName:" + FhirUtil.RESOURCE_LIST_REGEX + "}/{id:[0-9|-]+}") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, "application/xml+fhir", "application/json+fhir" }) public Response getParticularResourceWrapper(@PathParam("resourceName") String resourceName, @PathParam("id") String id, @HeaderParam("accept") String acceptHeader, @Context HttpHeaders headers, @Context HttpServletRequest request, @HeaderParam(AuthenticationFilter.AUTHENTICATION_HEADER) String tokString) throws DatatypeConfigurationException, ParserConfigurationException, SAXException, IOException, JAXBException, JSONException, XQueryUtilException, InterruptedException { logger.debug("got request " + request.getPathInfo() + "?" + request.getQueryString()); HttpSession session = request.getSession(); try {//from w ww .j av a2 s .com String msg = null; String mediaType = ""; authService.authenticateSession( headers.getRequestHeader(AuthenticationFilter.AUTHENTICATION_HEADER).get(0), session); Resource r = getParticularResource(request, resourceName, id, headers); if (r != null) { return generateResponse(acceptHeader, request, r); } else { msg = "xreason:" + resourceName + " with id:" + id + " NOT found"; return Response.ok( FhirHelper.generateOperationOutcome(msg, IssueTypeList.EXCEPTION, IssueSeverityList.ERROR)) .header("session_id", session.getId()).build(); } } catch (Exception e) { logger.error("", e); return Response .ok(FhirHelper.generateOperationOutcome(e.getMessage(), IssueTypeList.EXCEPTION, IssueSeverityList.FATAL)) .header("xreason", e.getMessage()).header("session_id", session.getId()).build(); } }
From source file:org.apache.tapestry.request.RequestContext.java
/** * Writes the state of the context to the writer, typically for inclusion * in a HTML page returned to the user. This is useful * when debugging. The Inspector uses this as well. * **///from ww w . j av a 2s . c o m public void write(IMarkupWriter writer) { // Create a box around all of this stuff ... writer.begin("table"); writer.attribute("class", "request-context-border"); writer.begin("tr"); writer.begin("td"); // Get the session, if it exists, and display it. HttpSession session = getSession(); if (session != null) { object(writer, "Session"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "id", session.getId()); datePair(writer, "creationTime", session.getCreationTime()); datePair(writer, "lastAccessedTime", session.getLastAccessedTime()); pair(writer, "maxInactiveInterval", session.getMaxInactiveInterval()); pair(writer, "new", session.isNew()); List names = getSorted(session.getAttributeNames()); int count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, session.getAttribute(name)); } writer.end(); // Session } object(writer, "Request"); writer.begin("table"); writer.attribute("class", "request-context-object"); // Parameters ... List parameters = getSorted(_request.getParameterNames()); int count = parameters.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Parameters"); header(writer, "Name", "Value(s)"); } String name = (String) parameters.get(i); String[] values = _request.getParameterValues(name); writer.begin("tr"); writer.attribute("class", getRowClass()); writer.begin("th"); writer.print(name); writer.end(); writer.begin("td"); if (values.length > 1) writer.begin("ul"); for (int j = 0; j < values.length; j++) { if (values.length > 1) writer.beginEmpty("li"); writer.print(values[j]); } writer.end("tr"); } section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "authType", _request.getAuthType()); pair(writer, "characterEncoding", _request.getCharacterEncoding()); pair(writer, "contentLength", _request.getContentLength()); pair(writer, "contentType", _request.getContentType()); pair(writer, "method", _request.getMethod()); pair(writer, "pathInfo", _request.getPathInfo()); pair(writer, "pathTranslated", _request.getPathTranslated()); pair(writer, "protocol", _request.getProtocol()); pair(writer, "queryString", _request.getQueryString()); pair(writer, "remoteAddr", _request.getRemoteAddr()); pair(writer, "remoteHost", _request.getRemoteHost()); pair(writer, "remoteUser", _request.getRemoteUser()); pair(writer, "requestedSessionId", _request.getRequestedSessionId()); pair(writer, "requestedSessionIdFromCookie", _request.isRequestedSessionIdFromCookie()); pair(writer, "requestedSessionIdFromURL", _request.isRequestedSessionIdFromURL()); pair(writer, "requestedSessionIdValid", _request.isRequestedSessionIdValid()); pair(writer, "requestURI", _request.getRequestURI()); pair(writer, "scheme", _request.getScheme()); pair(writer, "serverName", _request.getServerName()); pair(writer, "serverPort", _request.getServerPort()); pair(writer, "contextPath", _request.getContextPath()); pair(writer, "servletPath", _request.getServletPath()); // Now deal with any headers List headers = getSorted(_request.getHeaderNames()); count = headers.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Headers"); header(writer, "Name", "Value"); } String name = (String) headers.get(i); String value = _request.getHeader(name); pair(writer, name, value); } // Attributes List attributes = getSorted(_request.getAttributeNames()); count = attributes.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) attributes.get(i); pair(writer, name, _request.getAttribute(name)); } // Cookies ... Cookie[] cookies = _request.getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (i == 0) { section(writer, "Cookies"); header(writer, "Name", "Value"); } Cookie cookie = cookies[i]; pair(writer, cookie.getName(), cookie.getValue()); } // Cookies loop } writer.end(); // Request object(writer, "Servlet"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "servlet", _servlet); pair(writer, "name", _servlet.getServletName()); pair(writer, "servletInfo", _servlet.getServletInfo()); ServletConfig config = _servlet.getServletConfig(); List names = getSorted(config.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Init Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); ; pair(writer, name, config.getInitParameter(name)); } writer.end(); // Servlet ServletContext context = config.getServletContext(); object(writer, "Servlet Context"); writer.begin("table"); writer.attribute("class", "request-context-object"); section(writer, "Properties"); header(writer, "Name", "Value"); pair(writer, "majorVersion", context.getMajorVersion()); pair(writer, "minorVersion", context.getMinorVersion()); pair(writer, "serverInfo", context.getServerInfo()); names = getSorted(context.getInitParameterNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Initial Parameters"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getInitParameter(name)); } names = getSorted(context.getAttributeNames()); count = names.size(); for (int i = 0; i < count; i++) { if (i == 0) { section(writer, "Attributes"); header(writer, "Name", "Value"); } String name = (String) names.get(i); pair(writer, name, context.getAttribute(name)); } writer.end(); // Servlet Context writeSystemProperties(writer); writer.end("table"); // The enclosing border }
From source file:gov.nih.nci.security.upt.actions.ApplicationAction.java
public String setAssociation(String[] associatedIds) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logAssociation.isDebugEnabled()) logAssociation.debug("||" + applicationForm.getFormName() + "|setAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }//from ww w. j av a2 s. c o m try { session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0"); UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); applicationForm.setRequest(request); applicationForm.buildDisplayForm(userProvisioningManager); applicationForm.setAssociatedIds(associatedIds); applicationForm.setAssociationObject(userProvisioningManager); addActionMessage("Association Update Successful"); } catch (CSException cse) { cse.printStackTrace(); addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage())); if (logAssociation.isDebugEnabled()) logAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + applicationForm.getFormName() + "|setAssociation|Failure|Error in setting Association for the " + applicationForm.getFormName() + " object|" + "|" + cse.getMessage()); } session.setAttribute(DisplayConstants.CURRENT_ACTION, DisplayConstants.SEARCH); session.setAttribute(DisplayConstants.CURRENT_FORM, applicationForm); if (logAssociation.isDebugEnabled()) logAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + applicationForm.getFormName() + "|setAssociation|Success|Success in setting association for " + applicationForm.getFormName() + " object|"); return ForwardConstants.SET_ASSOCIATION_SUCCESS; }
From source file:com.azprogrammer.qgf.controllers.HomeController.java
@RequestMapping(value = "/wbSetName") public ModelAndView doWBSetName(ModelMap model, HttpServletRequest req) { model.clear();/*from w w w. j a v a2 s . co m*/ HttpSession session = req.getSession(); PersistenceManager pm = getPM(); WhiteBoard wb = null; try { wb = getWhiteBoard(req); if (wb == null) { throw new Exception("Invalid Whiteboard ID"); } } catch (Exception e) { model.put("error", e.getMessage()); } try { if (wb != null) { String userName = cleanUpName(req); String wbId = KeyFactory.keyToString(wb.getKey()); if ("".equals(userName)) { model.put("error", "Invalid username"); } else { req.getSession().setAttribute("userName", userName); WBChannel wbc = new WBChannel(); wbc.setSessionId(session.getId()); wbc.setWbKey(wb.getKey()); wbc.setUserName(userName); wbc.setTime(System.currentTimeMillis()); wbc.setUserAgent(req.getHeader("user-agent")); pm.makePersistent(wbc); pushNewUserList(wbId); ChannelService channelService = ChannelServiceFactory.getChannelService(); String token = channelService.createChannel(session.getId()); model.put("token", token); model.put("userName", userName); model.put("status", "ok"); } } } catch (Exception e) { model.put("error", e.getMessage()); } return doJSON(model); }
From source file:it.scoppelletti.programmerpower.web.security.SsoAuthenticationService.java
public String newAuthenticationTicket(HttpServletRequest req, HttpServletResponse resp, String userCode, SecureString pwd) {// ww w.j a v a 2s .c o m String tgt, ticket; HttpSession session; AttributeMap sessionMap; if (Strings.isNullOrEmpty(userCode)) { throw new ArgumentNullException("userCode"); } if (Values.isNullOrEmpty(pwd)) { throw new ArgumentNullException("pwd"); } if (req == null) { throw new ArgumentNullException("req"); } if (resp == null) { throw new ArgumentNullException("resp"); } if (myCasClient == null) { throw new PropertyNotSetException(toString(), "casClient"); } myLogger.trace("Calling method newAuthenticationTicket."); try { tgt = myCasClient.newTicketGrantingTicket(userCode, pwd); ticket = myCasClient.newServiceTicket(tgt); } catch (IOException ex) { throw new AuthenticationServiceException(ApplicationException.toString(ex), ex); } session = req.getSession(true); sessionMap = WebUtils.getSynchronizedAttributeMap(session); sessionMap.setAttribute(SsoAuthenticationService.ATTR_TICKETGRANTINGTICKET, tgt); myLogger.debug("New ticket {} for session {}.", ticket, session.getId()); return ticket; }
From source file:gov.nih.nci.security.upt.actions.CommonDoubleAssociationAction.java
public String loadDoubleAssociation(BaseDoubleAssociationForm baseDoubleAssociationForm) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpSession session = request.getSession(); if (session.isNew() || (session.getAttribute(DisplayConstants.LOGIN_OBJECT) == null)) { if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug("||" + baseDoubleAssociationForm.getFormName() + "|loadDoubleAssociation|Failure|No Session or User Object Forwarding to the Login Page||"); return ForwardConstants.LOGIN_PAGE; }/*from www. j av a2 s . c o m*/ session.setAttribute(DisplayConstants.CREATE_WORKFLOW, "0"); try { UserProvisioningManager userProvisioningManager = (UserProvisioningManager) (request.getSession()) .getAttribute(DisplayConstants.USER_PROVISIONING_MANAGER); baseDoubleAssociationForm.setRequest(request); baseDoubleAssociationForm.buildDoubleAssociationObject(userProvisioningManager); } catch (CSException cse) { addActionError(org.apache.commons.lang.StringEscapeUtils.escapeHtml(cse.getMessage())); if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadDoubleAssociation|Failure|Error Loading Double Association for the " + baseDoubleAssociationForm.getFormName() + " object|" + "|" + cse.getMessage()); } if (logDoubleAssociation.isDebugEnabled()) logDoubleAssociation.debug(session.getId() + "|" + ((LoginForm) session.getAttribute(DisplayConstants.LOGIN_OBJECT)).getLoginId() + "|" + baseDoubleAssociationForm.getFormName() + "|loadDoubleAssociation|Success|Success in Loading Double Association for " + baseDoubleAssociationForm.getFormName() + " object|" + "|"); return ForwardConstants.LOAD_DOUBLEASSOCIATION_SUCCESS; }
From source file:Controller.UserController.java
@RequestMapping(value = "/UpdateInformation", method = RequestMethod.POST) public String updateInformation(HttpServletRequest request, HttpSession session) { try {// w ww .j av a 2 s.c o m AccountSession account = tripperService.updateTripperInformation(request, session); session.setAttribute("account", account); if (request.getParameter("language") != null) { return "redirect:/Tripper/AccountInfo" + "?language=" + request.getParameter("language"); } else { return "redirect:/Tripper/AccountInfo"; } } catch (Exception e) { String content = "Function: UserController - updateInformation\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:org.apache.wicket.protocol.http.mock.MockHttpServletRequest.java
@Override public String changeSessionId() { final HttpSession oldSession = getSession(false); if (oldSession == null) { throw new IllegalStateException("There is no active session associated with the current request"); }// www. j a va 2 s . co m oldSession.invalidate(); final HttpSession newSession = getSession(true); return newSession.getId(); }
From source file:Controller.UserController.java
@RequestMapping(value = "/Chat", method = RequestMethod.GET) public String gotoChat(HttpServletRequest request) { try {/* w w w.j a v a 2 s . c om*/ request.setAttribute("page", "tripperMessage"); String conversationList = ""; HttpSession session = request.getSession(true); AccountSession account = (AccountSession) session.getAttribute("account"); conversationList = messageService.getListConversationbyTripperID(account.getId()); request.setAttribute("conversationList", conversationList); // tripperService.seenMessage(account.getId()); return "tripper/chat"; } catch (Exception e) { HttpSession session = request.getSession(true); String content = "Function: UserController - gotoChat\n" + "****Error****\n" + e.getMessage() + "\n" + "**********"; request.setAttribute("errorID", session.getId()); request.setAttribute("errorTime", errorService.logBugWithAccount(content, session, e)); return "forward:/Common/Error"; } }