List of usage examples for javax.servlet.http HttpSession getId
public String getId();
From source file:org.esigate.servlet.impl.RequestFactory.java
public IncomingRequest create(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException { HttpServletRequestContext context = new HttpServletRequestContext(request, response, servletContext, filterChain);//from ww w.j a v a 2 s. c o m // create request line String uri = UriUtils.createURI(request.getScheme(), request.getServerName(), request.getServerPort(), request.getRequestURI(), request.getQueryString(), null); ProtocolVersion protocolVersion = BasicLineParser.parseProtocolVersion(request.getProtocol(), null); IncomingRequest.Builder builder = IncomingRequest .builder(new BasicRequestLine(request.getMethod(), uri, protocolVersion)); builder.setContext(context); // copy headers @SuppressWarnings("rawtypes") Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); @SuppressWarnings("rawtypes") Enumeration values = request.getHeaders(name); while (values.hasMoreElements()) { String value = (String) values.nextElement(); builder.addHeader(name, value); } } // create entity HttpServletRequestEntity entity = new HttpServletRequestEntity(request); builder.setEntity(entity); builder.setRemoteAddr(request.getRemoteAddr()); builder.setRemoteUser(request.getRemoteUser()); HttpSession session = request.getSession(false); if (session != null) { builder.setSessionId(session.getId()); } builder.setUserPrincipal(request.getUserPrincipal()); // Copy cookies // As cookie header contains only name=value so we don't need to copy // all attributes! javax.servlet.http.Cookie[] src = request.getCookies(); if (src != null) { for (int i = 0; i < src.length; i++) { javax.servlet.http.Cookie c = src[i]; BasicClientCookie dest = new BasicClientCookie(c.getName(), c.getValue()); builder.addCookie(dest); } } builder.setSession(new HttpServletSession(request)); builder.setContextPath(request.getContextPath()); return builder.build(); }
From source file:org.hbr.mongo.session.controller.SessionController.java
/** * Test the Session/*from w w w . java2s . co m*/ * @return */ @RequestMapping(value = "/get-session", method = RequestMethod.GET) public ModelAndView getSession(HttpSession session) { /* add a property to the session */ session.setAttribute("TEST", "TEST"); Map<String, Object> model = new HashMap<String, Object>(); model.put("id", session.getId()); return new ModelAndView("displaySession", model); }
From source file:edu.umn.msi.tropix.webgui.server.messages.MessageManager.java
public Collection<T> drainQueue() { final HttpSession session = httpSessionSupplier.get(); final String sessionId = session.getId(); final String userId = userSession.getGridId(); final List<T> objects = Lists.newArrayList(); if (userId == null) { return objects; }/*from w ww .j a v a2s . c o m*/ CircularFifoBuffer queue; synchronized (userToSessionMap) { if (!userToSessionMap.containsEntry(userId, sessionId)) { final CloseWithSession finalizer = new CloseWithSession(userId, sessionId); session.setAttribute("messageManagerFinalizingObject", finalizer); userToSessionMap.put(userId, sessionId); sessionToUserMap.put(sessionId, userId); } if (!bufferMap.containsKey(sessionId)) { final CircularFifoBuffer objectBuffer = new CircularFifoBuffer(25); bufferMap.put(sessionId, objectBuffer); } queue = bufferMap.get(sessionId); } synchronized (queue) { while (!queue.isEmpty()) { @SuppressWarnings("unchecked") final T object = (T) queue.remove(); if (object == null) { break; } objects.add(object); } } return objects; }
From source file:com.kurento.kmf.jsonrpcconnector.internal.http.JsonRpcHttpRequestHandler.java
@Override public void handleRequest(HttpServletRequest servletRequest, final HttpServletResponse servletResponse) throws ServletException, IOException { String messageJson = getBodyAsString(servletRequest); ServerSessionFactory factory = new ServerSessionFactory() { @Override// w ww . j a va2 s .c om public ServerSession createSession(String sessionId, Object registerInfo, SessionsManager sessionsManager) { return new HttpRequestServerSession(sessionId, registerInfo, sessionsManager, null); } }; ResponseSender responseSender = new ResponseSender() { @Override public void sendResponse(Message message) throws IOException { servletResponse.getWriter().println(message); } }; String internalSessionId = null; HttpSession session = servletRequest.getSession(false); if (session != null) { internalSessionId = session.getId(); } protocolManager.processMessage(messageJson, factory, responseSender, internalSessionId); }
From source file:org.zht.framework.interceptors.TokenInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (handler instanceof HandlerMethod) { HandlerMethod handlerMethod = (HandlerMethod) handler; Method method = handlerMethod.getMethod(); RepeatToken annotation = method.getAnnotation(RepeatToken.class); if (annotation != null) { HttpSession session = request.getSession(false); if (session == null) { return true; }/*w w w.j a va 2 s .c o m*/ String seesionId = session.getId(); String uri = request.getRequestURI(); Boolean isPosted = (Boolean) session.getAttribute("_Token" + seesionId + uri); if (isPosted == null || isPosted == false) { session.setAttribute("_Token" + seesionId + uri, true); return true; } else { //?? return false; } } return true; } else { return super.preHandle(request, response, handler); } }
From source file:photosharing.api.bss.LogoutDefinition.java
/** * redirects the user to the logout SSO to destroy the login tokens and login sessions * //from ww w . jav a 2s.c o m * @see photosharing.api.conx.APIDefinition#run(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ public void run(HttpServletRequest request, HttpServletResponse response) { Configuration config = Configuration.getInstance(request); String api = config.getValue(Configuration.BASEURL) + apiUrl; try { //Invalidating photosharing session on the AppServer and IBM Connections Cloud HttpSession session = request.getSession(false); if (session != null) { logger.info(session.getId() + " is being logged out"); Request get = Request.Get(api); try { Executor exec = ExecutorUtil.getExecutor(); Response apiResponse = exec.execute(get); HttpResponse hr = apiResponse.returnResponse(); /** * Check the status codes and if 200, convert to String */ int code = hr.getStatusLine().getStatusCode(); if (code == HttpStatus.SC_OK) { } else { logger.log(Level.SEVERE, "Exception Encountered with IBM Connections Cloud Session"); } } catch (IOException e) { //Catches Exception Related to a Request logger.log(Level.SEVERE, "Exception Encountered"); response.setHeader("X-Application-Error", className); response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } //Indvalidates the User's current session and logs them out session.invalidate(); request.logout(); //Sets the Status to SC_OK (Http Status Code 200) to indicate a successful logout response.setStatus(HttpStatus.SC_NO_CONTENT); } else { //Something bad has happened logger.log(Level.SEVERE, "Invalid Request"); response.setStatus(HttpStatus.SC_BAD_REQUEST); } } catch (Exception e) { logger.log(Level.SEVERE, "Exception Encountered - " + e.toString()); //Sets the Status to SC_INTERNAL_SERVER_ERROR (Http Status Code 500) //Indicates an issue with the Server response.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.du.order.dist.log.LoggingFilter.java
private void logRequest(final HttpServletRequest request) { StringBuilder msg = new StringBuilder(); msg.append(REQUEST_PREFIX);//from w ww. j a v a 2s. c o m if (request instanceof RequestWrapper) { msg.append("request id=").append(((RequestWrapper) request).getId()).append("; "); } HttpSession session = request.getSession(false); if (session != null) { msg.append("session id=").append(session.getId()).append("; "); } if (request.getMethod() != null) { msg.append("method=").append(request.getMethod()).append("; "); } if (request.getContentType() != null) { msg.append("content type=").append(request.getContentType()).append("; "); } msg.append("uri=").append(request.getRequestURI()); if (request.getQueryString() != null) { msg.append('?').append(request.getQueryString()); } if (request instanceof RequestWrapper && !isMultipart(request) && !isBinaryContent(request)) { RequestWrapper requestWrapper = (RequestWrapper) request; try { // TODO deniz check it ( String str = new String(requestWrapper.toByteArray(), charEncoding); ); String charEncoding = requestWrapper.getCharacterEncoding() != null ? requestWrapper.getCharacterEncoding() : "UTF-8"; String str = new String(requestWrapper.toByteArray(), charEncoding); str = "".equals(str) || str == null ? "{}" : str; msg.append("; payload=").append(JsonFormatter.format(new JSONObject())); } catch (UnsupportedEncodingException e) { logger.warn("Failed to parse request payload", e); } } logger.info(msg.toString()); }
From source file:com.github.isrsal.logging.LoggingFilter.java
private void logRequest(final HttpServletRequest request) { StringBuilder msg = new StringBuilder(); msg.append(REQUEST_PREFIX);//from w w w . j a v a2 s . c om if (request instanceof RequestWrapper) { msg.append("request id=").append(((RequestWrapper) request).getId()).append("; "); } HttpSession session = request.getSession(false); if (session != null) { msg.append("session id=").append(session.getId()).append("; "); } if (request.getMethod() != null) { msg.append("method=").append(request.getMethod()).append("; "); } if (request.getContentType() != null) { msg.append("content type=").append(request.getContentType()).append("; "); } msg.append("uri=").append(request.getRequestURI()); if (request.getQueryString() != null) { msg.append('?').append(request.getQueryString()); } if (request instanceof RequestWrapper && !isMultipart(request) && !isBinaryContent(request)) { RequestWrapper requestWrapper = (RequestWrapper) request; try { String charEncoding = requestWrapper.getCharacterEncoding() != null ? requestWrapper.getCharacterEncoding() : "UTF-8"; msg.append("; payload=").append(new String(requestWrapper.toByteArray(), charEncoding)); } catch (UnsupportedEncodingException e) { logger.warn("Failed to parse request payload", e); } if (!requestWrapper.getParameterMap().isEmpty()) { msg.append("; parameters="); Map<String, String[]> parameterMap = requestWrapper.getParameterMap(); for (String key : parameterMap.keySet()) { msg.append(key + ":" + Arrays.toString(parameterMap.get(key))).append(";"); } } } logger.debug(msg.toString()); }
From source file:org.beanfuse.security.monitor.DefaultSecurityMonitor.java
/** * <br>/*from www . j ava2 s. com*/ * ?session<br> * ??<br> * ?? * * @param sessionId */ public void logout(HttpSession session) { String sessionId = session.getId(); OnlineActivity info = sessionController.getOnlineActivity(sessionId); if (null != info) { sessionController.removeAuthentication(sessionId); if (!sessionController.isRegisted(info.getPrincipal())) { authorityDecisionService.removeAuthorities(info.getUserid()); } httpSessionIntegrationFilter.clear(session); } }
From source file:com.flexive.war.listener.SessionTimeoutListener.java
@Override public void sessionDestroyed(HttpSessionEvent event) { final HttpSession session = event.getSession(); if (LOG.isDebugEnabled()) { LOG.debug("Session destroyed: " + session.getId()); }//from w w w . ja v a 2s . c o m // set parameters needed for logout final FxContext ctx = FxContext.get(); try { ctx.setSessionID(session.getId()); // retrieve context path final ServletContext servletContext = session.getServletContext(); if (servletContext != null) { ctx.setContextPath(servletContext.getContextPath()); } // get division ID from session final String divisionIdKey = FxSessionWrapper.encodeAttributeName(FxContext.SESSION_DIVISIONID); if (session.getAttribute(divisionIdKey) != null) { ctx.setDivisionId((Integer) session.getAttribute(divisionIdKey)); } if (ctx.getDivisionId() == -1 || !CacheAdmin.isEnvironmentLoaded()) { // probably during undeploy return; } ctx.setTicket(FxContext.getTicketFromEJB(session)); if (!ctx.getTicket().isGuest()) { // perform logout only when the user is logged in if (LOG.isDebugEnabled()) { LOG.debug("Performing logout for user of destroyed session (possible session timeout): " + session.getId()); } onLogout(ctx.getTicket()); ctx.logout(); } } catch (FxLogoutFailedException e) { LOG.error("Failed to logout user after session timeout: " + e.getMessage(), e); } finally { FxContext.cleanup(); } }