private HttpSession getSessionInstance() { if (!sessionWasRequested) { sessionWasRequested = true; String sessionId = getRequestedSessionId(); if (sessionId != null) { session = servletContext.getSession(sessionId); } } return session; }
/** * {@inheritDoc} */ @Override public HttpSession getSession() { return getSession(true); }
/** * {@inheritDoc} */ @Override public void invalidate() throws IllegalStateException { checkInvalidatedSession(); isInvalidated = true; }
private void flushHeadersIfPossible() throws IOException { if (!response.isCommitted()) { response.flushHeaders(); } }
/** * {@inheritDoc} */ @Override public HttpSession getSession(final boolean create) { getSessionInstance(); if (session == null && create) { session = servletContext.createNewSession(); } if (session != null) { session.setLastAccessedTime(System.currentTimeMillis()); } return session; }
/** * {@inheritDoc} */ @Override public String getContextPath() { return servletContext.getContextPath(); }
private Servlet initializeServlet(final Class<? extends HttpServlet> serverClass, final ServletConfig servletConfig) throws ServletInitializationException, ServletException { Servlet servlet = instantiateServlet(serverClass); servlet.init(servletConfig); servlets.put(serverClass, servlet); servletStats.put(serverClass, new ServletStats()); return servlet; }
/** * {@inheritDoc} */ @Override public Servlet getServletForClass(final Class<? extends HttpServlet> servletClass, final ServletConfig servletConfig) throws ServletInitializationException, ServletException { if (servlets.containsKey(servletClass)) { servletStats.get(servletClass).setLastRequestedAt(dateProvider.now()); return servlets.get(servletClass); } return initializeServlet(servletClass, servletConfig); }
/** * {@inheritDoc} */ @Override public void sendRedirect(final String location) { this.setStatus(HttpServletResponse.STATUS_MOVED_PERMANENTLY); headers.setHeader(Headers.HEADER_LOCATION, location); }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenPuttingIntoInvalidatedSession() { session.invalidate(); session.setAttribute("attribute", "value"); }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionWhenReadingAttributeNamesInvalidatedSession() { session.invalidate(); session.getAttributeNames(); } }
/** * {@inheritDoc} */ @Override public boolean isRequestedSessionIdValid() { return getSessionInstance() != null; }
/** * The constructor is private so that it can only be used trough HttpServletRequestImpl#createNewBuilder(). */ private Builder() { internal = new HttpServletRequestImpl(); }
public static Builder createNewBuilder() { return new Builder(); }
/** * {@inheritDoc} */ @Override public void setKeepAlive(final boolean keepAlive) { headers.setHeader(Headers.HEADER_CONNECTION, getKeepAliveHeaderValue(keepAlive)); }
/** * {@inheritDoc} */ @Override public long getLastAccessedTime() throws IllegalStateException { checkInvalidatedSession(); return lastAccessedTime; }
/** * {@inheritDoc} */ @Override public boolean isNew() { checkInvalidatedSession(); return creationTime == lastAccessedTime; }
/** * {@inheritDoc} */ @Override public long getCreationTime() throws IllegalStateException { checkInvalidatedSession(); return creationTime; }
/** * {@inheritDoc} */ @Override public void removeAttribute(final String name) throws IllegalStateException { checkInvalidatedSession(); attributes.remove(name); }
/** * {@inheritDoc} */ @Override public void setAttribute(final String name, final Object value) throws IllegalStateException { checkInvalidatedSession(); if (value == null) { attributes.remove(name); } else { attributes.put(name, value); } }