You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2007/12/30 12:37:00 UTC

svn commit: r607542 [1/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/...

Author: jgenender
Date: Sun Dec 30 03:36:47 2007
New Revision: 607542

URL: http://svn.apache.org/viewvc?rev=607542&view=rev
Log:
Adding a Mina2 version of AsyncHttpClient

Added:
    geronimo/sandbox/async-http-client-mina2/
    geronimo/sandbox/async-http-client-mina2/pom.xml   (with props)
    geronimo/sandbox/async-http-client-mina2/src/
    geronimo/sandbox/async-http-client-mina2/src/main/
    geronimo/sandbox/async-http-client-mina2/src/main/java/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClient.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthChallengeParser.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthPolicy.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScheme.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthSchemeBase.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScope.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthState.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthenticationException.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/BasicScheme.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/Credentials.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/DigestScheme.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/InvalidCredentialsException.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/MalformedChallengeException.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/NTCredentials.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/NTLM.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/NTLMScheme.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/RFC2617Scheme.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/UsernamePasswordCredentials.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/Cookie.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpDecoder.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpIoHandler.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpMessage.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpProtocolCodecFactory.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpRequestEncoder.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpRequestMessage.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpResponseDecoder.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/HttpResponseMessage.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/ResponseFuture.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/SessionCache.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/codec/package.html   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/package.html   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/TrustManagerFactoryImpl.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/ssl/package.html   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/AsyncHttpClientException.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateParseException.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/DateUtil.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/EncodingUtil.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/LangUtils.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NameValuePair.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/NeedMoreDataException.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterFormatter.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/ParameterParser.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/util/package.html   (with props)
    geronimo/sandbox/async-http-client-mina2/src/main/javadoc/
    geronimo/sandbox/async-http-client-mina2/src/main/javadoc/overview.html   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/conf/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/conf/keystore   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/conf/web.xml   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/ROOT/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/ROOT/index.jsp   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/ROOT/params.jsp   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/ROOT/pwrd_apache.gif   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/ROOT/redirect.jsp   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/ROOT/timeout.jsp   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_basic/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_basic/WEB-INF/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_basic/WEB-INF/web.xml   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_basic/secure.jsp   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_digest/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_digest/WEB-INF/
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_digest/WEB-INF/web.xml   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/catalina/webapps/auth_digest/secure.jsp   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AbstractTest.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AsyncHttpClientTest.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AsyncHttpClientWithFutureTest.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/AuthTest.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ChunkedTest.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/ConnectionReuseTest.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeIoSession.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeProtocolDecoderOutput.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/FakeRealm.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/RetryTest.java   (with props)
    geronimo/sandbox/async-http-client-mina2/src/test/java/org/apache/ahc/TimeoutTest.java   (with props)

Added: geronimo/sandbox/async-http-client-mina2/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/pom.xml?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/pom.xml (added)
+++ geronimo/sandbox/async-http-client-mina2/pom.xml Sun Dec 30 03:36:47 2007
@@ -0,0 +1,140 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.apache.ahc</groupId>
+    <artifactId>ahc</artifactId>
+    <packaging>jar</packaging>
+    <version>1.0-SNAPSHOT</version>
+    <name>Async Http Client</name>
+    <repositories>
+
+        <repository>
+            <id>apache-snapshots</id>
+            <name>Apache Snapshots Repository</name>
+            <url>http://people.apache.org/repo/m2-snapshot-repository</url>
+            <layout>default</layout>
+            <snapshots>
+                <enabled>true</enabled>
+                <updatePolicy>daily</updatePolicy>
+                <checksumPolicy>ignore</checksumPolicy>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+        </repository>
+    </repositories>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-core</artifactId>
+            <version>2.0.0-M1-SNAPSHOT</version>
+        </dependency>
+        <!--dependency>
+            <groupId>org.apache.mina</groupId>
+            <artifactId>mina-filter-ssl</artifactId>
+            <version>2.0.0-M1-SNAPSHOT</version>
+        </dependency-->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <version>1.4.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat</groupId>
+            <artifactId>catalina</artifactId>
+            <version>6.0.13</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat</groupId>
+            <artifactId>coyote</artifactId>
+            <version>6.0.13</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat</groupId>
+            <artifactId>servlet-api</artifactId>
+            <version>6.0.13</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat.extras</groupId>
+            <artifactId>juli-adapters</artifactId>
+            <version>6.0.13</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat</groupId>
+            <artifactId>jasper</artifactId>
+            <version>6.0.13</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.tomcat</groupId>
+            <artifactId>jasper-jdt</artifactId>
+            <version>6.0.13</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>commons-codec</groupId>
+            <artifactId>commons-codec</artifactId>
+            <version>1.3</version>
+        </dependency>
+    </dependencies>
+    <reporting>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-javadoc-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </reporting>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <forkMode>pertest</forkMode>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>

Propchange: geronimo/sandbox/async-http-client-mina2/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/async-http-client-mina2/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: geronimo/sandbox/async-http-client-mina2/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClient.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClient.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClient.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClient.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,671 @@
+/*
+ *  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;
+
+import java.net.InetSocketAddress;
+import java.security.GeneralSecurityException;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.net.ssl.SSLContext;
+
+import org.apache.ahc.codec.HttpDecoder;
+import org.apache.ahc.codec.HttpIoHandler;
+import org.apache.ahc.codec.HttpProtocolCodecFactory;
+import org.apache.ahc.codec.HttpRequestMessage;
+import org.apache.ahc.codec.ResponseFuture;
+import org.apache.ahc.codec.SessionCache;
+import org.apache.ahc.ssl.TrustManagerFactoryImpl;
+import org.apache.ahc.util.AsyncHttpClientException;
+import org.apache.mina.common.*;
+import org.apache.mina.filter.ssl.SslFilter;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.executor.ExecutorFilter;
+import org.apache.mina.transport.socket.SocketConnector;
+import org.apache.mina.transport.socket.SocketSessionConfig;
+import org.apache.mina.transport.socket.nio.NioSocketConnector;
+import org.apache.mina.transport.socket.nio.NioProcessor;
+
+
+/**
+ * Main class to use for sending asynchronous HTTP requests to servers.
+ * Only one or a few of these objects should be used in an application since
+ * it manages the threads and requests to multiple separate servers/sockets.
+ */
+public class AsyncHttpClient {
+
+    /** The Constant DEFAULT_REUSE_CONNECTION. */
+    public static final boolean DEFAULT_REUSE_CONNECTION = false;
+    
+    /** The Constant DEFAULT_CONNECTION_TIMEOUT. */
+    public static final int DEFAULT_CONNECTION_TIMEOUT = 30000;
+
+    /** The Constant DEFAULT_SSL_PROTOCOL. */
+    public static final String DEFAULT_SSL_PROTOCOL = "TLS";
+
+    /** The Default Reuse Address. */
+    private static final boolean DEFAULT_REUSE_ADDRESS = false;
+
+    /** The Default Receive Buffer Size. */
+    private static final int DEFAULT_RECEIVE_BUFFER_SIZE = 1024;
+
+    /** The Default Send Buffer Size. */
+    private static final int DEFAULT_SEND_BUFFER_SIZE = 1024;
+
+    /** The Default Traffic Class */
+    private static final int DEFAULT_TRAFFIC_CLASS = 0;
+
+    /** The Default Keep Alive. */
+    private static final boolean DEFAULT_KEEP_ALIVE = false;
+
+    /** The Default OOB Inline. */
+    private static final boolean DEFAULT_OOB_INLINE = false;
+
+    /** The Default SO Linger. */
+    private static final int DEFAULT_SO_LINGER = -1;
+
+    /** The Default TCP No Delay. */
+    private static final boolean DEFAULT_TCP_NO_DELAY = false;
+    
+    /** The default number of connection retries */
+    private static final int DEFAULT_CONNECTION_RETRIES = 0; 
+
+    /** The SSL protocol. */
+    private String sslProtocol = DEFAULT_SSL_PROTOCOL;
+
+    /** The connection timeout. */
+    private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
+    
+    /** The default number of retries */
+    private int connectionRetries = DEFAULT_CONNECTION_RETRIES; 
+
+    /** The connector. */
+    private final SocketConnector connector;
+
+    /** The thread pool for I/O processing, and the events and callbacks if 
+     * the optional event thread pool is not provided. */
+    private Executor threadPool;
+    
+    /** The (optional) thread pool for the events and callbacks. */
+    private volatile Executor eventThreadPool;
+    
+    /** The HttpIoHandler handler. */
+    private final HttpIoHandler handler;
+
+    /** connection reuse option */
+    private volatile boolean reuseConnection = DEFAULT_REUSE_CONNECTION;
+    
+    /** The Reuse Address Socket Parameter. */
+    private boolean reuseAddress = DEFAULT_REUSE_ADDRESS;
+
+    /** The Receive Buffer Size Socket Parameter. */
+    private int receiveBufferSize = DEFAULT_RECEIVE_BUFFER_SIZE;
+
+    /** The Send Buffer Size Socket Parameter. */
+    private int sendBufferSize = DEFAULT_SEND_BUFFER_SIZE;
+
+    /** The Traffic Class Socket Parameter. */
+    private int trafficClass = DEFAULT_TRAFFIC_CLASS;
+
+    /** The Keep Alive Socket Parameter. */
+    private boolean keepAlive = DEFAULT_KEEP_ALIVE;
+
+    /** The OOB Inline Socket Parameter. */
+    private boolean oobInline = DEFAULT_OOB_INLINE;
+
+    /** The Default SO Linger Socket Parameter. */
+    private int soLinger = DEFAULT_SO_LINGER;
+
+    /** The TCP No Delay Socket Parameter. */
+    private boolean tcpNoDelay = DEFAULT_TCP_NO_DELAY;
+    
+    /** flag to make this as having been disposed of */
+    private boolean destroyed = false; 
+
+    /**
+     * Returns if it reuses established connections for more requests.
+     * 
+     * @return true if it reuses connections
+     */
+    public boolean isReuseConnection() {
+        return reuseConnection;
+    }
+    
+    /**
+     * Sets if it should reuse established connections for more requests.
+     * 
+     * @param reuseConnection the new value
+     */
+    public void setReuseConnection(boolean reuseConnection) {
+        this.reuseConnection = reuseConnection;
+    }
+    
+    /**
+     * Checks if is reuse address.
+     *
+     * @return true, if is reuse address
+     */
+    public boolean isReuseAddress() {
+        return reuseAddress;
+    }
+
+    /**
+     * Sets the reuse address.
+     *
+     * @param reuseAddress the new reuse address
+     */
+    public void setReuseAddress(boolean reuseAddress) {
+        this.reuseAddress = reuseAddress;
+    }
+
+    /**
+     * Gets the receive buffer size.
+     *
+     * @return the receive buffer size
+     */
+    public int getReceiveBufferSize() {
+        return receiveBufferSize;
+    }
+
+    /**
+     * Sets the receive buffer size.
+     *
+     * @param receiveBufferSize the new receive buffer size
+     */
+    public void setReceiveBufferSize(int receiveBufferSize) {
+        this.receiveBufferSize = receiveBufferSize;
+    }
+
+    /**
+     * Gets the send buffer size.
+     *
+     * @return the send buffer size
+     */
+    public int getSendBufferSize() {
+        return sendBufferSize;
+    }
+
+    /**
+     * Sets the send buffer size.
+     *
+     * @param sendBufferSize the new send buffer size
+     */
+    public void setSendBufferSize(int sendBufferSize) {
+        this.sendBufferSize = sendBufferSize;
+    }
+
+    /**
+     * Gets the traffic class.
+     *
+     * @return the traffic class
+     */
+    public int getTrafficClass() {
+        return trafficClass;
+    }
+
+    /**
+     * Sets the traffic class.
+     *
+     * @param trafficClass the new traffic class
+     */
+    public void setTrafficClass(int trafficClass) {
+        this.trafficClass = trafficClass;
+    }
+
+    /**
+     * Checks if is keep alive.
+     *
+     * @return true, if is keep alive
+     */
+    public boolean isKeepAlive() {
+        return keepAlive;
+    }
+
+    /**
+     * Sets the keep alive.
+     *
+     * @param keepAlive the new keep alive
+     */
+    public void setKeepAlive(boolean keepAlive) {
+        this.keepAlive = keepAlive;
+    }
+
+    /**
+     * Checks if is oob inline.
+     *
+     * @return true, if is oob inline
+     */
+    public boolean isOobInline() {
+        return oobInline;
+    }
+
+    /**
+     * Sets the oob inline.
+     *
+     * @param oobInline the new oob inline
+     */
+    public void setOobInline(boolean oobInline) {
+        this.oobInline = oobInline;
+    }
+
+    /**
+     * Gets the so linger.
+     *
+     * @return the so linger
+     */
+    public int getSoLinger() {
+        return soLinger;
+    }
+
+    /**
+     * Sets the so linger.
+     *
+     * @param soLinger the new so linger
+     */
+    public void setSoLinger(int soLinger) {
+        this.soLinger = soLinger;
+    }
+
+    /**
+     * Checks if is tcp no delay.
+     *
+     * @return true, if is tcp no delay
+     */
+    public boolean isTcpNoDelay() {
+        return tcpNoDelay;
+    }
+
+    /**
+     * Sets the tcp no delay.
+     *
+     * @param tcpNoDelay the new tcp no delay
+     */
+    public void setTcpNoDelay(boolean tcpNoDelay) {
+        this.tcpNoDelay = tcpNoDelay;
+    }
+    
+    /**
+     * Sets the (optional) thread pool for the event processing and callback
+     * invocation.  It is the caller's responsibility to properly dispose of
+     * the thread pool.
+     */
+    public void setEventThreadPool(Executor threadPool) {
+        eventThreadPool = threadPool;
+    }
+    
+    /**
+     * Returns the connection retry count set for this 
+     * client.
+     * 
+     * @return The current connection retry count.
+     */
+    public int getConnectionRetries() {
+        return connectionRetries; 
+    }
+    
+    /**
+     * Sets the number of retries that will be attempted
+     * on connection failures.
+     * 
+     * @param retries The new retry count.
+     */
+    public void setConnectionRetries(int retries) {
+        connectionRetries = retries; 
+    }
+    
+    
+    /**
+     * Instantiates a new AsyncHttpClient.  It will use a single threaded model and is good for
+     * use in one-off connections.
+     */
+    public AsyncHttpClient() {
+        this(DEFAULT_CONNECTION_TIMEOUT, null, null);
+    }
+
+    /**
+     * Instantiates a new AsyncHttpClient.  This will take a thread pool (Executor) to use
+     * for processing connections.
+     *
+     * @param executor  the executor
+     * @param scheduler the scheduler to use to track timeouts
+     */
+    public AsyncHttpClient(Executor executor, ScheduledExecutorService scheduler) {
+        this(DEFAULT_CONNECTION_TIMEOUT, executor, scheduler);
+    }
+
+    /**
+     * Instantiates a new AsyncHttpClient.  Uses a single thread model by default and allows you to specify
+     * a connection timeout.
+     *
+     * @param connectionTimeout the connection timeout in milliseconds.
+     */
+    public AsyncHttpClient(int connectionTimeout) {
+        this(connectionTimeout, null, null);
+    }
+
+    /**
+     * Instantiates a new AsyncHttpClient.  Allows you to specify a connection timeout and an Executor.
+     *
+     * @param connectionTimeout the connection timeout in milliseconds.
+     * @param executor          the ExceutorService to use to process connections.
+     * @param scheduler         the scheduler to use to track timeouts
+     */
+    public AsyncHttpClient(int connectionTimeout, Executor executor, ScheduledExecutorService scheduler) {
+        this.connectionTimeout = connectionTimeout;
+
+        threadPool = executor;
+
+        if (scheduler == null)
+            handler = new HttpIoHandler();
+        else
+            handler = new HttpIoHandler(scheduler);
+
+        if (threadPool == null)
+            connector = new NioSocketConnector();
+        else{
+        //    connector = new NioSocketConnector((Runtime.getRuntime().availableProcessors(), threadPool);
+            connector = new NioSocketConnector(threadPool, new SimpleIoProcessorPool(NioProcessor.class));
+        }
+
+        connector.setHandler(handler);
+
+        applyConnectionTimeout();
+//        connector.setWorkerTimeout(1);
+
+    }
+
+    /**
+     * Sends a request.  The call is non-blocking, and returns a future object
+     * with which the caller can synchronize on the completion of the request.
+     * This does not use a completion queue as provided by the other version of
+     * <code>sendRequest()</code> method.
+     *
+     * @param message the <code>HttpRequestMessage</code> to send to the remote server.
+     * @return a future object that allows tracking of the progress.  If the
+     * future object already exists in the request, then the same future is
+     * returned.
+     * @see HttpRequestMessage
+     */
+    public ResponseFuture sendRequest(HttpRequestMessage message) {
+        return sendRequest(message, null);
+    }
+    
+    /**
+     * Sends a request.  The call is non-blocking, and returns a future object
+     * with which the caller can synchronize on the completion of the request.
+     * Once the call is complete, the future will also be placed in the queue 
+     * that is provided in the arguments.
+     * 
+     * @param message the <code>HttpRequestMessage</code> to send to the remote
+     * server.
+     * @param queue the completion queue on which the future will be added once
+     * it is complete.  May be null.  If the future object already exists in the
+     * request (i.e. <tt>sendRequest()</tt> was called repeatedly on the same
+     * request), then the queue is ignored, and the queue that's associated with
+     * the existing future object will be used.
+     * @return a future object that allows tracking of the progress.  If the
+     * future object already exists in the request, then the same future is
+     * returned.
+     */
+    public ResponseFuture sendRequest(HttpRequestMessage message, 
+            BlockingQueue<ResponseFuture> queue) {
+        if (destroyed) {
+            throw new IllegalStateException("AsyncHttpClient has been destroyed and cannot be reused.");
+        }
+        
+        // we need to provide a new result future and associate it with the
+        // request unless it already exists (i.e. sendRequest() is called
+        // multiple times for the request)
+        if (message.getResponseFuture() == null) {
+            message.setResponseFuture(new ResponseFuture(message, queue));
+        }
+        
+        // *IF* connection reuse is enabled, we should see if we have a cached 
+        // connection first; if not, always open a new one
+        ConnectFuture future = null;
+        if (reuseConnection) {
+            future = getCachedConnection(message);
+        } else {
+            // add the Connection close header explicitly
+            message.setHeader(HttpDecoder.CONNECTION, HttpDecoder.CLOSE);
+        }
+        
+        // if no cached connection is found or keep-alive is disabled, force a
+        // new connection
+        if (future == null) {
+            future = openConnection(message);
+        }
+        ResponseFuture response = message.getResponseFuture();
+        future.addListener(new FutureListener(message, response, connectionRetries));
+        return response;
+    }
+    
+    /**
+     * Retry a connection after a failure.  This will 
+     * create a new connection and try again.
+     * 
+     * @param message  The message request we're sending.
+     * @param response The response future for the message.
+     * @param retries  The number of retries to make for the next connection
+     *                 attempt.  This should be one less than the count
+     *                 used for the previous attempt.
+     */
+    private void retryConnection(HttpRequestMessage message, ResponseFuture response, int retries) {
+        ConnectFuture future = openConnection(message);
+        future.addListener(new FutureListener(message, response, retries));
+    }
+    
+    private ConnectFuture openConnection(HttpRequestMessage message) {
+        return connector.connect((new InetSocketAddress(message.getHost(), message.getPort())));
+    }
+    
+    private ConnectFuture getCachedConnection(HttpRequestMessage message) {
+        IoSession cached = SessionCache.getInstance().getActiveSession(message);
+        if (cached == null) {
+            return null;
+        }
+
+        // create a containing future object and set the session right away
+        ConnectFuture future = new DefaultConnectFuture();
+        future.setSession(cached);
+        return future;
+    }
+
+    /**
+     * Gets the connection timeout.
+     *
+     * @return the connection timeout in milliseconds
+     */
+    public int getConnectionTimeout() {
+        return connectionTimeout;
+    }
+
+    /**
+     * Sets the connection timeout.
+     *
+     * @param connectionTimeout the new connection timeout in milliseconds
+     */
+    public void setConnectionTimeout(int connectionTimeout) {
+        this.connectionTimeout = connectionTimeout;
+        // apply the new connect timeout value to the config
+        applyConnectionTimeout();
+    }
+
+    /** Apply connection timeout. */
+    private void applyConnectionTimeout() {
+        connector.setConnectTimeout(connectionTimeout / 1000);
+    }
+
+    /**
+     * Shuts down the AsyncHttpClient object and releases references to associated thread pools.  
+     * Should always be called when the application is  
+     * done using the object or a hang can occur.
+     */
+    public void destroyAll() {
+        handler.destroy();
+
+        if (connector != null) {
+            connector.dispose();
+            //connector.setWorkerTimeout(0);
+        }
+        // release the thread pool references 
+        threadPool = null; 
+        eventThreadPool = null; 
+        // and mark this as no longer usable. 
+        destroyed = true; 
+    }
+
+    /**
+     * The listener interface for receiving connection events. Its main purpose is to notify the
+     * callback of any exceptions that may have occurred, or to handle the session and inject
+     * the proper SSL filter if the connection is to be used for <code>https</code>.  If a good
+     * connection occurs, it is also responsible for sending the request.
+     */
+    class FutureListener implements IoFutureListener {
+        static final String SSL_FILTER = "SSL";
+        static final String PROTOCOL_FILTER = "protocolFilter";
+        static final String EVENT_THREAD_POOL_FILTER = "eventThreadPoolFilter";
+
+        /** The request. */
+        final HttpRequestMessage request;
+        /** The response future. */
+        final ResponseFuture response;
+        
+        /** The count of additional retries for the connection */
+        int retries = 0; 
+
+        /**
+         * Instantiates a new future listener for a connection.
+         *
+         * @param request the <code>HttpRequestMessage</code> request that is to be sent.
+         * @param response the response future object.
+         */
+        public FutureListener(HttpRequestMessage request, ResponseFuture response, int retries) {
+            this.request = request;
+            this.response = response;
+            this.retries = retries; 
+        }
+
+        /**
+         * Event notification that the conection has completed, either by a successful connection or
+         * by an error.
+         *
+         * @param future the {@link org.apache.mina.common.IoFuture} representing the <code>ConnectFuture</code>.
+         * @see org.apache.mina.common.IoFutureListener#operationComplete(org.apache.mina.common.IoFuture)
+         */
+        public void operationComplete(IoFuture future) {
+            ConnectFuture connFuture = (ConnectFuture) future;
+            if (connFuture.isConnected()) {
+                IoSession sess = future.getSession();
+
+                // see if we need to add the SSL filter
+                addSSLFilter(sess);
+                // add the protocol filter (if it's not there already like in a
+                // reused session)
+                if (!sess.getFilterChain().contains(PROTOCOL_FILTER)) {
+                    sess.getFilterChain().addLast(PROTOCOL_FILTER, new ProtocolCodecFilter(
+                            new HttpProtocolCodecFactory()));
+                }
+                // (optional) add the executor filter for the event thread pool 
+                // (if it's not there already like in a reused session)
+                if (eventThreadPool != null && 
+                        !sess.getFilterChain().contains(EVENT_THREAD_POOL_FILTER)) {
+                    sess.getFilterChain().addLast(EVENT_THREAD_POOL_FILTER, 
+                            new ExecutorFilter(eventThreadPool));
+                }
+                
+                sess.setAttribute(HttpIoHandler.CURRENT_REQUEST, request);
+
+                sess.setAttachment(AsyncHttpClient.this);
+
+                //Set the socket parameters on successfully obtaining the session
+                SocketSessionConfig config = (SocketSessionConfig) sess.getConfig();
+                config.setKeepAlive(keepAlive);
+                config.setOobInline(oobInline);
+                config.setReceiveBufferSize(receiveBufferSize);
+                config.setReuseAddress(reuseAddress);
+                config.setSendBufferSize(sendBufferSize);
+                config.setSoLinger(soLinger);
+                config.setTcpNoDelay(tcpNoDelay);
+                config.setTrafficClass(trafficClass);
+
+                sess.write(request);
+            } else {
+                if (retries > 0) {
+                    // go retry this connection 
+                    retryConnection(request, response, --retries); 
+                }
+                else {
+                    try {
+                        future.getSession();
+                        response.setException(new AsyncHttpClientException("Connection failed."));
+                    } catch (RuntimeIoException e) {
+                        //Set the future exception
+                        response.setException(e);
+                    }
+                }
+            }
+        }
+
+        private void addSSLFilter(IoSession sess) {
+            String scheme = request.getUrl().getProtocol();
+            
+            //Add the https filter
+            if (scheme.toLowerCase().equals("https")) {
+                // add the SSL filter if it's not there already like in a reused
+                // session
+                if (!sess.getFilterChain().contains(SSL_FILTER)) {
+                    try {
+                        SSLContext context = request.getSSLContext();
+                        if (context == null) {
+                            // if the caller did not provide an SSL context
+                            // create a default SSL context
+                            context = createDefaultSSLContext();
+                        }
+                        SslFilter sslFilter = new SslFilter(context);
+                        sslFilter.setUseClientMode(true);
+                        sess.getFilterChain().addLast(SSL_FILTER, sslFilter);
+                    } catch (GeneralSecurityException e) {
+                        try {
+                            sess.getHandler().exceptionCaught(sess, e);
+                        } catch (Exception e1) {
+                            //Do nothing...we just reported it
+                        }
+                    }
+                }
+            }
+        }
+
+        /**
+         * Creates a default SSL context in case it was not provided by the
+         * caller.
+         *
+         * @return the SSL context
+         * @throws GeneralSecurityException the general security exception
+         */
+        private SSLContext createDefaultSSLContext() throws GeneralSecurityException {
+            SSLContext context = SSLContext.getInstance(sslProtocol);
+            context.init(null, TrustManagerFactoryImpl.X509_MANAGERS, null);
+            return context;
+        }
+
+    }
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/AsyncHttpClientCallback.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,60 @@
+/*
+ * 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;
+
+import org.apache.ahc.codec.HttpResponseMessage;
+
+/**
+ * The Interface AsyncHttpClientCallback.  This callback that should be implemented to receive notifications
+ * from the <code>AsyncHttpClient</code>.  The callback implementation is passed as a parameter to a
+ * {@link org.apache.ahc.codec.HttpRequestMessage HttpRequestMessage}.  Each message should have its own 
+ * callback implementation.
+ * @see org.apache.ahc.codec.HttpRequestMessage
+ */
+public interface AsyncHttpClientCallback {
+    
+    /**
+     * Message response event.  Occurs when the {@link AsyncHttpClient} receives a response from the server.
+     * 
+     * @param message the {@link org.apache.ahc.codec.HttpResponseMessage HttpRequestMessage} message response
+     */
+    void onResponse(HttpResponseMessage message);
+    
+    /**
+     * Exception event. Occurs when the {@link AsyncHttpClient} receives any type of Exception from the connection
+     * through the response.
+     * 
+     * @param cause the cause of the Exception
+     */
+    void onException(Throwable cause);
+    
+    /**
+     * Closed event. Occurs when the {@link AsyncHttpClient} closes the connection.  This can occur if
+     * the remote server closes the connection,after an Exception occurred, after a response is sent, or
+     * during the handling of a redirect response.  This simply signals that the socket has closed.
+     */
+    void onClosed();
+    
+    /**
+     * Timeout event.  Occurs when the {@link AsyncHttpClient} times out while waiting for a response from a
+     * remote server.
+     */
+    void onTimeout();
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthChallengeParser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthChallengeParser.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthChallengeParser.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthChallengeParser.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,113 @@
+/*
+ *  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.auth;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.ahc.util.NameValuePair;
+import org.apache.ahc.util.ParameterParser;
+
+public class AuthChallengeParser {
+        /**
+     * Extracts authentication scheme from the given authentication
+     * challenge.
+     *
+     * @param challengeStr the authentication challenge string
+     * @return authentication scheme
+     *
+     * @throws MalformedChallengeException when the authentication challenge string
+     *  is malformed
+     *
+     * @since 2.0beta1
+     */
+    public static String extractScheme(final String challengeStr)
+      throws MalformedChallengeException {
+        if (challengeStr == null) {
+            throw new IllegalArgumentException("Challenge may not be null");
+        }
+        int idx = challengeStr.indexOf(' ');
+        String s = null;
+        if (idx == -1) {
+            s = challengeStr;
+        } else {
+            s = challengeStr.substring(0, idx);
+        }
+        if (s.equals("")) {
+            throw new MalformedChallengeException("Invalid challenge: " + challengeStr);
+        }
+        return s.toLowerCase();
+    }
+
+    /**
+     * Extracts a map of challenge parameters from an authentication challenge.
+     * Keys in the map are lower-cased
+     *
+     * @param challengeStr the authentication challenge string
+     * @return a map of authentication challenge parameters
+     * @throws MalformedChallengeException when the authentication challenge string
+     *  is malformed
+     *
+     * @since 2.0beta1
+     */
+    public static Map extractParams(final String challengeStr)
+      throws MalformedChallengeException {
+        if (challengeStr == null) {
+            throw new IllegalArgumentException("Challenge may not be null");
+        }
+        int idx = challengeStr.indexOf(' ');
+        if (idx == -1) {
+            throw new MalformedChallengeException("Invalid challenge: " + challengeStr);
+        }
+        Map map = new HashMap();
+        ParameterParser parser = new ParameterParser();
+        List params = parser.parse( challengeStr.substring(idx + 1, challengeStr.length()), ',');
+        for (int i = 0; i < params.size(); i++) {
+            NameValuePair param = (NameValuePair) params.get(i);
+            map.put(param.getName().toLowerCase(), param.getValue());
+        }
+        return map;
+    }
+
+    /**
+     * Extracts a map of challenges ordered by authentication scheme name
+     *
+     * @param headers the array of authorization challenges
+     * @return a map of authorization challenges
+     * 
+     * @throws MalformedChallengeException if any of challenge strings
+     *  is malformed
+     */
+//    public static Map parseChallenges(final Header[] headers)
+//      throws MalformedChallengeException {
+//        if (headers == null) {
+//            throw new IllegalArgumentException("Array of challenges may not be null");
+//        }
+//        String challenge = null;
+//        Map challengemap = new HashMap(headers.length);
+//        for (int i = 0; i < headers.length; i++) {
+//            challenge = headers[i].getValue();
+//            String s = AuthChallengeParser.extractScheme(challenge);
+//            challengemap.put(s, challenge);
+//        }
+//        return challengemap;
+//   }
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthPolicy.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthPolicy.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthPolicy.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthPolicy.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,157 @@
+/*
+ *  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.auth;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AuthPolicy {
+    private static final HashMap SCHEMES = new HashMap();
+    private static final ArrayList SCHEME_LIST = new ArrayList();
+
+    /**
+     * The key used to look up the list of IDs of supported {@link AuthScheme
+     * authentication schemes} in their order of preference. The scheme IDs are
+     * stored in a {@link java.util.Collection} as {@link java.lang.String}s.
+     * <p/>
+     * <p/>
+     * If several schemes are returned in the <tt>WWW-Authenticate</tt>
+     * or <tt>Proxy-Authenticate</tt> header, this parameter defines which
+     * {@link AuthScheme authentication schemes} takes precedence over others.
+     * The first item in the collection represents the most preferred
+     * {@link AuthScheme authentication scheme}, the last item represents the ID
+     * of the least preferred one.
+     * </p>
+     *
+     */
+    public static final String AUTH_SCHEME_PRIORITY = "http.auth.scheme-priority";
+
+    /**
+     * The NTLM scheme is a proprietary Microsoft Windows Authentication
+     * protocol (considered to be the most secure among currently supported
+     * authentication schemes).
+     */
+    public static final String NTLM = "NTLM";
+
+    /**
+     * Digest authentication scheme as defined in RFC2617.
+     */
+    public static final String DIGEST = "Digest";
+
+    /**
+     * Basic authentication scheme as defined in RFC2617 (considered inherently
+     * insecure, but most widely supported)
+     */
+    public static final String BASIC = "Basic";
+
+    static {
+        AuthPolicy.registerAuthScheme(NTLM, NTLMScheme.class);
+        AuthPolicy.registerAuthScheme(DIGEST, DigestScheme.class);
+        AuthPolicy.registerAuthScheme(BASIC, BasicScheme.class);
+    }
+
+    /**
+     * Log object.
+     */
+    private static final Logger LOG = LoggerFactory.getLogger(AuthPolicy.class);
+
+    /**
+     * Registers a class implementing an {@link AuthScheme authentication scheme} with
+     * the given identifier. If a class with the given ID already exists it will be overridden.
+     * This ID is the same one used to retrieve the {@link AuthScheme authentication scheme}
+     * from {@link #getAuthScheme(String)}.
+     * <p/>
+     * <p/>
+     * Please note that custom authentication preferences, if used, need to be updated accordingly
+     * for the new {@link AuthScheme authentication scheme} to take effect.
+     * </p>
+     *
+     * @param id    the identifier for this scheme
+     * @param clazz the class to register
+     * @see #getAuthScheme(String)
+     * @see #AUTH_SCHEME_PRIORITY
+     */
+    public static synchronized void registerAuthScheme(final String id, Class clazz) {
+        if (id == null) {
+            throw new IllegalArgumentException("Id may not be null");
+        }
+        if (clazz == null) {
+            throw new IllegalArgumentException("Authentication scheme class may not be null");
+        }
+        SCHEMES.put(id.toLowerCase(), clazz);
+        SCHEME_LIST.add(id.toLowerCase());
+    }
+
+    /**
+     * Unregisters the class implementing an {@link AuthScheme authentication scheme} with
+     * the given ID.
+     *
+     * @param id the ID of the class to unregister
+     */
+    public static synchronized void unregisterAuthScheme(final String id) {
+        if (id == null) {
+            throw new IllegalArgumentException("Id may not be null");
+        }
+        SCHEMES.remove(id.toLowerCase());
+        SCHEME_LIST.remove(id.toLowerCase());
+    }
+
+    /**
+     * Gets the {@link AuthScheme authentication scheme} with the given ID.
+     *
+     * @param id the {@link AuthScheme authentication scheme} ID
+     * @return {@link AuthScheme authentication scheme}
+     * @throws IllegalStateException if a scheme with the ID cannot be found
+     */
+    public static synchronized AuthScheme getAuthScheme(final String id)
+        throws IllegalStateException {
+
+        if (id == null) {
+            throw new IllegalArgumentException("Id may not be null");
+        }
+        Class clazz = (Class)SCHEMES.get(id.toLowerCase());
+        if (clazz != null) {
+            try {
+                return (AuthScheme)clazz.newInstance();
+            } catch (Exception e) {
+                LOG.error("Error initializing authentication scheme: " + id, e);
+                throw new IllegalStateException(id +
+                    " authentication scheme implemented by " +
+                    clazz.getName() + " could not be initialized");
+            }
+        } else {
+            throw new IllegalStateException("Unsupported authentication scheme " + id);
+        }
+    }
+
+    /**
+     * Returns a list containing all registered {@link AuthScheme authentication
+     * schemes} in their default order.
+     *
+     * @return {@link AuthScheme authentication scheme}
+     */
+    public static synchronized List getDefaultAuthPrefs() {
+        return (List)SCHEME_LIST.clone();
+    }
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScheme.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScheme.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScheme.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScheme.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,91 @@
+/*
+ *  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.auth;
+
+import org.apache.ahc.codec.HttpRequestMessage;
+
+public interface AuthScheme {
+    /**
+     * Processes the given challenge token. Some authentication schemes
+     * may involve multiple challenge-response exchanges. Such schemes must be able
+     * to maintain the state information when dealing with sequential challenges
+     *
+     * @param challenge the challenge string
+     */
+    void processChallenge(final String challenge) throws MalformedChallengeException;
+
+    /**
+     * Returns textual designation of the given authentication scheme.
+     *
+     * @return the name of the given authentication scheme
+     */
+    String getSchemeName();
+
+    /**
+     * Returns authentication parameter with the given name, if available.
+     *
+     * @param name The name of the parameter to be returned
+     *
+     * @return the parameter with the given name
+     */
+    String getParameter(final String name);
+
+    /**
+     * Returns authentication realm. If the concept of an authentication
+     * realm is not applicable to the given authentication scheme, returns
+     * <code>null</code>.
+     *
+     * @return the authentication realm
+     */
+    String getRealm();
+
+    /**
+     * Tests if the authentication scheme is provides authorization on a per
+     * connection basis instead of usual per request basis
+     *
+     * @return <tt>true</tt> if the scheme is connection based, <tt>false</tt>
+     * if the scheme is request based.
+     */
+    boolean isConnectionBased();
+
+    /**
+     * Authentication process may involve a series of challenge-response exchanges.
+     * This method tests if the authorization process has been completed, either
+     * successfully or unsuccessfully, that is, all the required authorization
+     * challenges have been processed in their entirety.
+     *
+     * @return <tt>true</tt> if the authentication process has been completed,
+     * <tt>false</tt> otherwise.
+     */
+    boolean isComplete();
+
+    /**
+     * Produces an authorization string for the given set of {@link Credentials}.
+     *
+     * @param credentials The set of credentials to be used for athentication
+     * @param method The method being authenticated
+     * @throws AuthenticationException if authorization string cannot
+     *   be generated due to an authentication failure
+     *
+     * @return the authorization string
+     */
+    String authenticate(Credentials credentials, HttpRequestMessage method) throws AuthenticationException;
+
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthSchemeBase.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthSchemeBase.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthSchemeBase.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthSchemeBase.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,72 @@
+/*
+ *  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.auth;
+
+public class AuthSchemeBase {
+        /**
+     * Original challenge string as received from the server.
+     */
+    private String challenge = null;
+
+    /**
+     * Constructor for an abstract authetication schemes.
+     *
+     * @param challenge authentication challenge
+     *
+     * @throws MalformedChallengeException is thrown if the authentication challenge
+     * is malformed
+     *
+     * @deprecated Use parameterless constructor and {@link AuthScheme#processChallenge(String)}
+     *             method
+     */
+    public AuthSchemeBase(final String challenge)
+      throws MalformedChallengeException {
+        super();
+        if (challenge == null) {
+            throw new IllegalArgumentException("Challenge may not be null");
+        }
+        this.challenge = challenge;
+    }
+
+    /**
+     * @see java.lang.Object#equals(Object)
+     */
+    public boolean equals(Object obj) {
+        if (obj instanceof AuthSchemeBase) {
+            return this.challenge.equals(((AuthSchemeBase) obj).challenge);
+        } else {
+            return super.equals(obj);
+        }
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() {
+        return this.challenge.hashCode();
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return this.challenge;
+    }
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScope.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScope.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScope.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthScope.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,302 @@
+/*
+ *  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.auth;
+
+import org.apache.ahc.util.LangUtils;
+
+public class AuthScope {
+    /**
+     * The <tt>null</tt> value represents any host. In the future versions of
+     * HttpClient the use of this parameter will be discontinued.
+     */
+    public static final String ANY_HOST = null;
+
+    /**
+     * The <tt>-1</tt> value represents any port.
+     */
+    public static final int ANY_PORT = -1;
+
+    /**
+     * The <tt>null</tt> value represents any realm.
+     */
+    public static final String ANY_REALM = null;
+
+    /**
+     * The <tt>null</tt> value represents any authentication scheme.
+     */
+    public static final String ANY_SCHEME = null;
+
+    /**
+     * Default scope matching any host, port, realm and authentication scheme.
+     * In the future versions of HttpClient the use of this parameter will be
+     * discontinued.
+     */
+    public static final AuthScope ANY = new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, ANY_SCHEME);
+
+    /**
+     * The authentication scheme the credentials apply to.
+     */
+    private String scheme = null;
+
+    /**
+     * The realm the credentials apply to.
+     */
+    private String realm = null;
+
+    /**
+     * The host the credentials apply to.
+     */
+    private String host = null;
+
+    /**
+     * The port the credentials apply to.
+     */
+    private int port = -1;
+
+    /**
+     * Creates a new credentials scope for the given
+     * <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and
+     * <tt>authentication scheme</tt>.
+     *
+     * @param host   the host the credentials apply to. May be set
+     *               to <tt>null</tt> if credenticals are applicable to
+     *               any host.
+     * @param port   the port the credentials apply to. May be set
+     *               to negative value if credenticals are applicable to
+     *               any port.
+     * @param realm  the realm the credentials apply to. May be set
+     *               to <tt>null</tt> if credenticals are applicable to
+     *               any realm.
+     * @param scheme the authentication scheme the credentials apply to.
+     *               May be set to <tt>null</tt> if credenticals are applicable to
+     *               any authentication scheme.
+     */
+    public AuthScope(final String host, int port,
+                     final String realm, final String scheme) {
+        this.host = (host == null) ? ANY_HOST : host.toLowerCase();
+        this.port = (port < 0) ? ANY_PORT : port;
+        this.realm = (realm == null) ? ANY_REALM : realm;
+        this.scheme = (scheme == null) ? ANY_SCHEME : scheme.toUpperCase();
+        ;
+    }
+
+    /**
+     * Creates a new credentials scope for the given
+     * <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and any
+     * authentication scheme.
+     *
+     * @param host  the host the credentials apply to. May be set
+     *              to <tt>null</tt> if credenticals are applicable to
+     *              any host.
+     * @param port  the port the credentials apply to. May be set
+     *              to negative value if credenticals are applicable to
+     *              any port.
+     * @param realm the realm the credentials apply to. May be set
+     *              to <tt>null</tt> if credenticals are applicable to
+     *              any realm.
+     */
+    public AuthScope(final String host, int port, final String realm) {
+        this(host, port, realm, ANY_SCHEME);
+    }
+
+    /**
+     * Creates a new credentials scope for the given
+     * <tt>host</tt>, <tt>port</tt>, any realm name, and any
+     * authentication scheme.
+     *
+     * @param host the host the credentials apply to. May be set
+     *             to <tt>null</tt> if credenticals are applicable to
+     *             any host.
+     * @param port the port the credentials apply to. May be set
+     *             to negative value if credenticals are applicable to
+     *             any port.
+     */
+    public AuthScope(final String host, int port) {
+        this(host, port, ANY_REALM, ANY_SCHEME);
+    }
+
+    /**
+     * Creates a copy of the given credentials scope.
+     */
+    public AuthScope(final AuthScope authscope) {
+        super();
+        if (authscope == null) {
+            throw new IllegalArgumentException("Scope may not be null");
+        }
+        this.host = authscope.getHost();
+        this.port = authscope.getPort();
+        this.realm = authscope.getRealm();
+        this.scheme = authscope.getScheme();
+    }
+
+    /**
+     * @return the host
+     */
+    public String getHost() {
+        return this.host;
+    }
+
+    /**
+     * @return the port
+     */
+    public int getPort() {
+        return this.port;
+    }
+
+    /**
+     * @return the realm name
+     */
+    public String getRealm() {
+        return this.realm;
+    }
+
+    /**
+     * @return the scheme type
+     */
+    public String getScheme() {
+        return this.scheme;
+    }
+
+    /**
+     * Determines if the given parameters are equal.
+     *
+     * @param p1 the parameter
+     * @param p2 the other parameter
+     * @return boolean true if the parameters are equal, otherwise false.
+     */
+    private static boolean paramsEqual(final String p1, final String p2) {
+        if (p1 == null) {
+            return p1 == p2;
+        } else {
+            return p1.equals(p2);
+        }
+    }
+
+    /**
+     * Determines if the given parameters are equal.
+     *
+     * @param p1 the parameter
+     * @param p2 the other parameter
+     * @return boolean true if the parameters are equal, otherwise false.
+     */
+    private static boolean paramsEqual(int p1, int p2) {
+        return p1 == p2;
+    }
+
+    /**
+     * Tests if the authentication scopes match.
+     *
+     * @return the match factor. Negative value signifies no match.
+     *         Non-negative signifies a match. The greater the returned value
+     *         the closer the match.
+     */
+    public int match(final AuthScope that) {
+        int factor = 0;
+        if (paramsEqual(this.scheme, that.scheme)) {
+            factor += 1;
+        } else {
+            if (this.scheme != ANY_SCHEME && that.scheme != ANY_SCHEME) {
+                return -1;
+            }
+        }
+        if (paramsEqual(this.realm, that.realm)) {
+            factor += 2;
+        } else {
+            if (this.realm != ANY_REALM && that.realm != ANY_REALM) {
+                return -1;
+            }
+        }
+        if (paramsEqual(this.port, that.port)) {
+            factor += 4;
+        } else {
+            if (this.port != ANY_PORT && that.port != ANY_PORT) {
+                return -1;
+            }
+        }
+        if (paramsEqual(this.host, that.host)) {
+            factor += 8;
+        } else {
+            if (this.host != ANY_HOST && that.host != ANY_HOST) {
+                return -1;
+            }
+        }
+        return factor;
+    }
+
+    /**
+     * @see java.lang.Object#equals(Object)
+     */
+    public boolean equals(Object o) {
+        if (o == null) {
+            return false;
+        }
+        if (o == this) {
+            return true;
+        }
+        if (!(o instanceof AuthScope)) {
+            return super.equals(o);
+        }
+        AuthScope that = (AuthScope)o;
+        return
+            paramsEqual(this.host, that.host)
+                && paramsEqual(this.port, that.port)
+                && paramsEqual(this.realm, that.realm)
+                && paramsEqual(this.scheme, that.scheme);
+    }
+
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+        if (this.scheme != null) {
+            buffer.append(this.scheme.toUpperCase());
+            buffer.append(' ');
+        }
+        if (this.realm != null) {
+            buffer.append('\'');
+            buffer.append(this.realm);
+            buffer.append('\'');
+        } else {
+            buffer.append("<any realm>");
+        }
+        if (this.host != null) {
+            buffer.append('@');
+            buffer.append(this.host);
+            if (this.port >= 0) {
+                buffer.append(':');
+                buffer.append(this.port);
+            }
+        }
+        return buffer.toString();
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode() {
+        int hash = LangUtils.HASH_SEED;
+        hash = LangUtils.hashCode(hash, this.host);
+        hash = LangUtils.hashCode(hash, this.port);
+        hash = LangUtils.hashCode(hash, this.realm);
+        hash = LangUtils.hashCode(hash, this.scheme);
+        return hash;
+    }
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthState.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthState.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthState.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthState.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,175 @@
+/*
+ *  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.auth;
+
+public class AuthState {
+    public static final String PREEMPTIVE_AUTH_SCHEME = "basic";
+
+    /** Actual authentication scheme */
+    private AuthScheme authScheme = null;
+
+    /** Whether an authetication challenged has been received */
+    private boolean authRequested = false;
+
+    /** Whether the authetication challenge has been responsed to */
+    private boolean authAttempted = false;
+
+    /** Whether preemtive authentication is attempted */
+    private boolean preemptive  = false;
+
+    /**
+     * Default constructor.
+     *
+     */
+    public AuthState() {
+        super();
+    }
+
+    /**
+     * Invalidates the authentication state by resetting its parameters.
+     */
+    public void invalidate() {
+        this.authScheme = null;
+        this.authRequested = false;
+        this.authAttempted = false;
+        this.preemptive = false;
+    }
+
+    /**
+     * Tests whether authenication challenge has been received
+     *
+     * @return <tt>true</tt> if authenication challenge has been received,
+     *  <tt>false</tt> otherwise
+     */
+    public boolean isAuthRequested() {
+        return this.authRequested;
+    }
+
+    /**
+     * Sets authentication request status
+     *
+     * @param challengeReceived <tt>true</tt> if authenication has been requested,
+     *  <tt>false</tt> otherwise
+     */
+    public void setAuthRequested(boolean challengeReceived) {
+        this.authRequested = challengeReceived;
+    }
+
+    /**
+     * Tests whether authenication challenge has been responsed to
+     *
+     * @return <tt>true</tt> if authenication challenge has been responsed to,
+     *  <tt>false</tt> otherwise
+     */
+    public boolean isAuthAttempted() {
+        return this.authAttempted;
+    }
+
+    /**
+     * Sets authentication attempt status
+     *
+     * @param challengeResponded <tt>true</tt> if authenication has been attempted,
+     *  <tt>false</tt> otherwise
+     */
+    public void setAuthAttempted(boolean challengeResponded) {
+        this.authAttempted = challengeResponded;
+    }
+
+    /**
+     * Preemptively assigns Basic authentication scheme.
+     */
+    public void setPreemptive() {
+        if (!this.preemptive) {
+            if (this.authScheme != null) {
+                throw new IllegalStateException("Authentication state already initialized");
+            }
+            this.authScheme = AuthPolicy.getAuthScheme(PREEMPTIVE_AUTH_SCHEME);
+            this.preemptive = true;
+        }
+    }
+
+    /**
+     * Tests if preemptive authentication is used.
+     *
+     * @return <tt>true</tt> if using the default Basic {@link AuthScheme
+     * authentication scheme}, <tt>false</tt> otherwise.
+     */
+    public boolean isPreemptive() {
+        return this.preemptive;
+    }
+
+    /**
+     * Assigns the given {@link AuthScheme authentication scheme}.
+     *
+     * @param authScheme the {@link AuthScheme authentication scheme}
+     */
+    public void setAuthScheme(final AuthScheme authScheme) {
+        if (authScheme == null) {
+            invalidate();
+            return;
+        }
+        if (this.preemptive && !(this.authScheme.getClass().isInstance(authScheme))) {
+            this.preemptive = false;
+            this.authAttempted = false;
+        }
+        this.authScheme = authScheme;
+    }
+
+    /**
+     * Returns the {@link AuthScheme authentication scheme}.
+     *
+     * @return {@link AuthScheme authentication scheme}
+     */
+    public AuthScheme getAuthScheme() {
+        return authScheme;
+    }
+
+    /**
+     * Returns the authentication realm.
+     *
+     * @return the name of the authentication realm
+     */
+    public String getRealm() {
+        if (this.authScheme != null) {
+            return this.authScheme.getRealm();
+        } else {
+            return null;
+        }
+    }
+
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+        buffer.append("Auth state: auth requested [");
+        buffer.append(this.authRequested);
+        buffer.append("]; auth attempted [");
+        buffer.append(this.authAttempted);
+        if (this.authScheme != null) {
+            buffer.append("]; auth scheme [");
+            buffer.append(this.authScheme.getSchemeName());
+            buffer.append("]; realm [");
+            buffer.append(this.authScheme.getRealm());
+        }
+        buffer.append("] preemptive [");
+        buffer.append(this.preemptive);
+        buffer.append("]");
+        return buffer.toString();
+    }
+
+}

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

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

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

Added: geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthenticationException.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthenticationException.java?rev=607542&view=auto
==============================================================================
--- geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthenticationException.java (added)
+++ geronimo/sandbox/async-http-client-mina2/src/main/java/org/apache/ahc/auth/AuthenticationException.java Sun Dec 30 03:36:47 2007
@@ -0,0 +1,41 @@
+/*
+ *  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.auth;
+
+import org.apache.ahc.AsyncHttpClient;
+
+public class AuthenticationException extends Exception{
+
+    public AuthenticationException() {
+        super();
+    }
+
+    public AuthenticationException(String string) {
+        super(string);
+    }
+
+    public AuthenticationException(String string, Throwable throwable) {
+        super(string, throwable);
+    }
+
+    public AuthenticationException(Throwable throwable) {
+        super(throwable);
+    }
+}

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

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

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