001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.jetty6.requestlog; 018 019 import org.apache.geronimo.gbean.GBeanInfo; 020 import org.apache.geronimo.gbean.GBeanInfoBuilder; 021 import org.apache.geronimo.gbean.GBeanLifecycle; 022 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 023 import org.apache.geronimo.jetty6.JettyContainer; 024 import org.apache.geronimo.system.serverinfo.ServerInfo; 025 import org.mortbay.jetty.RequestLog; 026 027 /** 028 * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $ 029 */ 030 public class NCSARequestLog implements GBeanLifecycle, JettyRequestLog { 031 private final JettyContainer container; 032 private final ServerInfo serverInfo; 033 private final RequestLog requestLog; 034 private boolean preferProxiedForAddress; 035 private String filename; 036 037 public NCSARequestLog(JettyContainer container, ServerInfo serverInfo) { 038 this.container = container; 039 this.serverInfo = serverInfo; 040 requestLog = new org.mortbay.jetty.NCSARequestLog(); 041 } 042 043 public void setFilename(String filename) { 044 this.filename = filename; 045 } 046 047 public String getFilename() { 048 return filename; 049 } 050 051 public void setLogDateFormat(String format) { 052 ((org.mortbay.jetty.NCSARequestLog)requestLog).setLogDateFormat(format); 053 } 054 055 public String getLogDateFormat() { 056 return ((org.mortbay.jetty.NCSARequestLog)requestLog).getLogDateFormat(); 057 } 058 059 public void setLogTimeZone(String tz) { 060 ((org.mortbay.jetty.NCSARequestLog)requestLog).setLogTimeZone(tz); 061 } 062 063 public String getLogTimeZone() { 064 return ((org.mortbay.jetty.NCSARequestLog)requestLog).getLogTimeZone(); 065 } 066 067 public int getRetainDays() { 068 return ((org.mortbay.jetty.NCSARequestLog)requestLog).getRetainDays(); 069 } 070 071 public void setRetainDays(int retainDays) { 072 ((org.mortbay.jetty.NCSARequestLog)requestLog).setRetainDays(retainDays); 073 } 074 075 public boolean isExtended() { 076 return ((org.mortbay.jetty.NCSARequestLog)requestLog).isExtended(); 077 } 078 079 public void setExtended(boolean e) { 080 ((org.mortbay.jetty.NCSARequestLog)requestLog).setExtended(e); 081 } 082 083 public boolean isAppend() { 084 return ((org.mortbay.jetty.NCSARequestLog)requestLog).isAppend(); 085 } 086 087 public void setAppend(boolean a) { 088 ((org.mortbay.jetty.NCSARequestLog)requestLog).setAppend(a); 089 } 090 091 public void setIgnorePaths(String[] ignorePaths) { 092 ((org.mortbay.jetty.NCSARequestLog)requestLog).setIgnorePaths(ignorePaths); 093 } 094 095 public String[] getIgnorePaths() { 096 return ((org.mortbay.jetty.NCSARequestLog)requestLog).getIgnorePaths(); 097 } 098 099 public void setPreferProxiedForAddress(boolean value) { 100 this.preferProxiedForAddress = value; 101 ((org.mortbay.jetty.NCSARequestLog)requestLog).setPreferProxiedForAddress(value); 102 } 103 104 public boolean isPreferProxiedForAddress() { 105 return preferProxiedForAddress; 106 } 107 108 public String getAbsoluteFilePath() { 109 return requestLog == null ? null : ((org.mortbay.jetty.NCSARequestLog)requestLog).getDatedFilename(); 110 } 111 112 public void doStart() throws Exception { 113 ((org.mortbay.jetty.NCSARequestLog)requestLog).setFilename(serverInfo.resolveServerPath(filename)); 114 container.setRequestLog(requestLog); 115 requestLog.start(); 116 } 117 118 public void doStop() throws Exception { 119 container.setRequestLog(null); 120 } 121 122 public void doFail() { 123 container.setRequestLog(null); 124 } 125 126 public static final GBeanInfo GBEAN_INFO; 127 128 static { 129 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("NCSA Request Log", NCSARequestLog.class); 130 infoFactory.addReference("JettyContainer", JettyContainer.class, NameFactory.GERONIMO_SERVICE); 131 infoFactory.addReference("ServerInfo", ServerInfo.class, NameFactory.GERONIMO_SERVICE); 132 133 infoFactory.addInterface(JettyRequestLog.class, new String[]{"filename", "logDateFormat", "logTimeZone", 134 "retainDays", "extended", "append", "ignorePaths", "preferProxiedForAddress", }); 135 136 infoFactory.setConstructor(new String[]{"JettyContainer", "ServerInfo"}); 137 GBEAN_INFO = infoFactory.getBeanInfo(); 138 } 139 140 public static GBeanInfo getGBeanInfo() { 141 return GBEAN_INFO; 142 } 143 }