Added: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/SslSessionConfigListener.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/SslSessionConfigListener.java?rev=890623&view=auto
==============================================================================
--- 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/SslSessionConfigListener.java
 (added)
+++ 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/SslSessionConfigListener.java
 Tue Dec 15 03:15:02 2009
@@ -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.client;
+
+import javax.net.ssl.SSLContext;
+import java.security.GeneralSecurityException;
+
+import org.apache.mina.core.session.IoSession;
+import org.apache.mina.filter.ssl.SslFilter;
+
+import org.apache.ahc.api.HttpRequest;
+import org.apache.ahc.client.api.SessionConfigListener;
+
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class SslSessionConfigListener implements SessionConfigListener
+{
+    public final static String SSL_FILTER = 
SslSessionConfigListener.class.getName() + ".filter";
+
+    public void configure(IoSession session, HttpRequest request)
+    {
+        String scheme = request.getUrl().getProtocol();
+
+        if ("https".equalsIgnoreCase(scheme))
+        {
+            // add the SSL filter if it's not there already, i.e. in a reused 
session
+            if (!session.getFilterChain().contains(SSL_FILTER))
+            {
+                try
+                {
+                    SslFilter sslFilter = createSslFilter(request);
+                    session.getFilterChain().addLast(SSL_FILTER, sslFilter);
+                }
+                catch (GeneralSecurityException e)
+                {
+                    try
+                    {
+                        session.getHandler().exceptionCaught(session, e);
+                    }
+                    catch (Exception ignore)
+                    {
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * Create an SSLFilter instance for this client.  The filter will be
+     * configured using any SSL context defined for the request, or a default
+     * context if one has not been explicitly configured.
+     *
+     * @param request the HTTP request that should be used to create the SSL 
Filter
+     * @return An appropriately configured SSLFilter for this connection.
+     * @throws GeneralSecurityException if there was a problem generating the 
SSL Filter
+     */
+    protected SslFilter createSslFilter(HttpRequest request) throws 
GeneralSecurityException
+    {
+        SslConfig config = request.getConfig(SslConfig.class);
+        SSLContext context = config.getSslContext();
+
+        if (context == null)
+        {
+            // if the caller did not provide an SSL context create a default 
SSL context
+            context = SSLContext.getInstance(config.getSslProtocol());
+            context.init(config.getKeyManagers(), config.getTrustManagers(), 
config.getSecureRandom());
+        }
+
+        SslFilter sslFilter = new SslFilter(context);
+        sslFilter.setUseClientMode(true);
+
+        return sslFilter;
+    }
+}

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/SslSessionConfigListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/SslSessionConfigListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/SslSessionConfigListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/IoSessionCache.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/IoSessionCache.java?rev=890623&view=auto
==============================================================================
--- 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/IoSessionCache.java
 (added)
+++ 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/IoSessionCache.java
 Tue Dec 15 03:15:02 2009
@@ -0,0 +1,37 @@
+/**
+ * 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.client.api;
+
+import java.net.InetSocketAddress;
+
+import org.apache.mina.core.service.IoConnector;
+import org.apache.mina.core.session.IoSession;
+
+import org.apache.ahc.api.HttpConfig;
+
+
+/**
+ * @version $Revision$ $Date$
+ */
+public interface IoSessionCache extends HttpConfig
+{
+    IoSession getIoSession(IoConnector connector, InetSocketAddress address) 
throws Throwable;
+
+    void returnIoSession(IoSession session);
+}

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/IoSessionCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/IoSessionCache.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/IoSessionCache.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/SessionConfigListener.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/SessionConfigListener.java?rev=890623&view=auto
==============================================================================
--- 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/SessionConfigListener.java
 (added)
+++ 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/SessionConfigListener.java
 Tue Dec 15 03:15:02 2009
@@ -0,0 +1,33 @@
+/**
+ * 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.client.api;
+
+import org.apache.mina.core.session.IoSession;
+
+import org.apache.ahc.api.HttpListener;
+import org.apache.ahc.api.HttpRequest;
+
+
+/**
+ * @version $Revision$ $Date$
+ */
+public interface SessionConfigListener extends HttpListener
+{
+    void configure(IoSession session, HttpRequest request);
+}

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/SessionConfigListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/SessionConfigListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: 
mina/sandbox/adc/ahc/src/main/java/org/apache/ahc/client/api/SessionConfigListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/AcmeHttpClient.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/AcmeHttpClient.java?rev=890623&r1=890622&r2=890623&view=diff
==============================================================================
--- mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/AcmeHttpClient.java 
(original)
+++ mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/AcmeHttpClient.java Tue Dec 
15 03:15:02 2009
@@ -19,12 +19,12 @@
 package com.acme.ahc;
 
 import java.net.InetAddress;
-import java.util.concurrent.TimeUnit;
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
-import org.apache.ahc.api.HttpClientFuture;
 import org.apache.ahc.api.HttpBatch;
 import org.apache.ahc.api.HttpClient;
+import org.apache.ahc.api.HttpClientFutureImpl;
 import org.apache.ahc.api.HttpConfig;
 import org.apache.ahc.api.HttpConnection;
 import org.apache.ahc.api.HttpListener;
@@ -43,32 +43,27 @@
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
     }
 
-    public void addConfig(HttpConfig config)
-    {
-        //Todo change body of implemented methods use File | Settings | File 
Templates.
-    }
-
-    public HttpClientFuture<HttpResponse> send(HttpRequest request)
+    public HttpClientFutureImpl<HttpResponse> send(HttpRequest request)
     {
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
     }
 
-    public HttpClientFuture<HttpResponse> get(String url)
+    public HttpClientFutureImpl<HttpResponse> get(String url)
     {
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
     }
 
-    public HttpClientFuture<HttpResponse> post(String url, Map<String, String> 
map, MimeContent... content)
+    public HttpClientFutureImpl<HttpResponse> post(String url, Map<String, 
String> map, MimeContent... content)
     {
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
     }
 
-    public HttpClientFuture<HttpResponse> put(String url, Map<String, String> 
map, MimeContent... content)
+    public HttpClientFutureImpl<HttpResponse> put(String url, Map<String, 
String> map, MimeContent... content)
     {
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
     }
 
-    public HttpClientFuture<HttpResponse> delete(String url)
+    public HttpClientFutureImpl<HttpResponse> delete(String url)
     {
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
     }
@@ -93,6 +88,11 @@
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
     }
 
+    public HttpClient equipWith(HttpConfig config)
+    {
+        return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.
+    }
+
     public HttpClient equipWith(HttpListener listener)
     {
         return null;  //Todo change body of implemented methods use File | 
Settings | File Templates.

Modified: 
mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/listeners/BenchmarkListener.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/listeners/BenchmarkListener.java?rev=890623&r1=890622&r2=890623&view=diff
==============================================================================
--- 
mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/listeners/BenchmarkListener.java
 (original)
+++ 
mina/sandbox/adc/ahc/src/test/java/com/acme/ahc/listeners/BenchmarkListener.java
 Tue Dec 15 03:15:02 2009
@@ -18,8 +18,8 @@
  */
 package com.acme.ahc.listeners;
 
-import org.apache.ahc.api.HttpListener;
 import org.apache.ahc.api.HttpConnection;
+import org.apache.ahc.api.HttpListener;
 
 
 /**

Added: 
mina/sandbox/adc/ahc/src/test/java/org/apache/ahc/client/EquipmentStackTest.java
URL: 
http://svn.apache.org/viewvc/mina/sandbox/adc/ahc/src/test/java/org/apache/ahc/client/EquipmentStackTest.java?rev=890623&view=auto
==============================================================================
--- 
mina/sandbox/adc/ahc/src/test/java/org/apache/ahc/client/EquipmentStackTest.java
 (added)
+++ 
mina/sandbox/adc/ahc/src/test/java/org/apache/ahc/client/EquipmentStackTest.java
 Tue Dec 15 03:15:02 2009
@@ -0,0 +1,318 @@
+/**
+ * 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.client;
+
+import java.util.EmptyStackException;
+import java.util.Set;
+
+import org.apache.ahc.api.HttpConfig;
+import org.apache.ahc.api.HttpListener;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class EquipmentStackTest
+{
+    @Test
+    public void testPropertiesStack() throws Exception
+    {
+        EquipmentStack stack = new EquipmentStack();
+
+        stack.equipWith("FOO", "BAR");
+
+        assertEquals("BAR", stack.get("FOO"));
+
+        stack.push();
+        stack.equipWith("CDR", "CAR");
+        stack.equipWith("FOO", "CAT");
+
+        assertEquals("CAR", stack.get("CDR"));
+        assertEquals("CAT", stack.get("FOO"));
+
+        stack.push();
+
+        assertEquals("CAR", stack.get("CDR"));
+        assertEquals("CAT", stack.get("FOO"));
+
+        stack.pop();
+
+        assertEquals("CAR", stack.get("CDR"));
+        assertEquals("CAT", stack.get("FOO"));
+
+        stack.pop();
+
+        assertEquals(null, stack.get("CAR"));
+        assertEquals("BAR", stack.get("FOO"));
+
+        try
+        {
+            stack.pop();
+            fail("Should have thrown a EmptyStackException");
+        }
+        catch (EmptyStackException ignore)
+        {
+        }
+    }
+
+    @Test
+    @SuppressWarnings({"unchecked"})
+    public void testListeners() throws Exception
+    {
+        EquipmentStack stack = new EquipmentStack();
+
+        stack.equipWith(new A("A1"));
+
+        Set set = stack.getListeners(AListener.class);
+        assertNotNull(set);
+        assertEquals(1, set.size());
+        assertEquals("A1", ((A)set.iterator().next()).getS());
+
+        stack.push();
+        stack.equipWith(new A("A2"));
+
+        set = stack.getListeners(AListener.class);
+        assertNotNull(set);
+        assertEquals(2, set.size());
+        boolean a1 = false, a2 = false;
+        for (A a : (Set<A>)set)
+        {
+            if ("A1".equals(a.getS())) a1 = true;
+            else if ("A2".equals(a.getS())) a2 = true;
+        }
+        assertTrue(a1);
+        assertTrue(a2);
+
+        stack.pop();
+
+        set = stack.getListeners(AListener.class);
+        assertNotNull(set);
+        assertEquals(1, set.size());
+        assertEquals("A1", ((A)set.iterator().next()).getS());
+
+        stack.equipWith(new B("B1"));
+
+        set = stack.getListeners(AListener.class);
+        assertNotNull(set);
+        assertEquals(2, set.size());
+        boolean b1 = false;
+        for (A a : (Set<A>)set)
+        {
+            if ("A1".equals(a.getS())) a1 = true;
+            else if ("B1".equals(a.getS())) b1 = true;
+        }
+        assertTrue(a1);
+        assertTrue(b1);
+
+        stack.equipWith(new C("C1"));
+
+        set = stack.getListeners(AListener.class);
+        assertNotNull(set);
+        assertEquals(3, set.size());
+        boolean c1 = false;
+        for (A a : (Set<A>)set)
+        {
+            if ("A1".equals(a.getS())) a1 = true;
+            else if ("B1".equals(a.getS())) b1 = true;
+            else if ("C1".equals(a.getS())) c1 = true;
+        }
+        assertTrue(a1);
+        assertTrue(b1);
+        assertTrue(c1);
+
+        set = stack.getListeners(CListener.class);
+        assertNotNull(set);
+        assertEquals(1, set.size());
+        a1 = b1 = false;
+        for (A a : (Set<A>)set)
+        {
+            if ("A1".equals(a.getS())) a1 = true;
+            else if ("B1".equals(a.getS())) b1 = true;
+            else if ("C1".equals(a.getS())) c1 = true;
+        }
+        assertFalse(a1);
+        assertFalse(b1);
+        assertTrue(c1);
+
+        stack.equipWith(new D("D1"));
+
+        set = stack.getListeners(AListener.class);
+        assertNotNull(set);
+        assertEquals(4, set.size());
+        boolean d1 = false;
+        for (A a : (Set<A>)set)
+        {
+            if ("A1".equals(a.getS())) a1 = true;
+            else if ("B1".equals(a.getS())) b1 = true;
+            else if ("C1".equals(a.getS())) c1 = true;
+            else if ("D1".equals(a.getS())) d1 = true;
+        }
+        assertTrue(a1);
+        assertTrue(b1);
+        assertTrue(c1);
+        assertTrue(d1);
+
+        set = stack.getListeners(CListener.class);
+        assertNotNull(set);
+        assertEquals(2, set.size());
+        a1 = b1 = false;
+        for (A a : (Set<A>)set)
+        {
+            if ("A1".equals(a.getS())) a1 = true;
+            else if ("B1".equals(a.getS())) b1 = true;
+            else if ("C1".equals(a.getS())) c1 = true;
+            else if ("D1".equals(a.getS())) d1 = true;
+        }
+        assertFalse(a1);
+        assertFalse(b1);
+        assertTrue(c1);
+        assertTrue(d1);
+    }
+
+    @Test
+    public void testConfig() throws Exception
+    {
+        EquipmentStack stack = new EquipmentStack();
+
+        stack.equipWith(new X("X1"));
+
+        X x = stack.getConfig(X.class);
+        assertNotNull(x);
+        assertEquals("X1", x.getS());
+
+        stack.push();
+        stack.equipWith(new X("X2"));
+
+        x = stack.getConfig(X.class);
+        assertNotNull(x);
+        assertEquals("X2", x.getS());
+
+        stack.pop();
+
+        x = stack.getConfig(X.class);
+        assertNotNull(x);
+        assertEquals("X1", x.getS());
+
+        stack.push();
+
+        x = stack.getConfig(X.class);
+        assertNotNull(x);
+        assertEquals("X1", x.getS());
+
+        stack.equipWith(new Y("Y1"));
+
+        x = stack.getConfig(X.class);
+        assertNotNull(x);
+        assertEquals("Y1", x.getS());
+        x = stack.getConfig(Y.class);
+        assertNotNull(x);
+        assertEquals("Y1", x.getS());
+
+        stack.pop();
+
+        x = stack.getConfig(X.class);
+        assertNotNull(x);
+        assertEquals("X1", x.getS());
+    }
+
+    static interface AListener extends HttpListener
+    {
+    }
+
+    static class A implements AListener
+    {
+        private final String s;
+
+        public A(String s)
+        {
+            this.s = s;
+        }
+
+        public String getS()
+        {
+            return s;
+        }
+    }
+
+    static class B extends A
+    {
+        public B(String s)
+        {
+            super(s);
+        }
+    }
+
+    static interface CListener extends AListener
+    {
+    }
+
+    static class C extends B implements CListener
+    {
+        public C(String s)
+        {
+            super(s);
+        }
+    }
+
+    static class D extends C implements CListener, AListener
+    {
+        public D(String s)
+        {
+            super(s);
+        }
+    }
+
+    static class W
+    {
+        private final String s;
+
+        public W(String s)
+        {
+            this.s = s;
+        }
+
+        public String getS()
+        {
+            return s;
+        }
+    }
+
+    static class X extends W implements HttpConfig
+    {
+        public X(String s)
+        {
+            super(s);
+        }
+    }
+
+    static class Y extends X
+    {
+        public Y(String s)
+        {
+            super(s);
+        }
+    }
+}
\ No newline at end of file

Propchange: 
mina/sandbox/adc/ahc/src/test/java/org/apache/ahc/client/EquipmentStackTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
mina/sandbox/adc/ahc/src/test/java/org/apache/ahc/client/EquipmentStackTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Id Author

Propchange: 
mina/sandbox/adc/ahc/src/test/java/org/apache/ahc/client/EquipmentStackTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to