1 17 18 19 package org.apache.catalina.session; 20 21 22 import java.beans.PropertyChangeSupport ; 23 import java.io.IOException ; 24 import java.io.NotSerializableException ; 25 import java.io.ObjectInputStream ; 26 import java.io.ObjectOutputStream ; 27 import java.io.Serializable ; 28 import java.lang.reflect.Method ; 29 import java.security.AccessController ; 30 import java.security.Principal ; 31 import java.security.PrivilegedAction ; 32 import java.util.ArrayList ; 33 import java.util.Enumeration ; 34 import java.util.HashMap ; 35 import java.util.Hashtable ; 36 import java.util.Iterator ; 37 import java.util.Map ; 38 import java.util.concurrent.ConcurrentHashMap ; 39 import java.util.concurrent.atomic.AtomicInteger ; 40 41 import javax.servlet.ServletContext ; 42 import javax.servlet.http.HttpSession ; 43 import javax.servlet.http.HttpSessionActivationListener ; 44 import javax.servlet.http.HttpSessionAttributeListener ; 45 import javax.servlet.http.HttpSessionBindingEvent ; 46 import javax.servlet.http.HttpSessionBindingListener ; 47 import javax.servlet.http.HttpSessionContext ; 48 import javax.servlet.http.HttpSessionEvent ; 49 import javax.servlet.http.HttpSessionListener ; 50 51 import org.apache.catalina.Context; 52 import org.apache.catalina.Globals; 53 import org.apache.catalina.Manager; 54 import org.apache.catalina.Session; 55 import org.apache.catalina.SessionEvent; 56 import org.apache.catalina.SessionListener; 57 import org.apache.catalina.util.Enumerator; 58 import org.apache.catalina.util.StringManager; 59 60 import org.apache.catalina.security.SecurityUtil; 61 62 82 83 public class StandardSession 84 implements HttpSession , Session , Serializable { 85 86 87 protected static final boolean ACTIVITY_CHECK = 88 Globals.STRICT_SERVLET_COMPLIANCE 89 || Boolean.valueOf(System.getProperty("org.apache.catalina.session.StandardSession.ACTIVITY_CHECK", "false")).booleanValue(); 90 91 92 94 95 100 public StandardSession(Manager manager) { 101 102 super(); 103 this.manager = manager; 104 105 if (ACTIVITY_CHECK) { 107 accessCount = new AtomicInteger (); 108 } 109 110 } 111 112 113 115 116 119 protected static final String EMPTY_ARRAY[] = new String [0]; 120 121 122 126 protected static final String NOT_SERIALIZED = 127 "___NOT_SERIALIZABLE_EXCEPTION___"; 128 129 130 133 protected Map attributes = new ConcurrentHashMap (); 134 135 136 141 protected transient String authType = null; 142 143 144 152 protected transient Method containerEventMethod = null; 153 154 155 158 protected static final Class containerEventTypes[] = 159 { String .class, Object .class }; 160 161 162 166 protected long creationTime = 0L; 167 168 169 172 protected static final String [] excludedAttributes = { 173 Globals.SUBJECT_ATTR 174 }; 175 176 177 182 protected transient boolean expiring = false; 183 184 185 189 protected transient StandardSessionFacade facade = null; 190 191 192 195 protected String id = null; 196 197 198 201 protected static final String info = "StandardSession/1.0"; 202 203 204 207 protected long lastAccessedTime = creationTime; 208 209 210 213 protected transient ArrayList listeners = new ArrayList (); 214 215 216 219 protected transient Manager manager = null; 220 221 222 227 protected int maxInactiveInterval = -1; 228 229 230 233 protected boolean isNew = false; 234 235 236 239 protected boolean isValid = false; 240 241 242 247 protected transient Map notes = new Hashtable (); 248 249 250 255 protected transient Principal principal = null; 256 257 258 261 protected static StringManager sm = 262 StringManager.getManager(Constants.Package); 263 264 265 268 protected static HttpSessionContext sessionContext = null; 269 270 271 275 protected transient PropertyChangeSupport support = 276 new PropertyChangeSupport (this); 277 278 279 282 protected long thisAccessedTime = creationTime; 283 284 285 288 protected transient AtomicInteger accessCount = null; 289 290 291 293 294 298 public String getAuthType() { 299 300 return (this.authType); 301 302 } 303 304 305 311 public void setAuthType(String authType) { 312 313 String oldAuthType = this.authType; 314 this.authType = authType; 315 support.firePropertyChange("authType", oldAuthType, this.authType); 316 317 } 318 319 320 326 public void setCreationTime(long time) { 327 328 this.creationTime = time; 329 this.lastAccessedTime = time; 330 this.thisAccessedTime = time; 331 332 } 333 334 335 338 public String getId() { 339 340 return (this.id); 341 342 } 343 344 345 348 public String getIdInternal() { 349 350 return (this.id); 351 352 } 353 354 355 360 public void setId(String id) { 361 362 if ((this.id != null) && (manager != null)) 363 manager.remove(this); 364 365 this.id = id; 366 367 if (manager != null) 368 manager.add(this); 369 tellNew(); 370 } 371 372 373 377 public void tellNew() { 378 379 fireSessionEvent(Session.SESSION_CREATED_EVENT, null); 381 382 Context context = (Context ) manager.getContainer(); 384 Object listeners[] = context.getApplicationLifecycleListeners(); 385 if (listeners != null) { 386 HttpSessionEvent event = 387 new HttpSessionEvent (getSession()); 388 for (int i = 0; i < listeners.length; i++) { 389 if (!(listeners[i] instanceof HttpSessionListener )) 390 continue; 391 HttpSessionListener listener = 392 (HttpSessionListener ) listeners[i]; 393 try { 394 fireContainerEvent(context, 395 "beforeSessionCreated", 396 listener); 397 listener.sessionCreated(event); 398 fireContainerEvent(context, 399 "afterSessionCreated", 400 listener); 401 } catch (Throwable t) { 402 try { 403 fireContainerEvent(context, 404 "afterSessionCreated", 405 listener); 406 } catch (Exception e) { 407 ; 408 } 409 manager.getContainer().getLogger().error 410 (sm.getString("standardSession.sessionEvent"), t); 411 } 412 } 413 } 414 415 } 416 417 418 423 public String getInfo() { 424 425 return (info); 426 427 } 428 429 430 436 public long getLastAccessedTime() { 437 438 if (!isValidInternal()) { 439 throw new IllegalStateException 440 (sm.getString("standardSession.getLastAccessedTime.ise")); 441 } 442 443 return (this.lastAccessedTime); 444 } 445 446 450 public long getLastAccessedTimeInternal() { 451 return (this.lastAccessedTime); 452 } 453 454 457 public Manager getManager() { 458 459 return (this.manager); 460 461 } 462 463 464 469 public void setManager(Manager manager) { 470 471 this.manager = manager; 472 473 } 474 475 476 481 public int getMaxInactiveInterval() { 482 483 return (this.maxInactiveInterval); 484 485 } 486 487 488 495 public void setMaxInactiveInterval(int interval) { 496 497 this.maxInactiveInterval = interval; 498 if (isValid && interval == 0) { 499 expire(); 500 } 501 502 } 503 504 505 510 public void setNew(boolean isNew) { 511 512 this.isNew = isNew; 513 514 } 515 516 517 524 public Principal getPrincipal() { 525 526 return (this.principal); 527 528 } 529 530 531 539 public void setPrincipal(Principal principal) { 540 541 Principal oldPrincipal = this.principal; 542 this.principal = principal; 543 support.firePropertyChange("principal", oldPrincipal, this.principal); 544 545 } 546 547 548 552 public HttpSession getSession() { 553 554 if (facade == null){ 555 if (SecurityUtil.isPackageProtectionEnabled()){ 556 final StandardSession fsession = this; 557 facade = (StandardSessionFacade)AccessController.doPrivileged(new PrivilegedAction (){ 558 public Object run(){ 559 return new StandardSessionFacade(fsession); 560 } 561 }); 562 } else { 563 facade = new StandardSessionFacade(this); 564 } 565 } 566 return (facade); 567 568 } 569 570 571 574 public boolean isValid() { 575 576 if (this.expiring) { 577 return true; 578 } 579 580 if (!this.isValid) { 581 return false; 582 } 583 584 if (ACTIVITY_CHECK && accessCount.get() > 0) { 585 return true; 586 } 587 588 if (maxInactiveInterval >= 0) { 589 long timeNow = System.currentTimeMillis(); 590 int timeIdle = (int) ((timeNow - thisAccessedTime) / 1000L); 591 if (timeIdle >= maxInactiveInterval) { 592 expire(true); 593 } 594 } 595 596 return (this.isValid); 597 } 598 599 600 605 public void setValid(boolean isValid) { 606 this.isValid = isValid; 607 } 608 609 610 612 613 618 public void access() { 619 620 this.lastAccessedTime = this.thisAccessedTime; 621 this.thisAccessedTime = System.currentTimeMillis(); 622 623 if (ACTIVITY_CHECK) { 624 accessCount.incrementAndGet(); 625 } 626 627 } 628 629 630 633 public void endAccess() { 634 635 isNew = false; 636 637 if (ACTIVITY_CHECK) { 638 accessCount.decrementAndGet(); 639 } 640 641 } 642 643 644 647 public void addSessionListener(SessionListener listener) { 648 649 listeners.add(listener); 650 651 } 652 653 654 658 public void expire() { 659 660 expire(true); 661 662 } 663 664 665 672 public void expire(boolean notify) { 673 674 if (expiring) 676 return; 677 678 synchronized (this) { 679 680 if (manager == null) 681 return; 682 683 expiring = true; 684 685 Context context = (Context ) manager.getContainer(); 688 Object listeners[] = context.getApplicationLifecycleListeners(); 689 if (notify && (listeners != null)) { 690 HttpSessionEvent event = 691 new HttpSessionEvent (getSession()); 692 for (int i = 0; i < listeners.length; i++) { 693 int j = (listeners.length - 1) - i; 694 if (!(listeners[j] instanceof HttpSessionListener )) 695 continue; 696 HttpSessionListener listener = 697 (HttpSessionListener ) listeners[j]; 698 try { 699 fireContainerEvent(context, 700 "beforeSessionDestroyed", 701 listener); 702 listener.sessionDestroyed(event); 703 fireContainerEvent(context, 704 "afterSessionDestroyed", 705 listener); 706 } catch (Throwable t) { 707 try { 708 fireContainerEvent(context, 709 "afterSessionDestroyed", 710 listener); 711 } catch (Exception e) { 712 ; 713 } 714 manager.getContainer().getLogger().error 715 (sm.getString("standardSession.sessionEvent"), t); 716 } 717 } 718 } 719 if (ACTIVITY_CHECK) { 720 accessCount.set(0); 721 } 722 setValid(false); 723 724 728 long timeNow = System.currentTimeMillis(); 729 int timeAlive = (int) ((timeNow - creationTime)/1000); 730 synchronized (manager) { 731 if (timeAlive > manager.getSessionMaxAliveTime()) { 732 manager.setSessionMaxAliveTime(timeAlive); 733 } 734 int numExpired = manager.getExpiredSessions(); 735 numExpired++; 736 manager.setExpiredSessions(numExpired); 737 int average = manager.getSessionAverageAliveTime(); 738 average = ((average * (numExpired-1)) + timeAlive)/numExpired; 739 manager.setSessionAverageAliveTime(average); 740 } 741 742 manager.remove(this); 744 745 if (notify) { 747 fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null); 748 } 749 750 expiring = false; 752 753 String keys[] = keys(); 755 for (int i = 0; i < keys.length; i++) 756 removeAttributeInternal(keys[i], notify); 757 758 } 759 760 } 761 762 763 767 public void passivate() { 768 769 fireSessionEvent(Session.SESSION_PASSIVATED_EVENT, null); 771 772 HttpSessionEvent event = null; 774 String keys[] = keys(); 775 for (int i = 0; i < keys.length; i++) { 776 Object attribute = attributes.get(keys[i]); 777 if (attribute instanceof HttpSessionActivationListener ) { 778 if (event == null) 779 event = new HttpSessionEvent (getSession()); 780 try { 781 ((HttpSessionActivationListener )attribute) 782 .sessionWillPassivate(event); 783 } catch (Throwable t) { 784 manager.getContainer().getLogger().error 785 (sm.getString("standardSession.attributeEvent"), t); 786 } 787 } 788 } 789 790 } 791 792 793 797 public void activate() { 798 799 if (ACTIVITY_CHECK) { 801 accessCount = new AtomicInteger (); 802 } 803 804 fireSessionEvent(Session.SESSION_ACTIVATED_EVENT, null); 806 807 HttpSessionEvent event = null; 809 String keys[] = keys(); 810 for (int i = 0; i < keys.length; i++) { 811 Object attribute = attributes.get(keys[i]); 812 if (attribute instanceof HttpSessionActivationListener ) { 813 if (event == null) 814 event = new HttpSessionEvent (getSession()); 815 try { 816 ((HttpSessionActivationListener )attribute) 817 .sessionDidActivate(event); 818 } catch (Throwable t) { 819 manager.getContainer().getLogger().error 820 (sm.getString("standardSession.attributeEvent"), t); 821 } 822 } 823 } 824 825 } 826 827 828 834 public Object getNote(String name) { 835 836 return (notes.get(name)); 837 838 } 839 840 841 845 public Iterator getNoteNames() { 846 847 return (notes.keySet().iterator()); 848 849 } 850 851 852 856 public void recycle() { 857 858 attributes.clear(); 860 setAuthType(null); 861 creationTime = 0L; 862 expiring = false; 863 id = null; 864 lastAccessedTime = 0L; 865 maxInactiveInterval = -1; 866 accessCount = null; 867 notes.clear(); 868 setPrincipal(null); 869 isNew = false; 870 isValid = false; 871 manager = null; 872 873 } 874 875 876 882 public void removeNote(String name) { 883 884 notes.remove(name); 885 886 } 887 888 889 892 public void removeSessionListener(SessionListener listener) { 893 894 listeners.remove(listener); 895 896 } 897 898 899 906 public void setNote(String name, Object value) { 907 908 notes.put(name, value); 909 910 } 911 912 913 916 public String toString() { 917 918 StringBuffer sb = new StringBuffer (); 919 sb.append("StandardSession["); 920 sb.append(id); 921 sb.append("]"); 922 return (sb.toString()); 923 924 } 925 926 927 929 930 940 public void readObjectData(ObjectInputStream stream) 941 throws ClassNotFoundException , IOException { 942 943 readObject(stream); 944 945 } 946 947 948 957 public void writeObjectData(ObjectOutputStream stream) 958 throws IOException { 959 960 writeObject(stream); 961 962 } 963 964 965 967 968 975 public long getCreationTime() { 976 977 if (!isValidInternal()) 978 throw new IllegalStateException 979 (sm.getString("standardSession.getCreationTime.ise")); 980 981 return (this.creationTime); 982 983 } 984 985 986 989 public ServletContext getServletContext() { 990 991 if (manager == null) 992 return (null); 993 Context context = (Context ) manager.getContainer(); 994 if (context == null) 995 return (null); 996 else 997 return (context.getServletContext()); 998 999 } 1000 1001 1002 1009 public HttpSessionContext getSessionContext() { 1010 1011 if (sessionContext == null) 1012 sessionContext = new StandardSessionContext(); 1013 return (sessionContext); 1014 1015 } 1016 1017 1018 1020 1021 1030 public Object getAttribute(String name) { 1031 1032 if (!isValidInternal()) 1033 throw new IllegalStateException 1034 (sm.getString("standardSession.getAttribute.ise")); 1035 1036 return (attributes.get(name)); 1037 1038 } 1039 1040 1041 1048 public Enumeration getAttributeNames() { 1049 1050 if (!isValidInternal()) 1051 throw new IllegalStateException 1052 (sm.getString("standardSession.getAttributeNames.ise")); 1053 1054 return (new Enumerator(attributes.keySet(), true)); 1055 1056 } 1057 1058 1059 1071 public Object getValue(String name) { 1072 1073 return (getAttribute(name)); 1074 1075 } 1076 1077 1078 1088 public String [] getValueNames() { 1089 1090 if (!isValidInternal()) 1091 throw new IllegalStateException 1092 (sm.getString("standardSession.getValueNames.ise")); 1093 1094 return (keys()); 1095 1096 } 1097 1098 1099 1105 public void invalidate() { 1106 1107 if (!isValidInternal()) 1108 throw new IllegalStateException 1109 (sm.getString("standardSession.invalidate.ise")); 1110 1111 expire(); 1113 1114 } 1115 1116 1117 1127 public boolean isNew() { 1128 1129 if (!isValidInternal()) 1130 throw new IllegalStateException 1131 (sm.getString("standardSession.isNew.ise")); 1132 1133 return (this.isNew); 1134 1135 } 1136 1137 1138 1139 1157 public void putValue(String name, Object value) { 1158 1159 setAttribute(name, value); 1160 1161 } 1162 1163 1164 1178 public void removeAttribute(String name) { 1179 1180 removeAttribute(name, true); 1181 1182 } 1183 1184 1185 1201 public void removeAttribute(String name, boolean notify) { 1202 1203 if (!isValidInternal()) 1205 throw new IllegalStateException 1206 (sm.getString("standardSession.removeAttribute.ise")); 1207 1208 removeAttributeInternal(name, notify); 1209 1210 } 1211 1212 1213 1230 public void removeValue(String name) { 1231 1232 removeAttribute(name); 1233 1234 } 1235 1236 1237 1254 public void setAttribute(String name, Object value) { 1255 setAttribute(name,value,true); 1256 } 1257 1274 1275 public void setAttribute(String name, Object value, boolean notify) { 1276 1277 if (name == null) 1279 throw new IllegalArgumentException 1280 (sm.getString("standardSession.setAttribute.namenull")); 1281 1282 if (value == null) { 1284 removeAttribute(name); 1285 return; 1286 } 1287 1288 if (!isValidInternal()) 1290 throw new IllegalStateException 1291 (sm.getString("standardSession.setAttribute.ise")); 1292 if ((manager != null) && manager.getDistributable() && 1293 !(value instanceof Serializable )) 1294 throw new IllegalArgumentException 1295 (sm.getString("standardSession.setAttribute.iae")); 1296 1297 HttpSessionBindingEvent event = null; 1299 1300 if (notify && value instanceof HttpSessionBindingListener ) { 1302 Object oldValue = attributes.get(name); 1304 if (value != oldValue) { 1305 event = new HttpSessionBindingEvent (getSession(), name, value); 1306 try { 1307 ((HttpSessionBindingListener ) value).valueBound(event); 1308 } catch (Throwable t){ 1309 manager.getContainer().getLogger().error 1310 (sm.getString("standardSession.bindingEvent"), t); 1311 } 1312 } 1313 } 1314 1315 Object unbound = attributes.put(name, value); 1317 1318 if (notify && (unbound != null) && (unbound != value) && 1320 (unbound instanceof HttpSessionBindingListener )) { 1321 try { 1322 ((HttpSessionBindingListener ) unbound).valueUnbound 1323 (new HttpSessionBindingEvent (getSession(), name)); 1324 } catch (Throwable t) { 1325 manager.getContainer().getLogger().error 1326 (sm.getString("standardSession.bindingEvent"), t); 1327 } 1328 } 1329 1330 if ( !notify ) return; 1331 1332 Context context = (Context ) manager.getContainer(); 1334 Object listeners[] = context.getApplicationEventListeners(); 1335 if (listeners == null) 1336 return; 1337 for (int i = 0; i < listeners.length; i++) { 1338 if (!(listeners[i] instanceof HttpSessionAttributeListener )) 1339 continue; 1340 HttpSessionAttributeListener listener = 1341 (HttpSessionAttributeListener ) listeners[i]; 1342 try { 1343 if (unbound != null) { 1344 fireContainerEvent(context, 1345 "beforeSessionAttributeReplaced", 1346 listener); 1347 if (event == null) { 1348 event = new HttpSessionBindingEvent 1349 (getSession(), name, unbound); 1350 } 1351 listener.attributeReplaced(event); 1352 fireContainerEvent(context, 1353 "afterSessionAttributeReplaced", 1354 listener); 1355 } else { 1356 fireContainerEvent(context, 1357 "beforeSessionAttributeAdded", 1358 listener); 1359 if (event == null) { 1360 event = new HttpSessionBindingEvent 1361 (getSession(), name, value); 1362 } 1363 listener.attributeAdded(event); 1364 fireContainerEvent(context, 1365 "afterSessionAttributeAdded", 1366 listener); 1367 } 1368 } catch (Throwable t) { 1369 try { 1370 if (unbound != null) { 1371 fireContainerEvent(context, 1372 "afterSessionAttributeReplaced", 1373 listener); 1374 } else { 1375 fireContainerEvent(context, 1376 "afterSessionAttributeAdded", 1377 listener); 1378 } 1379 } catch (Exception e) { 1380 ; 1381 } 1382 manager.getContainer().getLogger().error 1383 (sm.getString("standardSession.attributeEvent"), t); 1384 } 1385 } 1386 1387 } 1388 1389 1390 1392 1393 1397 protected boolean isValidInternal() { 1398 return (this.isValid || this.expiring); 1399 } 1400 1401 1402 1414 protected void readObject(ObjectInputStream stream) 1415 throws ClassNotFoundException , IOException { 1416 1417 authType = null; creationTime = ((Long ) stream.readObject()).longValue(); 1420 lastAccessedTime = ((Long ) stream.readObject()).longValue(); 1421 maxInactiveInterval = ((Integer ) stream.readObject()).intValue(); 1422 isNew = ((Boolean ) stream.readObject()).booleanValue(); 1423 isValid = ((Boolean ) stream.readObject()).booleanValue(); 1424 thisAccessedTime = ((Long ) stream.readObject()).longValue(); 1425 principal = null; id = (String ) stream.readObject(); 1428 if (manager.getContainer().getLogger().isDebugEnabled()) 1429 manager.getContainer().getLogger().debug 1430 ("readObject() loading session " + id); 1431 1432 if (attributes == null) 1434 attributes = new Hashtable (); 1435 int n = ((Integer ) stream.readObject()).intValue(); 1436 boolean isValidSave = isValid; 1437 isValid = true; 1438 for (int i = 0; i < n; i++) { 1439 String name = (String ) stream.readObject(); 1440 Object value = (Object ) stream.readObject(); 1441 if ((value instanceof String ) && (value.equals(NOT_SERIALIZED))) 1442 continue; 1443 if (manager.getContainer().getLogger().isDebugEnabled()) 1444 manager.getContainer().getLogger().debug(" loading attribute '" + name + 1445 "' with value '" + value + "'"); 1446 attributes.put(name, value); 1447 } 1448 isValid = isValidSave; 1449 1450 if (listeners == null) { 1451 listeners = new ArrayList (); 1452 } 1453 1454 if (notes == null) { 1455 notes = new Hashtable (); 1456 } 1457 } 1458 1459 1460 1479 protected void writeObject(ObjectOutputStream stream) throws IOException { 1480 1481 stream.writeObject(new Long (creationTime)); 1483 stream.writeObject(new Long (lastAccessedTime)); 1484 stream.writeObject(new Integer (maxInactiveInterval)); 1485 stream.writeObject(new Boolean (isNew)); 1486 stream.writeObject(new Boolean (isValid)); 1487 stream.writeObject(new Long (thisAccessedTime)); 1488 stream.writeObject(id); 1489 if (manager.getContainer().getLogger().isDebugEnabled()) 1490 manager.getContainer().getLogger().debug 1491 ("writeObject() storing session " + id); 1492 1493 String keys[] = keys(); 1495 ArrayList saveNames = new ArrayList (); 1496 ArrayList saveValues = new ArrayList (); 1497 for (int i = 0; i < keys.length; i++) { 1498 Object value = attributes.get(keys[i]); 1499 if (value == null) 1500 continue; 1501 else if ( (value instanceof Serializable ) 1502 && (!exclude(keys[i]) )) { 1503 saveNames.add(keys[i]); 1504 saveValues.add(value); 1505 } else { 1506 removeAttributeInternal(keys[i], true); 1507 } 1508 } 1509 1510 int n = saveNames.size(); 1512 stream.writeObject(new Integer (n)); 1513 for (int i = 0; i < n; i++) { 1514 stream.writeObject((String ) saveNames.get(i)); 1515 try { 1516 stream.writeObject(saveValues.get(i)); 1517 if (manager.getContainer().getLogger().isDebugEnabled()) 1518 manager.getContainer().getLogger().debug 1519 (" storing attribute '" + saveNames.get(i) + 1520 "' with value '" + saveValues.get(i) + "'"); 1521 } catch (NotSerializableException e) { 1522 manager.getContainer().getLogger().warn 1523 (sm.getString("standardSession.notSerializable", 1524 saveNames.get(i), id), e); 1525 stream.writeObject(NOT_SERIALIZED); 1526 if (manager.getContainer().getLogger().isDebugEnabled()) 1527 manager.getContainer().getLogger().debug 1528 (" storing attribute '" + saveNames.get(i) + 1529 "' with value NOT_SERIALIZED"); 1530 } 1531 } 1532 1533 } 1534 1535 1536 1540 protected boolean exclude(String name){ 1541 1542 for (int i = 0; i < excludedAttributes.length; i++) { 1543 if (name.equalsIgnoreCase(excludedAttributes[i])) 1544 return true; 1545 } 1546 1547 return false; 1548 } 1549 1550 1551 1553 1554 1564 protected void fireContainerEvent(Context context, 1565 String type, Object data) 1566 throws Exception { 1567 1568 if (!"org.apache.catalina.core.StandardContext".equals 1569 (context.getClass().getName())) { 1570 return; } 1572 if (containerEventMethod == null) { 1574 containerEventMethod = 1575 context.getClass().getMethod("fireContainerEvent", 1576 containerEventTypes); 1577 } 1578 Object containerEventParams[] = new Object [2]; 1579 containerEventParams[0] = type; 1580 containerEventParams[1] = data; 1581 containerEventMethod.invoke(context, containerEventParams); 1582 1583 } 1584 1585 1586 1587 1595 public void fireSessionEvent(String type, Object data) { 1596 if (listeners.size() < 1) 1597 return; 1598 SessionEvent event = new SessionEvent (this, type, data); 1599 SessionListener list[] = new SessionListener [0]; 1600 synchronized (listeners) { 1601 list = (SessionListener []) listeners.toArray(list); 1602 } 1603 1604 for (int i = 0; i < list.length; i++){ 1605 ((SessionListener ) list[i]).sessionEvent(event); 1606 } 1607 1608 } 1609 1610 1611 1616 protected String [] keys() { 1617 1618 return ((String []) attributes.keySet().toArray(EMPTY_ARRAY)); 1619 1620 } 1621 1622 1623 1636 protected void removeAttributeInternal(String name, boolean notify) { 1637 1638 Object value = attributes.remove(name); 1640 1641 if (!notify || (value == null)) { 1643 return; 1644 } 1645 1646 HttpSessionBindingEvent event = null; 1648 if (value instanceof HttpSessionBindingListener ) { 1649 event = new HttpSessionBindingEvent (getSession(), name, value); 1650 ((HttpSessionBindingListener ) value).valueUnbound(event); 1651 } 1652 1653 Context context = (Context ) manager.getContainer(); 1655 Object listeners[] = context.getApplicationEventListeners(); 1656 if (listeners == null) 1657 return; 1658 for (int i = 0; i < listeners.length; i++) { 1659 if (!(listeners[i] instanceof HttpSessionAttributeListener )) 1660 continue; 1661 HttpSessionAttributeListener listener = 1662 (HttpSessionAttributeListener ) listeners[i]; 1663 try { 1664 fireContainerEvent(context, 1665 "beforeSessionAttributeRemoved", 1666 listener); 1667 if (event == null) { 1668 event = new HttpSessionBindingEvent 1669 (getSession(), name, value); 1670 } 1671 listener.attributeRemoved(event); 1672 fireContainerEvent(context, 1673 "afterSessionAttributeRemoved", 1674 listener); 1675 } catch (Throwable t) { 1676 try { 1677 fireContainerEvent(context, 1678 "afterSessionAttributeRemoved", 1679 listener); 1680 } catch (Exception e) { 1681 ; 1682 } 1683 manager.getContainer().getLogger().error 1684 (sm.getString("standardSession.attributeEvent"), t); 1685 } 1686 } 1687 1688 } 1689 1690 1691} 1692 1693 1694 1696 1697 1707 1708final class StandardSessionContext implements HttpSessionContext { 1709 1710 1711 protected HashMap dummy = new HashMap (); 1712 1713 1721 public Enumeration getIds() { 1722 1723 return (new Enumerator(dummy)); 1724 1725 } 1726 1727 1728 1738 public HttpSession getSession(String id) { 1739 1740 return (null); 1741 1742 } 1743 1744 1745 1746} 1747 | Popular Tags |