### Eclipse Workspace Patch 1.0
#P httpcore
Index: src/main/java/org/apache/http/impl/metrics/MeasurableHttpMessageWrapper.java
===================================================================
--- src/main/java/org/apache/http/impl/metrics/MeasurableHttpMessageWrapper.java (revision 0)
+++ src/main/java/org/apache/http/impl/metrics/MeasurableHttpMessageWrapper.java (revision 0)
@@ -0,0 +1,144 @@
+/*
+ * $HeadURL: $
+ * $Revision: $
+ * $Date: $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.metrics;
+
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.HttpMessage;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.params.HttpParams;
+
+/**
+ * @author Zhang,Guilin
+ * @since 4.1
+ */
+public class MeasurableHttpMessageWrapper implements HttpMessage {
+
+ protected HttpMessage message;
+
+ protected long startTransferTime;
+
+ protected long endTransferTime;
+
+ public MeasurableHttpMessageWrapper(HttpMessage message) {
+ this(message, 0, 0);
+ }
+
+ public MeasurableHttpMessageWrapper(HttpMessage message, long startTransferTime, long endTransferTime) {
+ this.message = message;
+ this.startTransferTime = startTransferTime;
+ this.endTransferTime = endTransferTime;
+ }
+
+ public long getStartTransferTime() {
+ return startTransferTime;
+ }
+
+ public void setStartTransferTime(long startTransferTime) {
+ this.startTransferTime = startTransferTime;
+ }
+
+ public long getEndTransferTime() {
+ return endTransferTime;
+ }
+
+ public void setEndTransferTime(long endTransferTime) {
+ this.endTransferTime = endTransferTime;
+ }
+
+ public void addHeader(Header header) {
+ message.addHeader(header);
+ }
+
+ public void addHeader(String name, String value) {
+ message.addHeader(name, value);
+ }
+
+ public boolean containsHeader(String name) {
+ return message.containsHeader(name);
+ }
+
+ public Header[] getAllHeaders() {
+ return message.getAllHeaders();
+ }
+
+ public Header getFirstHeader(String name) {
+ return message.getFirstHeader(name);
+ }
+
+ public Header[] getHeaders(String name) {
+ return message.getHeaders(name);
+ }
+
+ public Header getLastHeader(String name) {
+ return message.getLastHeader(name);
+ }
+
+ public HttpParams getParams() {
+ return message.getParams();
+ }
+
+ public ProtocolVersion getProtocolVersion() {
+ return message.getProtocolVersion();
+ }
+
+ public HeaderIterator headerIterator() {
+ return message.headerIterator();
+ }
+
+ public HeaderIterator headerIterator(String name) {
+ return message.headerIterator(name);
+ }
+
+ public void removeHeader(Header header) {
+ message.removeHeader(header);
+ }
+
+ public void removeHeaders(String name) {
+ message.removeHeaders(name);
+ }
+
+ public void setHeader(Header header) {
+ message.setHeader(header);
+ }
+
+ public void setHeader(String name, String value) {
+ message.setHeader(name, value);
+ }
+
+ public void setHeaders(Header[] headers) {
+ message.setHeaders(headers);
+ }
+
+ public void setParams(HttpParams params) {
+ message.setParams(params);
+ }
+}
Index: src/main/java/org/apache/http/metrics/MeasurableHttpResponse.java
===================================================================
--- src/main/java/org/apache/http/metrics/MeasurableHttpResponse.java (revision 0)
+++ src/main/java/org/apache/http/metrics/MeasurableHttpResponse.java (revision 0)
@@ -0,0 +1,48 @@
+/*
+ * $HeadURL: $
+ * $Revision: 744522 $
+ * $Date: 2010-07-14 17:20:03 +0800 (Wednesday, 2010-07-14) $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.metrics;
+
+/**
+ * @author Zhang,Guilin
+ * @since 4.1
+ */
+public interface MeasurableHttpResponse {
+
+ /**
+ * @return header transfer start time in the unit of millisecond
+ */
+ long getHeaderTransferStartTime();
+
+ /**
+ * @return header transfer end time in the unit of millisecond
+ */
+ long getHeaderTransferEndTime();
+}
Index: src/main/java/org/apache/http/impl/io/HttpResponseParser.java
===================================================================
--- src/main/java/org/apache/http/impl/io/HttpResponseParser.java (revision 963946)
+++ src/main/java/org/apache/http/impl/io/HttpResponseParser.java (working copy)
@@ -100,13 +100,28 @@
this.lineBuf.clear();
int i = sessionBuffer.readLine(this.lineBuf);
+ startHeaderTransfer();
if (i == -1) {
throw new NoHttpResponseException("The target server failed to respond");
}
//create the status line from the status string
ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
StatusLine statusline = lineParser.parseStatusLine(this.lineBuf, cursor);
+ endHeaderTransfer();
return this.responseFactory.newHttpResponse(statusline, null);
}
+ /**
+ * A hook method which would be used in subclasses
+ */
+ protected void endHeaderTransfer() {
+ // do something like record time
+ }
+
+ /**
+ * A hook method which would be used in subclasses
+ */
+ protected void startHeaderTransfer() {
+ // do something like record time
+ }
}
Index: src/main/java/org/apache/http/impl/metrics/MeasurableHttpResponseParser.java
===================================================================
--- src/main/java/org/apache/http/impl/metrics/MeasurableHttpResponseParser.java (revision 0)
+++ src/main/java/org/apache/http/impl/metrics/MeasurableHttpResponseParser.java (revision 0)
@@ -0,0 +1,73 @@
+/*
+ * $HeadURL: $
+ * $Revision: $
+ * $Date: $
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * .
+ *
+ */
+package org.apache.http.impl.metrics;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpMessage;
+import org.apache.http.HttpResponseFactory;
+import org.apache.http.ParseException;
+import org.apache.http.impl.io.HttpResponseParser;
+import org.apache.http.io.SessionInputBuffer;
+import org.apache.http.message.LineParser;
+import org.apache.http.params.HttpParams;
+
+/**
+ * @author Zhang,Guilin
+ * @since 4.1
+ */
+public class MeasurableHttpResponseParser extends HttpResponseParser {
+
+ protected long headerTransferStart;
+
+ protected long headerTransferEnd;
+
+ public MeasurableHttpResponseParser(SessionInputBuffer buffer,
+ LineParser parser, HttpResponseFactory responseFactory,
+ HttpParams params) {
+ super(buffer, parser, responseFactory, params);
+ }
+
+ protected void startHeaderTransfer() {
+ headerTransferStart = System.currentTimeMillis();
+ }
+
+ protected void endHeaderTransfer() {
+ headerTransferEnd = System.currentTimeMillis();
+ }
+
+ protected HttpMessage parseHead(final SessionInputBuffer sessionBuffer)
+ throws IOException, HttpException, ParseException {
+ HttpMessage response = super.parseHead(sessionBuffer);
+ return new MeasurableHttpMessageWrapper(response, headerTransferStart, headerTransferEnd);
+ }
+}