View Javadoc

1   /**
2    *
3    *  Licensed to the Apache Software Foundation (ASF) under one or more
4    *  contributor license agreements.  See the NOTICE file distributed with
5    *  this work for additional information regarding copyright ownership.
6    *  The ASF licenses this file to You under the Apache License, Version 2.0
7    *  (the "License"); you may not use this file except in compliance with
8    *  the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *  Unless required by applicable law or agreed to in writing, software
13   *  distributed under the License is distributed on an "AS IS" BASIS,
14   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *  See the License for the specific language governing permissions and
16   *  limitations under the License.
17   */
18  package org.apache.geronimo.jetty.requestlog;
19  
20  import org.apache.geronimo.gbean.GBeanInfo;
21  import org.apache.geronimo.gbean.GBeanInfoBuilder;
22  import org.apache.geronimo.gbean.GBeanLifecycle;
23  import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
24  import org.apache.geronimo.jetty.JettyContainer;
25  import org.apache.geronimo.system.serverinfo.ServerInfo;
26  
27  /**
28   * @version $Rev: 470597 $ $Date: 2006-11-02 15:30:55 -0800 (Thu, 02 Nov 2006) $
29   */
30  public class NCSARequestLog implements GBeanLifecycle, JettyRequestLog {
31      private final JettyContainer container;
32      private final ServerInfo serverInfo;
33      private final org.mortbay.http.NCSARequestLog requestLog;
34      private boolean preferProxiedForAddress;
35      private String filename;
36  
37      public NCSARequestLog(JettyContainer container, ServerInfo serverInfo) {
38          this.container = container;
39          this.serverInfo = serverInfo;
40          requestLog = new org.mortbay.http.NCSARequestLog();
41      }
42  
43      public void setFilename(String filename) {
44          this.filename = filename;
45      }
46  
47      public String getFilename() {
48          return filename;
49      }
50  
51      public void setLogDateFormat(String format) {
52          requestLog.setLogDateFormat(format);
53      }
54  
55      public String getLogDateFormat() {
56          return requestLog.getLogDateFormat();
57      }
58  
59      public void setLogTimeZone(String tz) {
60          requestLog.setLogTimeZone(tz);
61      }
62  
63      public String getLogTimeZone() {
64          return requestLog.getLogTimeZone();
65      }
66  
67      public int getRetainDays() {
68          return requestLog.getRetainDays();
69      }
70  
71      public void setRetainDays(int retainDays) {
72          requestLog.setRetainDays(retainDays);
73      }
74  
75      public boolean isExtended() {
76          return requestLog.isExtended();
77      }
78  
79      public void setExtended(boolean e) {
80          requestLog.setExtended(e);
81      }
82  
83      public boolean isAppend() {
84          return requestLog.isAppend();
85      }
86  
87      public void setAppend(boolean a) {
88          requestLog.setAppend(a);
89      }
90  
91      public void setIgnorePaths(String[] ignorePaths) {
92          requestLog.setIgnorePaths(ignorePaths);
93      }
94  
95      public String[] getIgnorePaths() {
96          return requestLog.getIgnorePaths();
97      }
98  
99      public void setPreferProxiedForAddress(boolean value) {
100         this.preferProxiedForAddress = value;
101         requestLog.setPreferProxiedForAddress(value);
102     }
103 
104     public boolean isPreferProxiedForAddress() {
105         return preferProxiedForAddress;
106     }
107 
108     public String getAbsoluteFilePath() {
109         return requestLog == null ? null : requestLog.getDatedFilename();
110     }
111 
112     public void doStart() throws Exception {
113         requestLog.setFilename(serverInfo.resolveServerPath(filename));
114         container.setRequestLog(requestLog);
115         requestLog.start();
116     }
117 
118     public void doStop() throws Exception {
119         requestLog.stop();
120         container.setRequestLog(null);
121     }
122 
123     public void doFail() {
124         container.setRequestLog(null);
125         requestLog.stop();
126     }
127 
128     public static final GBeanInfo GBEAN_INFO;
129 
130     static {
131         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("NCSA Request Log", NCSARequestLog.class);
132         infoFactory.addReference("JettyContainer", JettyContainer.class, NameFactory.GERONIMO_SERVICE);
133         infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE);
134 
135         infoFactory.addInterface(JettyRequestLog.class, new String[]{"filename", "logDateFormat", "logTimeZone",
136                 "retainDays", "extended", "append", "ignorePaths", "preferProxiedForAddress", });
137 
138         infoFactory.setConstructor(new String[]{"JettyContainer", "ServerInfo"});
139         GBEAN_INFO = infoFactory.getBeanInfo();
140     }
141 
142     public static GBeanInfo getGBeanInfo() {
143         return GBEAN_INFO;
144     }
145 }