001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * <p> 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * <p> 009 * or (per the licensee's choosing) 010 * <p> 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.access.jetty; 015 016import java.util.HashMap; 017import java.util.Iterator; 018import java.util.Map; 019 020import ch.qos.logback.access.spi.ServerAdapter; 021import org.eclipse.jetty.http.HttpField; 022import org.eclipse.jetty.server.Request; 023import org.eclipse.jetty.server.Response; 024 025/** 026 * A Jetty 9.4.x and 10.0.x specific implementation of the {@link ServerAdapter} interface. 027 * 028 * @author Sébastien Pennec 029 * @author Ceki Gulcu 030 * @author Joakim Erdfelt 031 */ 032public class JettyModernServerAdapter extends JettyServerAdapter { 033 034 035 public JettyModernServerAdapter(Request jettyRequest, Response jettyResponse) { 036 super(jettyRequest, jettyResponse); 037 } 038 039 @Override 040 public long getContentLength() { 041 return response.getHttpChannel().getBytesWritten(); 042 } 043 044 @Override 045 public int getStatusCode() { 046 return response.getCommittedMetaData().getStatus(); 047 } 048 049 @Override 050 public long getRequestTimestamp() { 051 return request.getTimeStamp(); 052 } 053 054 @Override 055 public Map<String, String> buildResponseHeaderMap() { 056 Map<String, String> responseHeaderMap = new HashMap<String, String>(); 057 Iterator<HttpField> httpFieldIter = response.getHttpFields().iterator(); 058 while (httpFieldIter.hasNext()) { 059 HttpField httpField = httpFieldIter.next(); 060 String key = httpField.getName(); 061 String value = httpField.getValue(); 062 responseHeaderMap.put(key, value); 063 } 064 return responseHeaderMap; 065 } 066 067}