1 // 2 // ======================================================================== 3 // Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. 4 // ------------------------------------------------------------------------ 5 // All rights reserved. This program and the accompanying materials 6 // are made available under the terms of the Eclipse Public License v1.0 7 // and Apache License v2.0 which accompanies this distribution. 8 // 9 // The Eclipse Public License is available at 10 // http://www.eclipse.org/legal/epl-v10.html 11 // 12 // The Apache License v2.0 is available at 13 // http://www.opensource.org/licenses/apache2.0.php 14 // 15 // You may elect to redistribute this code under either of these licenses. 16 // ======================================================================== 17 // 18 19 package org.eclipse.jetty.server.handler; 20 21 import java.io.IOException; 22 23 import javax.servlet.DispatcherType; 24 import javax.servlet.ServletException; 25 import javax.servlet.http.HttpServletRequest; 26 import javax.servlet.http.HttpServletResponse; 27 28 import org.eclipse.jetty.server.Request; 29 import org.eclipse.jetty.server.RequestLog; 30 import org.eclipse.jetty.server.Server; 31 32 33 /** 34 * RequestLogHandler. 35 * This handler can be used to wrap an individual context for context logging. 36 * To set a {@link RequestLog} instance for the entire {@link Server}, use 37 * {@link Server#setRequestLog(RequestLog)} instead of this handler. 38 * 39 * @see Server#setRequestLog(RequestLog) 40 */ 41 public class RequestLogHandler extends HandlerWrapper 42 { 43 private RequestLog _requestLog; 44 45 /* ------------------------------------------------------------ */ 46 /* 47 * @see org.eclipse.jetty.server.server.Handler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int) 48 */ 49 @Override 50 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) 51 throws IOException, ServletException 52 { 53 if (baseRequest.getDispatcherType()==DispatcherType.REQUEST) 54 baseRequest.getHttpChannel().addRequestLog(_requestLog); 55 if (_handler!=null) 56 _handler.handle(target,baseRequest, request, response); 57 } 58 59 /* ------------------------------------------------------------ */ 60 public void setRequestLog(RequestLog requestLog) 61 { 62 updateBean(_requestLog,requestLog); 63 _requestLog=requestLog; 64 } 65 66 /* ------------------------------------------------------------ */ 67 public RequestLog getRequestLog() 68 { 69 return _requestLog; 70 } 71 72 73 }