public static byte[] serializeFrom(HttpSession session) throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { if (session != null) { Field facadeSessionField = StandardSessionFacade.class.getDeclaredField("session"); facadeSessionField.setAccessible(true); StandardSession standardSession = (StandardSession) facadeSessionField.get(session); if (standardSession != null) { // StandardSessionFacade standardSession = // (StandardSessionFacade) session; ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(bos)); oos.writeLong(standardSession.getCreationTime()); standardSession.writeObjectData(oos); oos.close(); return bos.toByteArray(); } } return null; }
public static HttpSession deserializeInto(byte[] data, HttpSession session, ClassLoader loader) throws IOException, ClassNotFoundException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { if (data != null && data.length > 0 && session != null) { Field facadeSessionField = StandardSessionFacade.class.getDeclaredField("session"); facadeSessionField.setAccessible(true); StandardSession standardSession = (StandardSession) facadeSessionField.get(session); // StandardSessionFacade standardSession = (StandardSessionFacade) // session; BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(data)); ObjectInputStream ois = new CustomObjectInputStream(bis, loader); standardSession.setCreationTime(ois.readLong()); standardSession.readObjectData(ois); } return session; }
public HttpSession getSession(boolean create) { HttpSession session = ((HttpServletRequest) request).getSession(create); if (session == null) return null; else return new StandardSessionFacade(session); }
public GlassFishAsyncServlet() throws SecurityException, NoSuchFieldException { sessionField = StandardSessionFacade.class.getDeclaredField("session"); sessionField.setAccessible(true); }
public Catalina60AsyncServlet() throws SecurityException, NoSuchFieldException { sessionField = StandardSessionFacade.class.getDeclaredField("session"); sessionField.setAccessible(true); }