Skip to content

Commit

Permalink
Fix for #242 Atmosphere&Jersey: Problem with using the session, Fix for
Browse files Browse the repository at this point in the history
#230 [runtime][jetty] Session lost on first request
  • Loading branch information
jfarcand committed Mar 27, 2012
1 parent 76d48a3 commit 3c1f151
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public JettyRequestFix(AtmosphereRequest request) {
this.serverPort = request.getServerPort();

HttpSession session = request.getSession(true);
httpSession = new FakeHttpSession(session.getId(), session.getServletContext(), session.getCreationTime());
httpSession = new FakeHttpSession(session);

Enumeration<String> e = request.getHeaderNames();
String s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class AtmosphereRequest implements HttpServletRequest {
private AtmosphereRequest(Builder b) {
pathInfo = b.pathInfo == "" ? b.request.getPathInfo() : b.pathInfo;
session = b.request == null ?
new FakeHttpSession("", null, System.currentTimeMillis()) : b.request.getSession();
new FakeHttpSession("", null, System.currentTimeMillis(), -1) : b.request.getSession();

if (b.inputStream == null) {
if (b.dataBytes != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ public class FakeHttpSession implements HttpSession {
private final ServletContext servletContext;
private int maxInactiveInterval;

public FakeHttpSession(String sessionId, ServletContext servletContext, long creationTime) {
public FakeHttpSession(String sessionId, ServletContext servletContext, long creationTime, int maxInactiveInterval) {
this.sessionId = sessionId;
this.servletContext = servletContext;
this.creationTime = creationTime;
this.maxInactiveInterval = maxInactiveInterval;
}

public FakeHttpSession(HttpSession session) {
this(session.getId(), session.getServletContext(), session.getLastAccessedTime(), session.getMaxInactiveInterval());
copyAttributes(session);
}

public void destroy() {
Expand Down Expand Up @@ -115,6 +121,16 @@ public void removeValue(String name) {
attributes.remove(name);
}

public FakeHttpSession copyAttributes(HttpSession httpSession){
Enumeration<String> e = httpSession.getAttributeNames();
String k;
while(e.hasMoreElements()) {
k = e.nextElement();
attributes.put(k, getAttribute(k));
}
return this;
}

// TODO: Not supported for now.
@Override
public void invalidate() {
Expand Down

0 comments on commit 3c1f151

Please sign in to comment.