1 16 package org.directwebremoting.util; 17 18 import java.util.Collections ; 19 import java.util.Enumeration ; 20 import java.util.HashMap ; 21 import java.util.Map ; 22 23 import javax.servlet.ServletContext ; 24 import javax.servlet.http.HttpSession ; 25 26 31 public class FakeHttpSession implements HttpSession 32 { 33 36 public FakeHttpSession() 37 { 38 creationTime = System.currentTimeMillis(); 39 } 40 41 45 public FakeHttpSession(String id) 46 { 47 this.id = id; 48 creationTime = System.currentTimeMillis(); 49 } 50 51 54 public long getCreationTime() 55 { 56 return creationTime; 57 } 58 59 62 public String getId() 63 { 64 if (id == null) 65 { 66 log.warn("Inventing data in FakeHttpSession.getId() to remain plausible."); 67 id = "fake"; 68 } 69 70 return id; 71 } 72 73 76 public long getLastAccessedTime() 77 { 78 return creationTime; 79 } 80 81 84 public ServletContext getServletContext() 85 { 86 return null; 87 } 88 89 92 public void setMaxInactiveInterval(int maxInactiveInterval) 93 { 94 this.maxInactiveInterval = maxInactiveInterval; 95 } 96 97 100 public int getMaxInactiveInterval() 101 { 102 return maxInactiveInterval; 103 } 104 105 109 public javax.servlet.http.HttpSessionContext getSessionContext() 110 { 111 return null; 112 } 113 114 117 public Object getAttribute(String name) 118 { 119 return attributes.get(name); 120 } 121 122 125 public Object getValue(String name) 126 { 127 return attributes.get(name); 128 } 129 130 133 public Enumeration getAttributeNames() 134 { 135 return Collections.enumeration(attributes.keySet()); 136 } 137 138 141 public String [] getValueNames() 142 { 143 return (String []) attributes.keySet().toArray(new String [attributes.keySet().size()]); 144 } 145 146 149 public void setAttribute(String name, Object value) 150 { 151 attributes.put(name, value); 152 } 153 154 157 public void putValue(String name, Object value) 158 { 159 attributes.put(name, value); 160 } 161 162 165 public void removeAttribute(String name) 166 { 167 attributes.remove(name); 168 } 169 170 173 public void removeValue(String name) 174 { 175 attributes.remove(name); 176 } 177 178 181 public void invalidate() 182 { 183 } 184 185 188 public boolean isNew() 189 { 190 return true; 191 } 192 193 196 private String id = null; 197 198 201 private Map attributes = new HashMap (); 202 203 206 private long creationTime; 207 208 211 private int maxInactiveInterval = 30 * 60 * 1000; 212 213 216 private static final Logger log = Logger.getLogger(FakeHttpSession.class); 217 } 218 | Popular Tags |