geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgenen...@apache.org
Subject svn commit: r607542 [4/6] - in /geronimo/sandbox/async-http-client-mina2: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/ahc/ src/main/java/org/apache/ahc/auth/ src/main/java/org/apache/ahc/codec/...
Date Sun, 30 Dec 2007 11:37:00 GMT
Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/ResponseFuture.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/ResponseFuture.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/ResponseFuture.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/ResponseFuture.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,133 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ahc.codec;
+
+import java.net.InetSocketAddress;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ConcurrentMap;
+
+import org.apache.mina.common.IoSession;
+
+/**
+ * Class that provides access to cached sessions.  IoSessions are cached using
+ * the host and the port.  This class is thread safe.
+ */
+public final class SessionCache {
+    private static final SessionCache theInstance = new SessionCache();
+    
+    private final ConcurrentMap<String,Queue<IoSession>> cachedSessions = 
+            new ConcurrentHashMap<String,Queue<IoSession>>();
+    
+    /**
+     * Returns a singleton instance of the session cache.
+     */
+    public static SessionCache getInstance() {
+        return theInstance;
+    }
+    
+    private SessionCache() {}
+
+    /**
+     * Returns an IoSession that is connected and considered usable.  Note that
+     * this is still on a best-effort basis, and there is no guarantee that the
+     * connection can be used without errors, although it should be usually
+     * safe to use it.
+     * 
+     * @param msg the message for which to look up an active session.
+     * @throws IllegalArgumentException if a null request message was passed in.
+     * @return an active IoSession, or null if none are found.
+     */
+    public IoSession getActiveSession(HttpRequestMessage msg) {
+        if (msg == null) {
+            throw new IllegalArgumentException("null request was passed in");
+        }
+        
+        Queue<IoSession> queue = cachedSessions.get(getKey(msg));
+        if (queue == null) {
+            return null;
+        }
+        
+        IoSession cached = null;
+        while ((cached = queue.poll()) != null) {
+        	// see if the session is usable
+            if (cached.isConnected() && !cached.isClosing()) {
+                return cached;
+            }
+        }
+        return null;
+    }
+    
+    /**
+     * Caches the given session using its remote host and port information.
+     * 
+     * @param session IoSession to cache
+     * @throws IllegalArgumentException if a null session was passed in.
+     */
+    void cacheSession(IoSession session) {
+        if (session == null) {
+            throw new IllegalArgumentException("null session was passed in");
+        }
+        
+        String key = getKey((InetSocketAddress)session.getRemoteAddress());
+        Queue<IoSession> newQueue = new ConcurrentLinkedQueue<IoSession>();
+        Queue<IoSession> queue = cachedSessions.putIfAbsent(key, newQueue);
+        if (queue == null) {
+            // the value was previously empty
+            queue = newQueue;
+        }
+        // add it to the queue
+        queue.offer(session);
+    }
+    
+    /**
+     * Removes the given session from the cache if it is in the cache.
+     * 
+     * @param session IoSession to remove from the cache
+     * @throws IllegalArgumentException if a null session was passed in
+     */
+    void removeSession(IoSession session) {
+        if (session == null) {
+            throw new IllegalArgumentException("null session was passed in");
+        }
+        
+        String key = getKey((InetSocketAddress)session.getRemoteAddress());
+        Queue<IoSession> queue = cachedSessions.get(key);
+        if (queue != null) {
+            queue.remove(session);
+        }
+    }
+    
+    private String getKey(HttpRequestMessage msg) {
+        return getKey(msg.getHost(), msg.getPort());
+    }
+    
+    private String getKey(InetSocketAddress remote) {
+        return getKey(remote.getHostName(), remote.getPort());
+    }
+    
+    /**
+     * The key is of the form "host:port".
+     */
+    private String getKey(String host, int port) {
+        return new StringBuilder(host).append(':').append(port).toString();
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html Sun Dec 30 03:36:47 2007
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+  ~  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.
+  -->
+</head>
+<body bgcolor="white">
+Contains the classes that support messages, encoding, and decoding the HTTP protocol.
+</body>
+</html>

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html Sun Dec 30 03:36:47 2007
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+  ~  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.
+  -->
+</head>
+<body bgcolor="white">
+<h2>The primary user components for the AsyncHttpClient API.</h2>
+</body>
+</html>

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,84 @@
+/*
+ *  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.
+ *
+ */
+package org.apache.ahc.ssl;
+
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactorySpi;
+import javax.net.ssl.X509TrustManager;
+
+/**
+ * The Class TrustManagerFactoryImpl.  Sets up the Trust support for SSL contexts.
+ */
+public class TrustManagerFactoryImpl extends TrustManagerFactorySpi {
+    
+    /** The Constant X509. */
+    public static final X509TrustManager X509 = new X509TrustManager() {
+
+
+        public void checkClientTrusted(X509Certificate[] x509Certificates, String s)
+            throws CertificateException {
+
+        }
+
+
+        public void checkServerTrusted(X509Certificate[] x509Certificates, String s)
+            throws CertificateException {
+
+        }
+
+
+        public X509Certificate[] getAcceptedIssuers() {
+
+            return new X509Certificate[0];
+
+        }
+
+    };
+
+    /** The Constant X509_MANAGERS. */
+    public static final TrustManager[] X509_MANAGERS = new TrustManager[] {X509};
+
+    /* Default stub for the <code>TrustManagerFactorySpi</code> parent.
+     * @see javax.net.ssl.TrustManagerFactorySpi#engineInit(java.security.KeyStore)
+     */
+    protected void engineInit(KeyStore keyStore) throws KeyStoreException {
+    }
+
+    /* Default stub for the <code>TrustManagerFactorySpi</code> parent.
+     * @see javax.net.ssl.TrustManagerFactorySpi#engineInit(javax.net.ssl.ManagerFactoryParameters)
+     */
+    protected void engineInit(ManagerFactoryParameters managerFactoryParameters)
+        throws InvalidAlgorithmParameterException {
+    }
+
+    /* Default stub for the <code>TrustManagerFactorySpi</code> parent.
+     * @return array of <code>TrustManager</code> objects.
+     * @see javax.net.ssl.TrustManagerFactorySpi#engineGetTrustManagers()
+     */
+    protected TrustManager[] engineGetTrustManagers() {
+        return X509_MANAGERS;
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html Sun Dec 30 03:36:47 2007
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+  ~  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.
+  -->
+</head>
+<body bgcolor="white">
+SSL utility classes.
+</body>
+</html>

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ahc.util;
+
+/**
+ * The Class AsyncHttpClientException.  Generic unchecked exception used with the 
+ * AsyncHttpClient API.
+ */
+public class AsyncHttpClientException extends Error {
+
+    /**
+     * Instantiates a new async http client exception.
+     */
+    public AsyncHttpClientException() {
+    }
+
+    /**
+     * Instantiates a new async http client exception.
+     * 
+     * @param string the string
+     */
+    public AsyncHttpClientException(String string) {
+        super(string);
+    }
+
+    /**
+     * Instantiates a new async http client exception.
+     * 
+     * @param string the string
+     * @param throwable the throwable
+     */
+    public AsyncHttpClientException(String string, Throwable throwable) {
+        super(string, throwable);
+    }
+
+    /**
+     * Instantiates a new async http client exception.
+     * 
+     * @param throwable the throwable
+     */
+    public AsyncHttpClientException(Throwable throwable) {
+        super(throwable);
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ahc.util;
+
+/**
+ * An exception to indicate an error parsing a date string.
+ * 
+ * @see DateUtil
+ * @author Michael Becke
+ */
+public class DateParseException extends Exception {
+
+    /**
+     * Instantiates a new date parse exception.
+     */
+    public DateParseException() {
+        super();
+    }
+
+    /**
+     * Instantiates a new date parse exception.
+     * 
+     * @param message the message
+     */
+    public DateParseException(String message) {
+        super(message);
+    }
+
+}
+

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ahc.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * A utility class for parsing and formatting HTTP dates as used in cookies and
+ * other headers.  This class handles dates as defined by RFC 2616 section
+ * 3.3.1 as well as some other common non-standard formats.
+ *
+ * @author Christopher Brown
+ * @author Michael Becke
+ */
+public final class DateUtil {
+
+    /**
+     * Date format pattern used to parse HTTP date headers in RFC 1123 format.
+     */
+    public static final String PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
+
+    /**
+     * Date format pattern used to parse HTTP date headers in RFC 1036 format.
+     */
+    public static final String PATTERN_RFC1036 = "EEEE, dd-MMM-yy HH:mm:ss zzz";
+
+    /**
+     * Date format pattern used to parse HTTP date headers in ANSI C
+     * <code>asctime()</code> format.
+     */
+    public static final String PATTERN_ASCTIME = "EEE MMM d HH:mm:ss yyyy";
+
+    private static final Collection DEFAULT_PATTERNS = Arrays.asList(
+        new String[] {PATTERN_ASCTIME, PATTERN_RFC1036, PATTERN_RFC1123});
+
+    private static final Date DEFAULT_TWO_DIGIT_YEAR_START;
+
+    static {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(2000, Calendar.JANUARY, 1, 0, 0);
+        DEFAULT_TWO_DIGIT_YEAR_START = calendar.getTime();
+    }
+
+    private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
+
+    /**
+     * This class should not be instantiated.
+     */
+    private DateUtil() {
+    }
+
+
+    /**
+     * Parses a date value.  The formats used for parsing the date value are retrieved from
+     * the default http params.
+     *
+     * @param dateValue the date value to parse
+     * @return the parsed date
+     * @throws DateParseException if the value could not be parsed using any of the
+     *                            supported date formats
+     */
+    public static Date parseDate(String dateValue) throws DateParseException {
+        return parseDate(dateValue, null, null);
+    }
+
+    /**
+     * Parses the date value using the given date formats.
+     *
+     * @param dateValue   the date value to parse
+     * @param dateFormats the date formats to use
+     * @return the parsed date
+     * @throws DateParseException if none of the dataFormats could parse the dateValue
+     */
+    public static Date parseDate(String dateValue, Collection dateFormats)
+        throws DateParseException {
+        return parseDate(dateValue, dateFormats, null);
+    }
+
+    /**
+     * Parses the date value using the given date formats.
+     *
+     * @param dateValue   the date value to parse
+     * @param dateFormats the date formats to use
+     * @param startDate   During parsing, two digit years will be placed in the range
+     *                    <code>startDate</code> to <code>startDate + 100 years</code>. This value may
+     *                    be <code>null</code>. When <code>null</code> is given as a parameter, year
+     *                    <code>2000</code> will be used.
+     * @return the parsed date
+     * @throws DateParseException if none of the dataFormats could parse the dateValue
+     */
+    public static Date parseDate(
+        String dateValue,
+        Collection dateFormats,
+        Date startDate
+    ) throws DateParseException {
+
+        if (dateValue == null) {
+            throw new IllegalArgumentException("dateValue is null");
+        }
+        if (dateFormats == null) {
+            dateFormats = DEFAULT_PATTERNS;
+        }
+        if (startDate == null) {
+            startDate = DEFAULT_TWO_DIGIT_YEAR_START;
+        }
+        // trim single quotes around date if present
+        // see issue #5279
+        if (dateValue.length() > 1
+            && dateValue.startsWith("'")
+            && dateValue.endsWith("'")
+            ) {
+            dateValue = dateValue.substring(1, dateValue.length() - 1);
+        }
+
+        SimpleDateFormat dateParser = null;
+        Iterator formatIter = dateFormats.iterator();
+
+        while (formatIter.hasNext()) {
+            String format = (String)formatIter.next();
+            if (dateParser == null) {
+                dateParser = new SimpleDateFormat(format, Locale.US);
+                dateParser.setTimeZone(TimeZone.getTimeZone("GMT"));
+                dateParser.set2DigitYearStart(startDate);
+            } else {
+                dateParser.applyPattern(format);
+            }
+            try {
+                return dateParser.parse(dateValue);
+            } catch (ParseException pe) {
+                // ignore this exception, we will try the next format
+            }
+        }
+
+        // we were unable to parse the date
+        throw new DateParseException("Unable to parse the date " + dateValue);
+    }
+
+    /**
+     * Formats the given date according to the RFC 1123 pattern.
+     *
+     * @param date The date to format.
+     * @return An RFC 1123 formatted date string.
+     * @see #PATTERN_RFC1123
+     */
+    public static String formatDate(Date date) {
+        return formatDate(date, PATTERN_RFC1123);
+    }
+
+    /**
+     * Formats the given date according to the specified pattern.  The pattern
+     * must conform to that used by the {@link SimpleDateFormat simple date
+     * format} class.
+     *
+     * @param date    The date to format.
+     * @param pattern The pattern to use for formatting the date.
+     * @return A formatted date string.
+     * @throws IllegalArgumentException If the given date pattern is invalid.
+     * @see SimpleDateFormat
+     */
+    public static String formatDate(Date date, String pattern) {
+        if (date == null) {
+            throw new IllegalArgumentException("date is null");
+        }
+        if (pattern == null) {
+            throw new IllegalArgumentException("pattern is null");
+        }
+
+        SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.US);
+        formatter.setTimeZone(GMT);
+        return formatter.format(date);
+    }
+
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,265 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ahc.util;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.codec.net.URLCodec;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The home for utility methods that handle various encoding tasks.
+ *
+ * @author Michael Becke
+ * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
+ * @since 2.0 final
+ */
+public final class EncodingUtil {
+
+    static final Logger LOG = LoggerFactory.getLogger(EncodingUtil.class);
+
+    /**
+     * Default content encoding chatset
+     */
+    private static final String DEFAULT_CHARSET = "ISO-8859-1";
+
+    /**
+     * This class should not be instantiated.
+     */
+    private EncodingUtil() {
+    }
+
+    /**
+     * Form-urlencoding routine.
+     * <p/>
+     * The default encoding for all forms is `application/x-www-form-urlencoded'.
+     * A form data set is represented in this media type as follows:
+     * <p/>
+     * The form field names and values are escaped: space characters are replaced
+     * by `+', and then reserved characters are escaped as per [URL]; that is,
+     * non-alphanumeric characters are replaced by `%HH', a percent sign and two
+     * hexadecimal digits representing the ASCII code of the character. Line breaks,
+     * as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
+     * <p/>
+     * <p/>
+     * if the given charset is not supported, ISO-8859-1 is used instead.
+     * </p>
+     *
+     * @param pairs   the values to be encoded
+     * @param charset the character set of pairs to be encoded
+     * @return the urlencoded pairs
+     * @since 2.0 final
+     */
+    public static String formUrlEncode(NameValuePair[] pairs, String charset) {
+        try {
+            return doFormUrlEncode(pairs, charset);
+        } catch (UnsupportedEncodingException e) {
+            LOG.error("Encoding not supported: " + charset);
+            try {
+                return doFormUrlEncode(pairs, DEFAULT_CHARSET);
+            } catch (UnsupportedEncodingException fatal) {
+                // Should never happen. ISO-8859-1 must be supported on all JVMs
+                throw new AsyncHttpClientException("Encoding not supported: "
+                    + DEFAULT_CHARSET);
+            }
+        }
+    }
+
+    /**
+     * Form-urlencoding routine.
+     * <p/>
+     * The default encoding for all forms is `application/x-www-form-urlencoded'.
+     * A form data set is represented in this media type as follows:
+     * <p/>
+     * The form field names and values are escaped: space characters are replaced
+     * by `+', and then reserved characters are escaped as per [URL]; that is,
+     * non-alphanumeric characters are replaced by `%HH', a percent sign and two
+     * hexadecimal digits representing the ASCII code of the character. Line breaks,
+     * as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
+     *
+     * @param pairs   the values to be encoded
+     * @param charset the character set of pairs to be encoded
+     * @return the urlencoded pairs
+     * @throws UnsupportedEncodingException if charset is not supported
+     * @since 2.0 final
+     */
+    private static String doFormUrlEncode(NameValuePair[] pairs, String charset)
+        throws UnsupportedEncodingException {
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < pairs.length; i++) {
+            URLCodec codec = new URLCodec();
+            NameValuePair pair = pairs[i];
+            if (pair.getName() != null) {
+                if (i > 0) {
+                    buf.append("&");
+                }
+                buf.append(codec.encode(pair.getName(), charset));
+                buf.append("=");
+                if (pair.getValue() != null) {
+                    buf.append(codec.encode(pair.getValue(), charset));
+                }
+            }
+        }
+        return buf.toString();
+    }
+
+    /**
+     * Converts the byte array of HTTP content characters to a string. If
+     * the specified charset is not supported, default system encoding
+     * is used.
+     *
+     * @param data    the byte array to be encoded
+     * @param offset  the index of the first byte to encode
+     * @param length  the number of bytes to encode
+     * @param charset the desired character encoding
+     * @return The result of the conversion.
+     * @since 3.0
+     */
+    public static String getString(
+        final byte[] data,
+        int offset,
+        int length,
+        String charset
+    ) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
+
+        if (charset == null || charset.length() == 0) {
+            throw new IllegalArgumentException("charset may not be null or empty");
+        }
+
+        try {
+            return new String(data, offset, length, charset);
+        } catch (UnsupportedEncodingException e) {
+
+            if (LOG.isWarnEnabled()) {
+                LOG.warn("Unsupported encoding: " + charset + ". System encoding used");
+            }
+            return new String(data, offset, length);
+        }
+    }
+
+
+    /**
+     * Converts the byte array of HTTP content characters to a string. If
+     * the specified charset is not supported, default system encoding
+     * is used.
+     *
+     * @param data    the byte array to be encoded
+     * @param charset the desired character encoding
+     * @return The result of the conversion.
+     * @since 3.0
+     */
+    public static String getString(final byte[] data, String charset) {
+        return getString(data, 0, data.length, charset);
+    }
+
+    /**
+     * Converts the specified string to a byte array.  If the charset is not supported the
+     * default system charset is used.
+     *
+     * @param data    the string to be encoded
+     * @param charset the desired character encoding
+     * @return The resulting byte array.
+     * @since 3.0
+     */
+    public static byte[] getBytes(final String data, String charset) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("data may not be null");
+        }
+
+        if (charset == null || charset.length() == 0) {
+            throw new IllegalArgumentException("charset may not be null or empty");
+        }
+
+        try {
+            return data.getBytes(charset);
+        } catch (UnsupportedEncodingException e) {
+
+            if (LOG.isWarnEnabled()) {
+                LOG.warn("Unsupported encoding: " + charset + ". System encoding used.");
+            }
+
+            return data.getBytes();
+        }
+    }
+
+    /**
+     * Converts the specified string to byte array of ASCII characters.
+     *
+     * @param data the string to be encoded
+     * @return The string as a byte array.
+     * @since 3.0
+     */
+    public static byte[] getAsciiBytes(final String data) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
+
+        try {
+            return data.getBytes("US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            throw new AsyncHttpClientException("HttpClient requires ASCII support");
+        }
+    }
+
+    /**
+     * Converts the byte array of ASCII characters to a string. This method is
+     * to be used when decoding content of HTTP elements (such as response
+     * headers)
+     *
+     * @param data   the byte array to be encoded
+     * @param offset the index of the first byte to encode
+     * @param length the number of bytes to encode
+     * @return The string representation of the byte array
+     */
+    public static String getAsciiString(final byte[] data, int offset, int length) {
+
+        if (data == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
+
+        try {
+            return new String(data, offset, length, "US-ASCII");
+        } catch (UnsupportedEncodingException e) {
+            throw new AsyncHttpClientException("HttpClient requires ASCII support");
+        }
+    }
+
+    /**
+     * Converts the byte array of ASCII characters to a string. This method is
+     * to be used when decoding content of HTTP elements (such as response
+     * headers)
+     *
+     * @param data the byte array to be encoded
+     * @return The string representation of the byte array
+     */
+    public static String getAsciiString(final byte[] data) {
+        return getAsciiString(data, 0, data.length);
+    }
+
+
+}
+

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ahc.util;
+
+/**
+ * A set of utility methods to help produce consistent Object#equals(Object) and
+ * Object#hashCode methods.
+ * 
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ */
+public final class LangUtils {
+
+    /** The Constant HASH_SEED. */
+    public static final int HASH_SEED = 17;
+    
+    /** The Constant HASH_OFFSET. */
+    public static final int HASH_OFFSET = 37;
+
+    /**
+     * Instantiates a new LangUtils object.
+     */
+    private LangUtils() {
+        super();
+    }
+
+    /**
+     * Hash code.
+     * 
+     * @param seed the seed
+     * @param hashcode the hashcode
+     * 
+     * @return the calculated hash value
+     */
+    public static int hashCode(final int seed, final int hashcode) {
+        return seed * HASH_OFFSET + hashcode;
+    }
+
+    /**
+     * Hash code.
+     * 
+     * @param seed the seed
+     * @param obj the obj
+     * 
+     * @return the calculated hash value
+     */
+    public static int hashCode(final int seed, final Object obj) {
+        return hashCode(seed, obj != null ? obj.hashCode() : 0);
+    }
+
+    /**
+     * Hash code.
+     * 
+     * @param seed the seed
+     * @param b the b
+     * 
+     * @return the calculated hash value
+     */
+    public static int hashCode(final int seed, final boolean b) {
+        return hashCode(seed, b ? 1 : 0);
+    }
+
+    /**
+     * Equals.
+     * 
+     * @param obj1 the obj1
+     * @param obj2 the obj2
+     * 
+     * @return true, if the objects equal
+     */
+    public static boolean equals(final Object obj1, final Object obj2) {
+        return obj1 == null ? obj2 == null : obj1.equals(obj2);
+    }
+
+}
+

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,144 @@
+/*
+ * 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.
+ *
+ */
+package org.apache.ahc.util;
+
+import java.io.Serializable;
+
+/**
+ * The Class NameValuePair. A wrapper class to represent name/value Strings.
+ */
+public class NameValuePair implements Serializable {
+    
+    /** Name. */
+    private String name;
+
+    /** Value. */
+    private String value;
+
+
+    /**
+     * Default constructor.
+     */
+    public NameValuePair() {
+        this(null, null);
+    }
+
+    /**
+     * Constructor.
+     * 
+     * @param name  The name.
+     * @param value The value.
+     */
+    public NameValuePair(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+
+
+    /**
+     * Sets the name.
+     * 
+     * @param name The new name
+     * 
+     * @see #getName()
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+
+    /**
+     * Returns the name.
+     * 
+     * @return String name The name
+     * 
+     * @see #setName(String)
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * Sets the value.
+     * 
+     * @param value The new value.
+     */
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+
+    /**
+     * Returns the current value.
+     * 
+     * @return String value The current value.
+     */
+    public String getValue() {
+        return value;
+    }
+
+    // --------------------------------------------------------- Public Methods
+
+    /**
+     * Get a String representation of this pair.
+     * 
+     * @return A string representation.
+     */
+    public String toString() {
+        return "name=" + name + ", " + "value=" + value;
+    }
+
+    /**
+     * Equals.
+     * 
+     * @param object to compare with <code>this</code>
+     * 
+     * @return true, if the objects equal
+     */
+    public boolean equals(final Object object) {
+        if (object == null) {
+            return false;
+        }
+        if (this == object) {
+            return true;
+        }
+        if (object instanceof NameValuePair) {
+            NameValuePair that = (NameValuePair)object;
+            return LangUtils.equals(this.name, that.name)
+                && LangUtils.equals(this.value, that.value);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Hash code.
+     * 
+     * @return the calculated hash value
+     */
+    public int hashCode() {
+        int hash = LangUtils.HASH_SEED;
+        hash = LangUtils.hashCode(hash, this.name);
+        hash = LangUtils.hashCode(hash, this.value);
+        return hash;
+    }
+}
+

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,62 @@
+/*
+ *  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.
+ */
+
+package org.apache.ahc.util;
+
+/**
+ * The Class NeedMoreDataException.  Represents an exception if the decoders need more data.
+ */
+public class NeedMoreDataException extends Exception {
+
+    /**
+     * Instantiates a new need more data exception.
+     */
+    public NeedMoreDataException() {
+        super();
+    }
+
+    /**
+     * Instantiates a new need more data exception.
+     * 
+     * @param string the string
+     */
+    public NeedMoreDataException(String string) {
+        super(string);
+    }
+
+    /**
+     * Instantiates a new need more data exception.
+     * 
+     * @param string the string
+     * @param throwable the throwable
+     */
+    public NeedMoreDataException(String string, Throwable throwable) {
+        super(string,
+            throwable);
+    }
+
+    /**
+     * Instantiates a new need more data exception.
+     * 
+     * @param throwable the throwable
+     */
+    public NeedMoreDataException(Throwable throwable) {
+        super(throwable);
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,226 @@
+/*
+ *  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.
+ */
+
+package org.apache.ahc.util;
+
+/**
+ * <p>
+ *  This formatter produces a textual representation of attribute/value pairs. It
+ *  comforms to the generic grammar and formatting rules outlined in the
+ *  <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.1">Section 2.1</a>
+ *  and
+ *  <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6">Section 3.6</a>
+ *  of <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.txt">RFC 2616</a>
+ * </p>
+ * <h>2.1 Augmented BNF</h>
+ * <p>
+ *  Many HTTP/1.1 header field values consist of words separated by LWS or special
+ *  characters. These special characters MUST be in a quoted string to be used within
+ *  a parameter value (as defined in section 3.6).
+ * <p>
+ * <pre>
+ * token          = 1*<any CHAR except CTLs or separators>
+ * separators     = "(" | ")" | "<" | ">" | "@"
+ *                | "," | ";" | ":" | "\" | <">
+ *                | "/" | "[" | "]" | "?" | "="
+ *                | "{" | "}" | SP | HT
+ * </pre>
+ * <p>
+ *  A string of text is parsed as a single word if it is quoted using double-quote marks.
+ * </p>
+ * <pre>
+ * quoted-string  = ( <"> *(qdtext | quoted-pair ) <"> )
+ * qdtext         = <any TEXT except <">>
+ * </pre>
+ * <p>
+ *  The backslash character ("\") MAY be used as a single-character quoting mechanism only
+ *  within quoted-string and comment constructs.
+ * </p>
+ * <pre>
+ * quoted-pair    = "\" CHAR
+ * </pre>
+ * <h>3.6 Transfer Codings</h>
+ * <p>
+ *  Parameters are in the form of attribute/value pairs.
+ * </p>
+ * <pre>
+ * parameter               = attribute "=" value
+ * attribute               = token
+ * value                   = token | quoted-string
+ * </pre>
+ *
+ * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
+ * 
+ */
+public class ParameterFormatter {
+        /**
+     * Special characters that can be used as separators in HTTP parameters.
+     * These special characters MUST be in a quoted string to be used within
+     * a parameter value
+     */
+    private static final char[] SEPARATORS   = {
+            '(', ')', '<', '>', '@',
+            ',', ';', ':', '\\', '"',
+            '/', '[', ']', '?', '=',
+            '{', '}', ' ', '\t'
+            };
+
+    /**
+     * Unsafe special characters that must be escaped using the backslash
+     * character
+     */
+    private static final char[] UNSAFE_CHARS = {
+            '"', '\\'
+            };
+
+    /**
+     * This flag determines whether all parameter values must be enclosed in
+     * quotation marks, even if they do not contain any special characters
+     */
+    private boolean alwaysUseQuotes = true;
+
+    /** Default ParameterFormatter constructor */
+    public ParameterFormatter() {
+        super();
+    }
+
+    private static boolean isOneOf(char[] chars, char ch) {
+        for (int i = 0; i < chars.length; i++) {
+            if (ch == chars[i]) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private static boolean isUnsafeChar(char ch) {
+        return isOneOf(UNSAFE_CHARS, ch);
+    }
+
+    private static boolean isSeparator(char ch) {
+        return isOneOf(SEPARATORS, ch);
+    }
+
+    /**
+     * Determines whether all parameter values must be enclosed in quotation
+     * marks, even if they do not contain any special characters
+     *
+     * @return <tt>true</tt> if all parameter values must be enclosed in
+     * quotation marks, <tt>false</tt> otherwise
+     */
+    public boolean isAlwaysUseQuotes() {
+        return alwaysUseQuotes;
+    }
+
+    /**
+     * Defines whether all parameter values must be enclosed in quotation
+     * marks, even if they do not contain any special characters
+     *
+     * @param alwaysUseQuotes
+     */
+    public void setAlwaysUseQuotes(boolean alwaysUseQuotes) {
+        this.alwaysUseQuotes = alwaysUseQuotes;
+    }
+
+    /**
+     * Formats the given parameter value using formatting rules defined
+     * in RFC 2616
+     *
+     * @param buffer output buffer
+     * @param value the parameter value to be formatted
+     * @param alwaysUseQuotes <tt>true</tt> if the parameter value must
+     * be enclosed in quotation marks, even if it does not contain any special
+     * characters<tt>, false</tt> only if the parameter value contains
+     * potentially unsafe special characters
+     */
+    public static void formatValue(
+            final StringBuffer buffer, final String value, boolean alwaysUseQuotes) {
+        if (buffer == null) {
+            throw new IllegalArgumentException("String buffer may not be null");
+        }
+        if (value == null) {
+            throw new IllegalArgumentException("Value buffer may not be null");
+        }
+        if (alwaysUseQuotes) {
+            buffer.append('"');
+            for (int i = 0; i < value.length(); i++) {
+                char ch = value.charAt(i);
+                if (isUnsafeChar(ch)) {
+                    buffer.append('\\');
+                }
+                buffer.append(ch);
+            }
+            buffer.append('"');
+        } else {
+            int offset = buffer.length();
+            boolean unsafe = false;
+            for (int i = 0; i < value.length(); i++) {
+                char ch = value.charAt(i);
+                if (isSeparator(ch)) {
+                    unsafe = true;
+                }
+                if (isUnsafeChar(ch)) {
+                    buffer.append('\\');
+                }
+                buffer.append(ch);
+            }
+            if (unsafe) {
+                buffer.insert(offset, '"');
+                buffer.append('"');
+            }
+        }
+    }
+
+    /**
+     * Produces textual representaion of the attribute/value pair using
+     * formatting rules defined in RFC 2616
+     *
+     * @param buffer output buffer
+     * @param param the parameter to be formatted
+     */
+    public void format(final StringBuffer buffer, final NameValuePair param) {
+        if (buffer == null) {
+            throw new IllegalArgumentException("String buffer may not be null");
+        }
+        if (param == null) {
+            throw new IllegalArgumentException("Parameter may not be null");
+        }
+        buffer.append(param.getName());
+        String value = param.getValue();
+        if (value != null) {
+            buffer.append("=");
+            formatValue(buffer, value, this.alwaysUseQuotes);
+        }
+    }
+
+    /**
+     * Produces textual representaion of the attribute/value pair using
+     * formatting rules defined in RFC 2616
+     *
+     * @param param the parameter to be formatted
+     *
+     * @return RFC 2616 conformant textual representaion of the
+     * attribute/value pair
+     */
+    public String format(final NameValuePair param) {
+        StringBuffer buffer = new StringBuffer();
+        format(buffer, param);
+        return buffer.toString();
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,228 @@
+/*
+ *  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.
+ */
+
+package org.apache.ahc.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ParameterParser {
+
+    /**
+     * String to be parsed
+     */
+    private char[] chars = null;
+
+    /**
+     * Current position in the string
+     */
+    private int pos = 0;
+
+    /**
+     * Maximum position in the string
+     */
+    private int len = 0;
+
+    /**
+     * Start of a token
+     */
+    private int i1 = 0;
+
+    /**
+     * End of a token
+     */
+    private int i2 = 0;
+
+    /**
+     * Default ParameterParser constructor
+     */
+    public ParameterParser() {
+        super();
+    }
+
+
+    /**
+     * Are there any characters left to parse?
+     */
+    private boolean hasChar() {
+        return this.pos < this.len;
+    }
+
+
+    /**
+     * A helper method to process the parsed token.
+     */
+    private String getToken(boolean quoted) {
+        // Trim leading white spaces
+        while ((i1 < i2) && (Character.isWhitespace(chars[i1]))) {
+            i1++;
+        }
+        // Trim trailing white spaces
+        while ((i2 > i1) && (Character.isWhitespace(chars[i2 - 1]))) {
+            i2--;
+        }
+        // Strip away quotes if necessary
+        if (quoted) {
+            if (((i2 - i1) >= 2)
+                && (chars[i1] == '"')
+                && (chars[i2 - 1] == '"')) {
+                i1++;
+                i2--;
+            }
+        }
+        String result = null;
+        if (i2 >= i1) {
+            result = new String(chars, i1, i2 - i1);
+        }
+        return result;
+    }
+
+
+    /**
+     * Is given character present in the array of characters?
+     */
+    private boolean isOneOf(char ch, char[] charray) {
+        boolean result = false;
+        for (int i = 0; i < charray.length; i++) {
+            if (ch == charray[i]) {
+                result = true;
+                break;
+            }
+        }
+        return result;
+    }
+
+
+    /**
+     * Parse out a token until any of the given terminators
+     * is encountered.
+     */
+    private String parseToken(final char[] terminators) {
+        char ch;
+        i1 = pos;
+        i2 = pos;
+        while (hasChar()) {
+            ch = chars[pos];
+            if (isOneOf(ch, terminators)) {
+                break;
+            }
+            i2++;
+            pos++;
+        }
+        return getToken(false);
+    }
+
+
+    /**
+     * Parse out a token until any of the given terminators
+     * is encountered. Special characters in quoted tokens
+     * are escaped.
+     */
+    private String parseQuotedToken(final char[] terminators) {
+        char ch;
+        i1 = pos;
+        i2 = pos;
+        boolean quoted = false;
+        boolean charEscaped = false;
+        while (hasChar()) {
+            ch = chars[pos];
+            if (!quoted && isOneOf(ch, terminators)) {
+                break;
+            }
+            if (!charEscaped && ch == '"') {
+                quoted = !quoted;
+            }
+            charEscaped = (!charEscaped && ch == '\\');
+            i2++;
+            pos++;
+
+        }
+        return getToken(true);
+    }
+
+    /**
+     * Extracts a list of {@link NameValuePair}s from the given string.
+     *
+     * @param str the string that contains a sequence of name/value pairs
+     * @return a list of {@link NameValuePair}s
+     */
+    public List parse(final String str, char separator) {
+
+        if (str == null) {
+            return new ArrayList();
+        }
+        return parse(str.toCharArray(), separator);
+    }
+
+    /**
+     * Extracts a list of {@link NameValuePair}s from the given array of
+     * characters.
+     *
+     * @param chars the array of characters that contains a sequence of
+     *              name/value pairs
+     * @return a list of {@link NameValuePair}s
+     */
+    public List parse(final char[] chars, char separator) {
+
+        if (chars == null) {
+            return new ArrayList();
+        }
+        return parse(chars, 0, chars.length, separator);
+    }
+
+
+    /**
+     * Extracts a list of {@link NameValuePair}s from the given array of
+     * characters.
+     *
+     * @param chars  the array of characters that contains a sequence of
+     *               name/value pairs
+     * @param offset - the initial offset.
+     * @param length - the length.
+     * @return a list of {@link NameValuePair}s
+     */
+    public List parse(final char[] chars, int offset, int length, char separator) {
+
+        if (chars == null) {
+            return new ArrayList();
+        }
+        List params = new ArrayList();
+        this.chars = chars;
+        this.pos = offset;
+        this.len = length;
+
+        String paramName = null;
+        String paramValue = null;
+        while (hasChar()) {
+            paramName = parseToken(new char[] {'=', separator});
+            paramValue = null;
+            if (hasChar() && (chars[pos] == '=')) {
+                pos++; // skip '='
+                paramValue = parseQuotedToken(new char[] {separator});
+            }
+            if (hasChar() && (chars[pos] == separator)) {
+                pos++; // skip separator
+            }
+            if (paramName != null && !(paramName.equals("") && paramValue == null)) {
+                params.add(new NameValuePair(paramName, paramValue));
+            }
+        }
+        return params;
+    }
+}

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java
------------------------------------------------------------------------------
    svn:mime-type = text/x-java

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html Sun Dec 30 03:36:47 2007
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+<!--
+  ~  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.
+  -->
+</head>
+<body bgcolor="white">
+AsynHttpClient utility and support classes.
+</body>
+</html>

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html Sun Dec 30 03:36:47 2007
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+    <!--
+    ~  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.
+    -->
+    <title>The AsyncHttpClient is a high performance HTTP client API that is based on the Java NIO networking
+        API.</title>
+</head>
+<body bgcolor="white">
+<h1>The AsyncHttpClient is a high performance HTTP client API that is based on the Java NIO networking API.</h1>
+This API is based on the <a href="http://mina.apache.org">Apache MINA</a> framework to provide a high
+performance networking library based on the HTTP protocol. The AsyncHttpClient utilizes the Java NIO and
+mutlithreaded capabilities to be able to handle many concurrent outbound connections without having threads
+sitting in a wait state. There are numerous applications this API can be good for, such as gaming applications
+or web servers that need to access 3rd party web components and operate under heavy load. The major
+implication for this API is the ability to effectively and efficiently make use of threads while waiting for
+responses from the server.
+</body>
+</html>

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: geronimo/sandbox/async-http-client-mina2/src/test/catalina/conf/keystore
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/test/catalina/conf/keystore?rev=607542&view=auto
==============================================================================
Binary file - no diff available.

Propchange: geronimo/sandbox/async-http-client-mina2/src/test/catalina/conf/keystore
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message