You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/07/12 12:43:30 UTC
svn commit: r555576 - in
/jakarta/httpcomponents/httpcore/trunk/module-main/src:
main/java/org/apache/http/protocol/RequestDate.java
main/java/org/apache/http/protocol/ResponseDate.java
test/java/org/apache/http/protocol/TestStandardInterceptors.java
Author: rolandw
Date: Thu Jul 12 03:43:29 2007
New Revision: 555576
URL: http://svn.apache.org/viewvc?view=rev&rev=555576
Log:
added RequestDate interceptor
Added:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java (with props)
Modified:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/ResponseDate.java
jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java
Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java?view=auto&rev=555576
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java Thu Jul 12 03:43:29 2007
@@ -0,0 +1,71 @@
+/*
+ * $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
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.protocol;
+
+import java.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpRequestInterceptor;
+
+/**
+ * A request interceptor that adds a Date header.
+ * For use on the client side.
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ *
+ * @version $Revision$
+ *
+ * @since 4.0
+ */
+public class RequestDate implements HttpRequestInterceptor {
+
+ private static final HttpDateGenerator DATE_GENERATOR = new HttpDateGenerator();
+
+ public RequestDate() {
+ super();
+ }
+
+ public void process(final HttpRequest request, final HttpContext context)
+ throws HttpException, IOException {
+ if (request == null) {
+ throw new IllegalArgumentException
+ ("HTTP request may not be null.");
+ }
+ if (request instanceof HttpEntityEnclosingRequest) {
+ String httpdate = DATE_GENERATOR.getCurrentDate();
+ request.setHeader(HTTP.DATE_DIRECTIVE, httpdate);
+ }
+ }
+
+}
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/RequestDate.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/ResponseDate.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/ResponseDate.java?view=diff&rev=555576&r1=555575&r2=555576
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/ResponseDate.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/ResponseDate.java Thu Jul 12 03:43:29 2007
@@ -59,7 +59,8 @@
public void process(final HttpResponse response, final HttpContext context)
throws HttpException, IOException {
if (response == null) {
- throw new IllegalArgumentException("HTTP request may not be null");
+ throw new IllegalArgumentException
+ ("HTTP response may not be null.");
}
int status = response.getStatusLine().getStatusCode();
if (status >= HttpStatus.SC_OK) {
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java?view=diff&rev=555576&r1=555575&r2=555576
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/protocol/TestStandardInterceptors.java Thu Jul 12 03:43:29 2007
@@ -771,6 +771,41 @@
// expected
}
}
+
+ public void testRequestDateGenerated() throws Exception {
+ HttpContext context = new HttpExecutionContext(null);
+ BasicHttpRequest request =
+ new BasicHttpEntityEnclosingRequest("POST", "/");
+ //BasicHttpRequest request = new BasicHttpRequest("GET", "/");
+
+ RequestDate interceptor = new RequestDate();
+ interceptor.process(request, context);
+ Header h1 = request.getFirstHeader(HTTP.DATE_DIRECTIVE);
+ assertNotNull(h1);
+ interceptor.process(request, context);
+ Header h2 = request.getFirstHeader(HTTP.DATE_DIRECTIVE);
+ assertNotNull(h2);
+ }
+
+ public void testRequestDateNotGenerated() throws Exception {
+ HttpContext context = new HttpExecutionContext(null);
+ BasicHttpRequest request = new BasicHttpRequest("GET", "/");
+
+ RequestDate interceptor = new RequestDate();
+ interceptor.process(request, context);
+ Header h1 = request.getFirstHeader(HTTP.DATE_DIRECTIVE);
+ assertNull(h1);
+ }
+
+ public void testRequestDateInvalidInput() throws Exception {
+ RequestDate interceptor = new RequestDate();
+ try {
+ interceptor.process(null, null);
+ fail("IllegalArgumentException should have been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
public void testResponseServerGenerated() throws Exception {
HttpContext context = new HttpExecutionContext(null);