Return-Path: Delivered-To: apmail-incubator-abdera-commits-archive@locus.apache.org Received: (qmail 23714 invoked from network); 18 Oct 2007 23:17:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Oct 2007 23:17:22 -0000 Received: (qmail 75160 invoked by uid 500); 18 Oct 2007 23:17:09 -0000 Delivered-To: apmail-incubator-abdera-commits-archive@incubator.apache.org Received: (qmail 75143 invoked by uid 500); 18 Oct 2007 23:17:09 -0000 Mailing-List: contact abdera-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: abdera-dev@incubator.apache.org Delivered-To: mailing list abdera-commits@incubator.apache.org Received: (qmail 75134 invoked by uid 99); 18 Oct 2007 23:17:09 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Oct 2007 16:17:09 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 18 Oct 2007 23:17:20 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 459FA1A9832; Thu, 18 Oct 2007 16:16:30 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r586171 - in /incubator/abdera/java/trunk: client/src/main/java/org/apache/abdera/protocol/client/ client/src/main/java/org/apache/abdera/protocol/client/cache/ client/src/main/java/org/apache/abdera/protocol/client/util/ protocol/src/main/... Date: Thu, 18 Oct 2007 23:16:27 -0000 To: abdera-commits@incubator.apache.org From: jmsnell@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071018231630.459FA1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jmsnell Date: Thu Oct 18 16:16:26 2007 New Revision: 586171 URL: http://svn.apache.org/viewvc?rev=586171&view=rev Log: Protocol API refactorings, simplifications, corrections, etc. In order to help ensure that the API is consistent across the request and responses objects, a new top level base interface called Message is provided. Response and Request extend from Message. Common code is moved into an AbstractMessage class. A couple of Lists are replaced with arrays in order to enforce the fact that the listings are actually immutable. A couple of error refactorings are made to simplify error handling. Added: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Message.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractMessage.java Removed: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestException.java Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheBase.java incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCachedResponse.java incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MethodHelper.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/ItemManager.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Request.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Resolver.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Response.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractRequest.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractResponse.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java Thu Oct 18 16:16:26 2007 @@ -30,6 +30,7 @@ import org.apache.abdera.Abdera; import org.apache.abdera.model.Base; import org.apache.abdera.model.Document; +import org.apache.abdera.model.Element; import org.apache.abdera.protocol.Response.ResponseType; import org.apache.abdera.protocol.client.cache.Cache; import org.apache.abdera.protocol.client.cache.CacheDisposition; @@ -39,6 +40,8 @@ import org.apache.abdera.protocol.client.util.BaseRequestEntity; import org.apache.abdera.protocol.client.util.MethodHelper; import org.apache.abdera.protocol.client.util.SimpleSSLProtocolSocketFactory; +import org.apache.abdera.protocol.error.Error; +import org.apache.abdera.protocol.error.ProtocolException; import org.apache.abdera.protocol.util.CacheControlUtil; import org.apache.abdera.util.ServiceUtil; import org.apache.abdera.util.Version; @@ -424,8 +427,30 @@ if (response == null) return; ResponseType type = response.getType(); if ((type.equals(ResponseType.CLIENT_ERROR) && options.is4xxRequestException()) || - (type.equals(ResponseType.SERVER_ERROR) && options.is5xxRequestException())) - throw new RequestException(response); + (type.equals(ResponseType.SERVER_ERROR) && options.is5xxRequestException())) { + try { + Document doc = response.getDocument(); + org.apache.abdera.protocol.error.Error error = null; + if (doc != null) { + Element root = doc.getRoot(); + if (root instanceof Error) { + error = (Error) root; + } + } + if (error == null) + error = org.apache.abdera.protocol.error.Error.create( + abdera, + response.getStatus(), + response.getStatusText()); + error.throwException(); + } catch (ProtocolException pe) { + throw pe; + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new RuntimeException(e); + } + } } public RequestOptions getDefaultRequestOptions() { Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/ClientResponse.java Thu Oct 18 16:16:26 2007 @@ -95,7 +95,7 @@ Date getServerDate(); /** - * Return the character set encoding specified in the ContentType header, if ant + * Return the character set encoding specified in the ContentType header, if any */ String getCharacterEncoding(); Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsResponse.java Thu Oct 18 16:16:26 2007 @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -86,36 +87,34 @@ */ public String getHeader(String header) { Header h = method.getResponseHeader(header); - if (h != null) - return h.getValue(); - else return null; + return h != null ? h.getValue() : null; } /** * Return the values of the named HTTP header */ - public List getHeaders(String header) { + public Object[] getHeaders(String header) { Header[] headers = method.getResponseHeaders(header); List values = new ArrayList(); for (Header h : headers) { values.add(h.getValue()); } - return java.util.Collections.unmodifiableList(values); + return values.toArray(new Object[values.size()]); } /** * Return all of the HTTP headers */ - public Map> getHeaders() { + public Map getHeaders() { Header[] headers = method.getResponseHeaders(); - Map> map = new HashMap>(); + Map map = new HashMap(); for (Header header : headers) { - List values = map.get(header.getName()); - if (values == null) { - values = new ArrayList(); - map.put(header.getName(),values); - } - values.add(header.getValue()); + Object[] values = map.get(header.getName()); + List list = values == null ? + new ArrayList() : + Arrays.asList(values); + list.add(header.getValue()); + map.put(header.getName(), list.toArray(new Object[list.size()])); } return java.util.Collections.unmodifiableMap(map); } @@ -173,5 +172,5 @@ throw new ClientException(e); // server likely returned a bad date format } } - + } Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/RequestOptions.java Thu Oct 18 16:16:26 2007 @@ -49,11 +49,9 @@ private boolean requestException5xx = false; private boolean useExpectContinue = true; - private final Map> headers; + private final Map headers = new HashMap(); - public RequestOptions() { - headers = new HashMap>(); - } + public RequestOptions() {} public RequestOptions(Date ifModifiedSince) { this(); @@ -87,7 +85,7 @@ setNoCache(no_cache); } - private Map> getHeaders() { + private Map getHeaders() { return headers; } @@ -124,6 +122,10 @@ setHeader("Content-Type", value); } + public void setContentLocation(String iri) { + setHeader("Content-Location", iri); + } + /** * Set the value of the HTTP Content-Type header */ @@ -153,8 +155,7 @@ for (int n = 0; n < values.length; n++) { values[n] = EncodingUtil.encode(values[n], charset); } - List list = Arrays.asList(new String[] {combine(values)}); - getHeaders().put(header, list); + getHeaders().put(header, new String[] {combine(values)}); } else { removeHeaders(header); } @@ -175,8 +176,7 @@ */ public void setHeader(String header, String... values) { if (values != null && values.length > 0) { - List list = Arrays.asList(new String[] {combine(values)}); - getHeaders().put(header, list); + getHeaders().put(header, new String[] {combine(values)}); } else { removeHeaders(header); } @@ -209,7 +209,7 @@ for (int n = 0; n < values.length; n++) { values[n] = EncodingUtil.encode(values[n], charset); } - List list = getHeaders().get(header); + List list = Arrays.asList(getHeaders().get(header)); String value = combine(values); if (list != null) { if (!list.contains(value)) @@ -232,7 +232,7 @@ */ public void addHeader(String header, String... values) { if (values == null || values.length == 0) return; - List list = getHeaders().get(header); + List list = Arrays.asList(getHeaders().get(header)); String value = combine(values); if (list != null) { if (!list.contains(value)) @@ -254,14 +254,14 @@ * Returns the text value of the specified header */ public String getHeader(String header) { - List list = getHeaders().get(header); - return (list != null) ? list.get(0) : null; + String[] list = getHeaders().get(header); + return (list != null && list.length > 0) ? list[0] : null; } /** * Return a listing of text values for the specified header */ - public List getHeaders(String header) { + public String[] getHeaders(String header) { return getHeaders().get(header); } Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheBase.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheBase.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheBase.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/CacheBase.java Thu Oct 18 16:16:26 2007 @@ -18,11 +18,10 @@ package org.apache.abdera.protocol.client.cache; import java.io.IOException; -import java.util.List; import org.apache.abdera.Abdera; -import org.apache.abdera.protocol.client.RequestOptions; import org.apache.abdera.protocol.client.ClientResponse; +import org.apache.abdera.protocol.client.RequestOptions; import org.apache.abdera.protocol.util.CacheControlUtil; public abstract class CacheBase @@ -44,9 +43,10 @@ CacheKey key = getCacheKey(uri, options); CachedResponse response = get(key); if (response != null && options != null) { - List pragma = options.getHeaders("Pragma"); + Object[] pragma = options.getHeaders("Pragma"); if (pragma != null) { - for (String s: pragma) { + for (Object o: pragma) { + String s = (String)o; if (s.equalsIgnoreCase("no-cache")) { return CacheDisposition.TRANSPARENT; } Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCachedResponse.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCachedResponse.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCachedResponse.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/cache/InMemoryCachedResponse.java Thu Oct 18 16:16:26 2007 @@ -23,7 +23,6 @@ import java.io.InputStream; import java.util.Date; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.apache.abdera.Abdera; @@ -42,7 +41,7 @@ private int status = 0; private String status_text = null; private String uri = null; - private Map> headers = null; + private Map headers = null; private byte[] buf = null; public InMemoryCachedResponse( @@ -80,9 +79,9 @@ this.buf = out.toByteArray(); } - public Map> getHeaders() { + public Map getHeaders() { if (headers == null) - headers = new HashMap>(); + headers = new HashMap(); return headers; } @@ -91,15 +90,15 @@ } public String getHeader(String header) { - List values = getHeaders().get(header); - return (values != null) ? (String)values.get(0) : null; + Object[] values = getHeaders().get(header); + return (values != null && values.length > 0) ? (String)values[0] : null; } public String[] getHeaderNames() { return getHeaders().keySet().toArray(new String[getHeaders().size()]); } - public List getHeaders(String header) { + public Object[] getHeaders(String header) { return getHeaders().get(header); } Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MethodHelper.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MethodHelper.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MethodHelper.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MethodHelper.java Thu Oct 18 16:16:26 2007 @@ -18,11 +18,10 @@ package org.apache.abdera.protocol.client.util; import java.util.HashMap; -import java.util.List; import java.util.Map; -import org.apache.abdera.protocol.client.RequestOptions; import org.apache.abdera.protocol.client.ClientResponse; +import org.apache.abdera.protocol.client.RequestOptions; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.URI; import org.apache.commons.httpclient.methods.DeleteMethod; @@ -61,12 +60,12 @@ } } - public static Map> getCacheableHeaders(ClientResponse response) { - Map> map = new HashMap>(); + public static Map getCacheableHeaders(ClientResponse response) { + Map map = new HashMap(); String[] headers = response.getHeaderNames(); for (String header : headers) { if (MethodHelper.isCacheableHeader(header, response)) { - List list = response.getHeaders(header); + Object[] list = response.getHeaders(header); map.put(header, list); } } @@ -162,9 +161,9 @@ private static void initHeaders(RequestOptions options, HttpMethod method) { String[] headers = options.getHeaderNames(); for (String header : headers) { - List values = options.getHeaders(header); - for (String value : values) { - method.addRequestHeader(header, value); + Object[] values = options.getHeaders(header); + for (Object value : values) { + method.addRequestHeader(header, value.toString()); } } String cc = options.getCacheControl(); Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/ItemManager.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/ItemManager.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/ItemManager.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/ItemManager.java Thu Oct 18 16:16:26 2007 @@ -17,10 +17,20 @@ */ package org.apache.abdera.protocol; +/** + * ItemManager is an internal utility class that provides a simple get/release + * interface. It is used primarily to control access to pooled resources. + */ public interface ItemManager { + /** + * Get an item based on the specified request + */ T get(Request request); + /** + * Release an item + */ void release(T item); } Added: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Message.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Message.java?rev=586171&view=auto ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Message.java (added) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Message.java Thu Oct 18 16:16:26 2007 @@ -0,0 +1,108 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. 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. For additional information regarding +* copyright in this work, please see the NOTICE file in the top level +* directory of this distribution. +*/ +package org.apache.abdera.protocol; + +import java.util.Date; + +import javax.activation.MimeType; + +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.protocol.util.ProtocolConstants; + +/** + * A protocol message. This is used as the basis for both request and response + * objects in order to provide a consistent interface. + */ +public interface Message extends ProtocolConstants { + + /** + * Get the value of the specified header + */ + String getHeader(String name); + + /** + * Get the decoded value of a RFC 2047 header + */ + String getDecodedHeader(String name); + + /** + * Return multiple values for the specified header + */ + Object[] getHeaders(String name); + + /** + * Return multiple decoded values for the specified header + */ + String[] getDecodedHeaders(String name); + + /** + * Return a listing of header names + */ + String[] getHeaderNames(); + + /** + * Return the value of the Cache-Control header + */ + String getCacheControl(); + + /** + * Return the value of the Slug header + */ + String getSlug(); + + /** + * Return the value of the Content-Type header + */ + MimeType getContentType(); + + /** + * Return the value of the Content-Location header + */ + IRI getContentLocation(); + + /** + * Return the value of the Content-Language header + */ + String getContentLanguage(); + + /** + * Return the value of a Date header + */ + Date getDateHeader(String name); + + /** + * Return the maximum-age as specified by the Cache-Control header + */ + long getMaxAge(); + + /** + * Return true if the Cache-Control header contains no-cache + */ + boolean isNoCache(); + + /** + * Return true if the Cache-Control header contains no-store + */ + boolean isNoStore(); + + /** + * Return true if the Cache-Control header contains no-transform + */ + boolean isNoTransform(); + +} Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Request.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Request.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Request.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Request.java Thu Oct 18 16:16:26 2007 @@ -18,63 +18,73 @@ package org.apache.abdera.protocol; import java.util.Date; -import java.util.List; -import javax.activation.MimeType; - -import org.apache.abdera.protocol.util.ProtocolConstants; import org.apache.abdera.util.EntityTag; -public interface Request extends ProtocolConstants { - String getHeader(String name); - - String getDecodedHeader(String name); - - List getHeaders(String name); - - List getDecodedHeaders(String name); - - String[] getHeaderNames(); - +/** + * A protocol request. This is used as a base for both server and client requests + */ +public interface Request extends Message { + + /** + * Get the value of the Accept header + */ String getAccept(); - + + /** + * Get the value of the Accept-Charset header + */ String getAcceptCharset(); - + + /** + * Get the value of the Accept-Encoding header + */ String getAcceptEncoding(); - + + /** + * Get the value of the Accept-Language header + */ String getAcceptLanguage(); - + + /** + * Get the value of the Authorization header + */ String getAuthorization(); - - String getCacheControl(); - - String getSlug(); - - MimeType getContentType(); - - Date getDateHeader(String name); - + + /** + * Get a listing of Etags from the If-Match header + */ EntityTag[] getIfMatch(); - + + /** + * Get the value of the If-Modified-Since header + */ Date getIfModifiedSince(); - + + /** + * Get a listing of ETags from the If-None-Match header + */ EntityTag[] getIfNoneMatch(); - + + /** + * Get the value of the If-Unmodified-Since header + */ Date getIfUnmodifiedSince(); - - long getMaxAge(); - + + /** + * Get the max-stale value from the Cache-Control header + */ long getMaxStale(); - + + /** + * Get the min-fresh value from the Cache-Control header + */ long getMinFresh(); - - boolean isNoCache(); - - boolean isNoStore(); - - boolean isNoTransform(); - + + /** + * True if the only-if-cached directive is set in the Cache-Control header + */ boolean isOnlyIfCached(); } Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Resolver.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Resolver.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Resolver.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Resolver.java Thu Oct 18 16:16:26 2007 @@ -17,6 +17,11 @@ */ package org.apache.abdera.protocol; +/** + * The Resolver interface is a utility class used to resolve objects based on + * a request. It is used internally by Abdera as the basis for Target and Subject + * resolvers. + */ public interface Resolver { T resolve(Request request); Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Response.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Response.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Response.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/Response.java Thu Oct 18 16:16:26 2007 @@ -18,17 +18,12 @@ package org.apache.abdera.protocol; import java.util.Date; -import java.util.List; -import java.util.Map; -import javax.activation.MimeType; - -import org.apache.abdera.protocol.util.ProtocolConstants; -import org.apache.abdera.util.EntityTag; import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.util.EntityTag; public interface Response - extends ProtocolConstants { + extends Message { public static enum ResponseType { SUCCESS, REDIRECTION, CLIENT_ERROR, SERVER_ERROR, UNKNOWN; @@ -43,58 +38,30 @@ } - public EntityTag getEntityTag(); + EntityTag getEntityTag(); - public ResponseType getType(); - - public int getStatus(); - - public String getStatusText(); - - public Date getLastModified(); - - public String getContentLanguage(); - - public IRI getContentLocation(); - - public long getContentLength(); + ResponseType getType(); - public MimeType getContentType(); + int getStatus(); - public String getAllow(); + String getStatusText(); - public IRI getLocation(); + Date getLastModified(); - public String getSlug(); + long getContentLength(); - public Date getDateHeader(String name); + String getAllow(); - public IRI getUriHeader(String name); - - public String getHeader(String name); - - public List getHeaders(String name); - - public Map> getHeaders(); - - public String[] getHeaderNames(); + IRI getLocation(); boolean isPrivate(); boolean isPublic(); - boolean isNoCache(); - - boolean isNoStore(); - - boolean isNoTransform(); - boolean isMustRevalidate(); boolean isProxyRevalidate(); - long getMaxAge(); - long getSMaxAge(); long getAge(); @@ -105,7 +72,4 @@ String[] getPrivateHeaders(); - String getCacheControl(); - - String getDecodedHeader(String header); } Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/Error.java Thu Oct 18 16:16:26 2007 @@ -26,7 +26,8 @@ import org.apache.abdera.model.ExtensibleElementWrapper; /** - * Abdera protocol error element + * Abdera protocol error element. The Abdera error document provides a + * simple structure for reporting errors back to Abdera clients. */ public class Error extends ExtensibleElementWrapper { @@ -44,11 +45,19 @@ super(factory, qname); } + /** + * The code should typically match the HTTP status code; however, certain + * application scenarios may require the use of a different code + */ public int getCode() { String code = getSimpleExtension(CODE); return code != null ? Integer.parseInt(code) : -1; } - + + /** + * The code should typically match the HTTP status code; however, certain + * application scenarios may require the use of a different code + */ public void setCode(int code) { if (code > -1) { Element element = getExtension(CODE); @@ -63,10 +72,16 @@ } } + /** + * Human-readable, language-sensitive description of the error + */ public String getMessage() { return getSimpleExtension(MESSAGE); } - + + /** + * Human-readable, language-sensitive description of the error + */ public void setMessage(String message) { if (message != null) { Element element = getExtension(MESSAGE); @@ -81,10 +96,17 @@ } } + /** + * Will throw a ProtocolException that wraps this element. This is + * useful on the client side to surface error responses + */ public void throwException() { throw new ProtocolException(this); } + /** + * Create a new Error object + */ public static Error create(Abdera abdera, int code, String message) { Document doc = abdera.getFactory().newDocument(); Error error = abdera.getFactory().newElement(ERROR,doc); Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/error/ProtocolException.java Thu Oct 18 16:16:26 2007 @@ -23,7 +23,7 @@ extends RuntimeException { private static final long serialVersionUID = 1017447143200419489L; - protected final Error error; + private final Error error; public ProtocolException(Error error) { super(error.getCode() + "::" + error.getMessage()); @@ -38,25 +38,34 @@ public Error getError() { return error; } - - @Override + + @Override public int hashCode() { - final int PRIME = 31; + final int prime = 31; int result = 1; - result = PRIME * result + ((error == null) ? 0 : error.hashCode()); + String message = error != null ? error.getMessage() : null; + int code = error != null ? error.getCode() : 0; + result = prime * result + ((message == null) ? 0 : message.hashCode()); + result = prime * result + code; return result; } - @Override + @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; final ProtocolException other = (ProtocolException) obj; - if (error == null) { - if (other.error != null) return false; - } else if (!error.equals(other.error)) return false; + String message = error != null ? error.getMessage() : null; + int code = error != null ? error.getCode() : 0; + String omessage = other.error != null ? other.error.getMessage() : null; + int ocode = other.error != null ? other.error.getCode() : 0; + if (message == null) { + if (omessage != null) return false; + } else if (!message.equals(omessage)) return false; + if (code != ocode) return false; return true; } + } Added: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractMessage.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractMessage.java?rev=586171&view=auto ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractMessage.java (added) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractMessage.java Thu Oct 18 16:16:26 2007 @@ -0,0 +1,101 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. 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. For additional information regarding +* copyright in this work, please see the NOTICE file in the top level +* directory of this distribution. +*/ +package org.apache.abdera.protocol.util; + +import javax.activation.MimeType; + +import org.apache.abdera.i18n.iri.Escaping; +import org.apache.abdera.i18n.iri.IRI; +import org.apache.abdera.protocol.Message; + +/** + * Root impl for Message interface impls. This is provided solely as a way of + * keeping the interface and impl's consistent across the Request and Response + * objects. + */ +public abstract class AbstractMessage + implements Message { + + protected int flags = 0; + protected long max_age = -1; + + + public String getCacheControl() { + return getHeader("Cache-Control"); + } + + public String getContentLanguage() { + return getHeader("Content-Language"); + } + + public IRI getContentLocation() { + String value = getHeader("Content-Location"); + return (value != null) ? new IRI(value) : null; + } + + public MimeType getContentType() { + try { + String value = getHeader("Content-Type"); + return (value != null) ? new MimeType(value) : null; + } catch (javax.activation.MimeTypeParseException e) { + throw new org.apache.abdera.util.MimeTypeParseException(e); + } + } + + public String getDecodedHeader(String header) { + return Escaping.decode(EncodingUtil.decode(getHeader(header))); + } + + public String[] getDecodedHeaders(String header) { + Object[] headers = getHeaders(header); + for (int n = 0; n < headers.length; n++) { + headers[n] = Escaping.decode(EncodingUtil.decode(headers[n].toString())); + } + return (String[])headers; + } + + public String getSlug() { + return getDecodedHeader("Slug"); + } + + + protected boolean check(int flag) { + return (flags & flag) == flag; + } + + protected void toggle(boolean val, int flag) { + if (val) flags |= flag; + else flags &= ~flag; + } + + public boolean isNoCache() { + return check(NOCACHE); + } + + public boolean isNoStore() { + return check(NOSTORE); + } + + public boolean isNoTransform() { + return check(NOTRANSFORM); + } + + public long getMaxAge() { + return max_age; + } +} Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractRequest.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractRequest.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractRequest.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractRequest.java Thu Oct 18 16:16:26 2007 @@ -18,18 +18,14 @@ package org.apache.abdera.protocol.util; import java.util.Date; -import java.util.List; -import javax.activation.MimeType; - -import org.apache.abdera.i18n.iri.Escaping; import org.apache.abdera.protocol.Request; import org.apache.abdera.util.EntityTag; -public abstract class AbstractRequest implements Request { +public abstract class AbstractRequest + extends AbstractMessage + implements Request { - protected int flags = 0; - protected long max_age = -1; protected long max_stale = -1; protected long min_fresh = -1; @@ -53,23 +49,6 @@ return getHeader("Authorization"); } - public String getCacheControl() { - return getHeader("Cache-Control"); - } - - public String getSlug() { - return Escaping.decode(EncodingUtil.decode(getHeader("Slug"))); - } - - public MimeType getContentType() { - try { - String value = getHeader("Content-Type"); - return (value != null) ? new MimeType(value) : null; - } catch (javax.activation.MimeTypeParseException e) { - throw new org.apache.abdera.util.MimeTypeParseException(e); - } - } - public EntityTag[] getIfMatch() { return EntityTag.parseTags(getHeader("If-Match")); } @@ -86,10 +65,6 @@ return getDateHeader("If-Unmodified-Since"); } - public long getMaxAge() { - return max_age; - } - public long getMaxStale() { return max_stale; } @@ -98,18 +73,6 @@ return min_fresh; } - public boolean isNoCache() { - return check(NOCACHE); - } - - public boolean isNoStore() { - return check(NOSTORE); - } - - public boolean isNoTransform() { - return check(NOTRANSFORM); - } - public boolean isOnlyIfCached() { return check(ONLYIFCACHED); } @@ -126,15 +89,6 @@ this.min_fresh = min_fresh; } - private boolean check(int flag) { - return (flags & flag) == flag; - } - - private void toggle(boolean val, int flag) { - if (val) flags |= flag; - else flags &= ~flag; - } - public void setNoCache(boolean val) { toggle(val, NOCACHE); } @@ -151,16 +105,4 @@ toggle(val, ONLYIFCACHED); } - public String getDecodedHeader(String header) { - return EncodingUtil.decode(getHeader(header)); - } - - public List getDecodedHeaders(String header) { - List headers = getHeaders(header); - String[] vals = new String[headers.size()]; - for (int n = 0; n < headers.size(); n++) { - vals[n] = EncodingUtil.decode(headers.get(n)); - } - return java.util.Arrays.asList(vals); - } } Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractResponse.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractResponse.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractResponse.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/AbstractResponse.java Thu Oct 18 16:16:26 2007 @@ -19,17 +19,14 @@ import java.util.Date; -import javax.activation.MimeType; - +import org.apache.abdera.i18n.iri.IRI; import org.apache.abdera.protocol.Response; import org.apache.abdera.util.EntityTag; -import org.apache.abdera.i18n.iri.Escaping; -import org.apache.abdera.i18n.iri.IRI; -public abstract class AbstractResponse +public abstract class AbstractResponse + extends AbstractMessage implements Response { - protected int flags = 0; protected String[] nocache_headers = null; protected String[] private_headers = null; protected long max_age = -1; @@ -48,14 +45,6 @@ return getHeader("Allow"); } - public String getCacheControl() { - return getHeader("Cache-Control"); - } - - public String getContentLanguage() { - return getHeader("Content-Language"); - } - public long getContentLength() { String value = getHeader("Content-Length"); try { @@ -65,23 +54,6 @@ } } - public IRI getContentLocation() { - return getUriHeader("Content-Location"); - } - - public String getSlug() { - return getDecodedHeader("Slug"); - } - - public MimeType getContentType() { - try { - String value = getHeader("Content-Type"); - return (value != null) ? new MimeType(value) : null; - } catch (javax.activation.MimeTypeParseException e) { - throw new org.apache.abdera.util.MimeTypeParseException(e); - } - } - public EntityTag getEntityTag() { String etag = getHeader("ETag"); return (etag != null) ? EntityTag.parse(getHeader("ETag")) : null; @@ -96,11 +68,8 @@ } public IRI getLocation() { - return getUriHeader("Location"); - } - - public long getMaxAge() { - return max_age; + String l = getHeader("Location"); + return l != null ? new IRI(l) : null; } public String[] getNoCacheHeaders() { @@ -119,27 +88,10 @@ return ResponseType.select(getStatus()); } - public IRI getUriHeader(String name) { - String value = getHeader(name); - return (value != null) ? new IRI(value) : null; - } - public boolean isMustRevalidate() { return check(REVALIDATE); } - public boolean isNoCache() { - return check(NOCACHE); - } - - public boolean isNoStore() { - return check(NOSTORE); - } - - public boolean isNoTransform() { - return check(NOTRANSFORM); - } - public boolean isPrivate() { return check(PRIVATE); } @@ -193,17 +145,4 @@ this.nocache_headers = headers; } - private boolean check(int flag) { - return (flags & flag) == flag; - } - - private void toggle(boolean val, int flag) { - if (val) flags |= flag; - else flags &= ~flag; - } - - public String getDecodedHeader(String header) { - return Escaping.decode(EncodingUtil.decode(getHeader(header))); - } - } Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/CacheControlUtil.java Thu Oct 18 16:16:26 2007 @@ -23,8 +23,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Provides parsing and properly handling of the HTTP Cache-Control header. + */ public class CacheControlUtil { + /** + * Idempotent methods are handled differently in caches than other methods + */ public static boolean isIdempotent(String method) { return (method.equalsIgnoreCase("GET") || method.equalsIgnoreCase("HEAD") || @@ -40,6 +46,9 @@ buf.append(value); } + /** + * Construct the Cache-Control header from info in the request object + */ public static String buildCacheControl(AbstractRequest request) { StringBuffer buf = new StringBuffer(); if (request.isNoCache()) append(buf,"no-cache"); @@ -52,6 +61,9 @@ return buf.toString(); } + /** + * Parse the Cache-Control header + */ public static void parseCacheControl( String cc, AbstractRequest request) { @@ -77,6 +89,9 @@ } } + /** + * Parse the Cache-Control header + */ public static void parseCacheControl( String cc, AbstractResponse response) { @@ -114,7 +129,9 @@ } } - + /** + * Cache Control Directives + */ public enum Directive { MAXAGE, MAXSTALE, MINFRESH, NOCACHE, NOSTORE, NOTRANSFORM, ONLYIFCACHED, MUSTREVALIDATE, PRIVATE, PROXYREVALIDATE, PUBLIC, SMAXAGE, UNKNOWN; @@ -127,7 +144,10 @@ return UNKNOWN; } } - + + /** + * Parser for the Cache-Control header + */ public static class CacheControlParser implements Iterable { Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java (original) +++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/PoolManager.java Thu Oct 18 16:16:26 2007 @@ -25,7 +25,11 @@ * Implements a simple pool manager. * * By default, an upper limit to the pool is set at 25 entries. - * New items can always be created. + * New items can always be created, but if more than 25 entries + * are released back to the pool, the extras are discarded. + * Items added to the stack should never maintain any kind of + * state as it is entirely possible that different threads will + * be grabbing items from the pool */ public abstract class PoolManager implements ItemManager { Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java (original) +++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractRequestHandler.java Thu Oct 18 16:16:26 2007 @@ -22,8 +22,6 @@ import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.util.Date; -import java.util.List; -import java.util.Map; import javax.activation.MimeType; import javax.servlet.ServletException; @@ -117,20 +115,17 @@ MimeType ct = context.getContentType(); if (ct != null) response.setContentType(ct.toString()); } catch (Exception e) {} - Map> headers = context.getHeaders(); - if (headers != null) { - for (Map.Entry> entry : headers.entrySet()) { - List values = entry.getValue(); - if (values == null) - continue; - for (Object value : values) { - if (value instanceof Date) - response.setDateHeader(entry.getKey(), ((Date)value).getTime()); - else - response.setHeader(entry.getKey(), value.toString()); - } + String[] names = context.getHeaderNames(); + for (String name : names) { + Object[] headers = context.getHeaders(name); + for (Object value : headers) { + if (value instanceof Date) + response.setDateHeader(name, ((Date)value).getTime()); + else + response.setHeader(name, value.toString()); } - } + } + if (!request.getMethod().equals("HEAD") && context.hasEntity()) { OutputStream out = response.getOutputStream(); context.writeTo(out); Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java (original) +++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/AbstractResponseContext.java Thu Oct 18 16:16:26 2007 @@ -18,6 +18,7 @@ package org.apache.abdera.protocol.server.impl; import java.util.ArrayList; +import java.util.Arrays; import java.util.BitSet; import java.util.Date; import java.util.HashMap; @@ -45,10 +46,10 @@ protected String status_text = null; protected Writer writer = null; - protected Map> headers = null; + protected Map headers = null; public void removeHeader(String name) { - Map> headers = getHeaders(); + Map headers = getHeaders(); headers.remove(name); } @@ -57,12 +58,11 @@ } public void setEncodedHeader(String name, String charset, String... vals) { - Map> headers = getHeaders(); - List values = new ArrayList(); - for (String value : vals) { - values.add(EncodingUtil.encode(value, charset)); + Object[] evals = new Object[vals.length]; + for (int n = 0; n < vals.length; n++) { + evals[n] = EncodingUtil.encode(vals[n], charset); } - headers.put(name, values); + setHeader(name, evals); } public void setEscapedHeader(String name, BitSet mask, String value) { @@ -70,19 +70,16 @@ } public void setHeader(String name, Object value) { - Map> headers = getHeaders(); - List values = new ArrayList(); - values.add(value); - headers.put(name, values); + setHeader(name, new Object[] {value}); } public void setHeader(String name, Object... vals) { - Map> headers = getHeaders(); + Map headers = getHeaders(); List values = new ArrayList(); for (Object value : vals) { values.add(value); } - headers.put(name, values); + headers.put(name, values.toArray(new Object[values.size()])); } public void addEncodedHeader(String name, String charset, String value) { @@ -90,48 +87,39 @@ } public void addEncodedHeaders(String name, String charset, String... vals) { - Map> headers = getHeaders(); - List values = new ArrayList(); - if (values == null) { - values = new ArrayList(); - headers.put(name,values); - } for (String value : vals) { - values.add(EncodingUtil.encode(value, charset)); + addHeader(name,EncodingUtil.encode(value, charset)); } } public void addHeader(String name, Object value) { - Map> headers = getHeaders(); - List values = new ArrayList(); - if (values == null) { - values = new ArrayList(); - headers.put(name, values); - } - values.add(value); + addHeader(name, new Object[] {value}); } public void addHeaders(String name, Object... vals) { - Map> headers = getHeaders(); - List values = new ArrayList(); + Map headers = getHeaders(); + Object[] values = headers.get(name); + List l = null; if (values == null) { - values = new ArrayList(); - headers.put(name,values); + l = new ArrayList(); + } else { + l = Arrays.asList(values); } for (Object value : vals) { - values.add(value); + l.add(value); } + headers.put(name, l.toArray(new Object[l.size()])); } - public Map> getHeaders() { + public Map getHeaders() { if (headers == null) - headers = new HashMap>(); + headers = new HashMap(); return headers; } public Date getDateHeader(String name) { - Map> headers = getHeaders(); - List values = headers.get(name); + Map headers = getHeaders(); + Object[] values = headers.get(name); if (values != null) { for (Object value : values) { if (value instanceof Date) @@ -142,20 +130,20 @@ } public String getHeader(String name) { - Map> headers = getHeaders(); - List values = headers.get(name); - if (values != null && values.size() > 0) - return values.get(0).toString(); + Map headers = getHeaders(); + Object[] values = headers.get(name); + if (values != null && values.length > 0) + return values[0].toString(); return null; } - public List getHeaders(String name) { - Map> headers = getHeaders(); + public Object[] getHeaders(String name) { + Map headers = getHeaders(); return headers.get(name); } public String[] getHeaderNames() { - Map> headers = getHeaders(); + Map headers = getHeaders(); return headers.keySet().toArray(new String[headers.size()]); } Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java (original) +++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/impl/HttpServletRequestContext.java Thu Oct 18 16:16:26 2007 @@ -167,9 +167,10 @@ } @SuppressWarnings("unchecked") - public List getHeaders(String name) { - Enumeration e = request.getHeaders(name); - return java.util.Collections.list(e); + public Object[] getHeaders(String name) { + Enumeration e = request.getHeaders(name); + List list = java.util.Collections.list(e); + return list.toArray(new String[list.size()]); } @SuppressWarnings("unchecked") Modified: incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java?rev=586171&r1=586170&r2=586171&view=diff ============================================================================== --- incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java (original) +++ incubator/abdera/java/trunk/server/src/test/java/org/apache/abdera/test/server/UtilityTest.java Thu Oct 18 16:16:26 2007 @@ -25,6 +25,9 @@ import java.util.HashMap; import java.util.List; +import junit.framework.TestCase; + +import org.apache.abdera.i18n.iri.IRI; import org.apache.abdera.protocol.server.ServiceManager; import org.apache.abdera.protocol.server.Target; import org.apache.abdera.protocol.server.TargetType; @@ -33,9 +36,6 @@ import org.apache.abdera.protocol.server.impl.SimpleSubjectResolver; import org.apache.abdera.protocol.util.EncodingUtil; import org.apache.abdera.util.EntityTag; -import org.apache.abdera.i18n.iri.IRI; - -import junit.framework.TestCase; public class UtilityTest extends TestCase { @@ -181,7 +181,7 @@ return null; } - public List getHeaders(String name) { + public String[] getHeaders(String name) { return null; }