use of org.atmosphere.util.FakeHttpSession in project atmosphere by Atmosphere.
the class SessionTest method basicSessionTest.
@Test
public void basicSessionTest() throws IOException, ServletException, ExecutionException, InterruptedException {
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().build();
assertNull(request.getSession(false));
assertNotNull(request.getSession());
assertNotNull(request.getSession(true));
assertNotNull(request.getSession());
request = new AtmosphereRequestImpl.Builder().session(new FakeHttpSession("-1", null, System.currentTimeMillis(), -1)).build();
assertNotNull(request.getSession());
assertNotNull(request.getSession(true));
}
use of org.atmosphere.util.FakeHttpSession in project atmosphere by Atmosphere.
the class SessionTest method basicAtmosphereResourceSessionTest.
@Test
public void basicAtmosphereResourceSessionTest() throws IOException, ServletException, ExecutionException, InterruptedException {
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().build();
AtmosphereResponse response = new AtmosphereResponseImpl.Builder().build();
AtmosphereConfig config = new AtmosphereFramework().getAtmosphereConfig();
AtmosphereResource r = config.resourcesFactory().create(new AtmosphereFramework().getAtmosphereConfig(), request, response, mock(AsyncSupport.class));
r.getAtmosphereConfig().setSupportSession(true);
assertNull(r.session(false));
assertNotNull(r.session());
assertNotNull(r.session(true));
assertNotNull(r.session());
request = new AtmosphereRequestImpl.Builder().session(new FakeHttpSession("-1", null, System.currentTimeMillis(), -1)).build();
response = new AtmosphereResponseImpl.Builder().build();
r = config.resourcesFactory().create(new AtmosphereFramework().getAtmosphereConfig(), request, response, mock(AsyncSupport.class));
r.getAtmosphereConfig().setSupportSession(true);
assertNotNull(r.session());
assertNotNull(r.session(true));
}
use of org.atmosphere.util.FakeHttpSession in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method cloneRequest.
/**
* Copy the HttpServletRequest content inside an AtmosphereRequest. By default the returned AtmosphereRequest
* is not destroyable.
*
* @param request {@link HttpServletRequest}
* @return an {@link AtmosphereRequest}
*/
public static final AtmosphereRequest cloneRequest(HttpServletRequest request, boolean loadInMemory, boolean copySession, boolean isDestroyable, boolean createSession) {
Builder b;
HttpServletRequest r;
Cookie[] cs = request.getCookies();
Set<Cookie> hs = Collections.synchronizedSet(new HashSet<>());
if (cs != null) {
Collections.addAll(hs, cs);
}
boolean isWrapped = false;
if (AtmosphereRequestImpl.class.isAssignableFrom(request.getClass())) {
b = ((AtmosphereRequestImpl) request).b;
isWrapped = true;
} else {
b = new Builder();
b.request(request);
}
HttpSession session = request.getSession(false);
if (copySession) {
session = request.getSession(createSession);
if (session != null) {
session = new FakeHttpSession(session);
} else {
session = new FakeHttpSession("", null, System.currentTimeMillis(), -1);
}
}
b.servletPath(request.getServletPath()).pathInfo(request.getPathInfo()).contextPath(request.getContextPath()).requestURI(request.getRequestURI()).requestURL(request.getRequestURL().toString()).method(request.getMethod()).serverName(request.getServerName()).serverPort(request.getServerPort()).remoteAddr(request.getRemoteAddr()).remoteHost(request.getRemoteHost()).remotePort(request.getRemotePort()).destroyable(isDestroyable).cookies(hs).session(session).principal(request.getUserPrincipal()).authType(request.getAuthType()).isSSecure(request.isSecure());
if (loadInMemory) {
String s = (String) attributeWithoutException(request, FrameworkConfig.THROW_EXCEPTION_ON_CLONED_REQUEST);
boolean throwException = Boolean.parseBoolean(s);
r = new NoOpsRequest(throwException);
if (isWrapped) {
load(b.request, b);
} else {
load(request, b);
}
b.request(r);
}
return isWrapped ? (AtmosphereRequestImpl) request : b.build();
}
use of org.atmosphere.util.FakeHttpSession in project atmosphere by Atmosphere.
the class AtmosphereRequestImpl method cloneRequest.
/**
* Copy the HttpServletRequest content inside an AtmosphereRequest. By default the returned AtmosphereRequest
* is not destroyable.
*
* @param request {@link HttpServletRequest}
* @return an {@link AtmosphereRequest}
*/
public static final AtmosphereRequest cloneRequest(HttpServletRequest request, boolean loadInMemory, boolean copySession, boolean isDestroyable, boolean createSession) {
Builder b;
HttpServletRequest r;
Cookie[] cs = request.getCookies();
Set<Cookie> hs = Collections.synchronizedSet(new HashSet());
if (cs != null) {
for (Cookie c : cs) {
hs.add(c);
}
}
boolean isWrapped = false;
if (AtmosphereRequestImpl.class.isAssignableFrom(request.getClass())) {
b = AtmosphereRequestImpl.class.cast(request).b;
isWrapped = true;
} else {
b = new Builder();
b.request(request);
}
HttpSession session = request.getSession(false);
if (copySession) {
session = request.getSession(createSession);
if (session != null) {
session = new FakeHttpSession(session);
} else {
session = new FakeHttpSession("", null, System.currentTimeMillis(), -1);
}
}
b.servletPath(request.getServletPath()).pathInfo(request.getPathInfo()).contextPath(request.getContextPath()).requestURI(request.getRequestURI()).requestURL(request.getRequestURL().toString()).method(request.getMethod()).serverName(request.getServerName()).serverPort(request.getServerPort()).remoteAddr(request.getRemoteAddr()).remoteHost(request.getRemoteHost()).remotePort(request.getRemotePort()).destroyable(isDestroyable).cookies(hs).session(session).principal(request.getUserPrincipal()).authType(request.getAuthType()).isSSecure(request.isSecure());
if (loadInMemory) {
String s = (String) attributeWithoutException(request, FrameworkConfig.THROW_EXCEPTION_ON_CLONED_REQUEST);
boolean throwException = s != null && Boolean.parseBoolean(s);
r = new NoOpsRequest(throwException);
if (isWrapped) {
load(b.request, b);
} else {
load(request, b);
}
b.request(r);
}
return isWrapped ? AtmosphereRequestImpl.class.cast(request) : b.build();
}
use of org.atmosphere.util.FakeHttpSession in project atmosphere by Atmosphere.
the class SessionTest method basicSessionTest.
@Test
public void basicSessionTest() throws IOException, ServletException, ExecutionException, InterruptedException {
AtmosphereRequest request = new AtmosphereRequestImpl.Builder().build();
assertNull(request.getSession(false));
assertNotNull(request.getSession());
assertNotNull(request.getSession(true));
assertNotNull(request.getSession());
request = new AtmosphereRequestImpl.Builder().session(new FakeHttpSession("-1", null, System.currentTimeMillis(), -1)).build();
assertNotNull(request.getSession());
assertNotNull(request.getSession(true));
}
Aggregations