1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.goetz.domino.log4j;
18
19 import org.apache.log4j.helpers.LogLog;
20
21 import lotus.domino.NotesException;
22 import lotus.domino.NotesFactory;
23 import lotus.domino.NotesThread;
24 import lotus.domino.Session;
25
26 /***
27 * This appender can be used for servlets in the Domino servlet container.
28 *
29 * @author Bernd G?tz
30 */
31 public class ServletAppender extends DominoAppender {
32
33 /***
34 * Cached session object per appender.
35 */
36 private Session session = null;
37
38
39
40
41 protected Session retrieveSession() throws NotesException {
42 if ((session != null) && (!session.isValid())) {
43
44 LogLog.debug("Session is not valid anymore, resetting it");
45 session = null;
46 }
47
48 if (session == null) {
49 LogLog.debug("Call NotesFactory.createSession()...");
50 session = NotesFactory.createSession();
51 } else {
52 LogLog.debug("Returning cached session object");
53 }
54 return session;
55 }
56
57
58
59
60 protected String getApplicationPath() {
61 return "DominoServlet";
62 }
63
64
65
66
67 protected void initAppend() throws NotesException {
68 NotesThread.sinitThread();
69 }
70
71
72
73
74 protected void releaseAppend() {
75
76
77 }
78
79
80
81
82 public String retrieveUserName() throws NotesException {
83 return retrieveSession().getUserName();
84 }
85
86
87
88
89 public void close() {
90 super.close();
91 if ((session != null)) {
92 if (session.isValid()) {
93 LogLog.debug("Session is still valid");
94 } else {
95 LogLog.debug("Session is not valid");
96 }
97 try {
98 LogLog.debug("Recycling session now");
99 session.recycle();
100 }
101 catch (NotesException e) {
102 LogLog.debug("Got Notes exception: " + e.getMessage());
103
104 }
105 } else {
106 LogLog.debug("Session is null");
107 }
108 }
109
110 }