hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1164856 - in /httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http: impl/nio/reactor/ nio/reactor/ssl/
Date Sat, 03 Sep 2011 12:38:12 GMT
Author: olegk
Date: Sat Sep  3 12:38:11 2011
New Revision: 1164856

URL: http://svn.apache.org/viewvc?rev=1164856&view=rev
Log:
Refactored SSL I/O session class; removed dependency on HttpParams; moved SSL I/O session
and related interfaces to public API

Added:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java
  (with props)
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
      - copied, changed from r1164217, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLMode.java
      - copied, changed from r1164217, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLMode.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLSetupHandler.java
      - copied, changed from r1164217, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java
Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSessionHandlerAdaptor.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java?rev=1164856&r1=1164855&r2=1164856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
Sat Sep  3 12:38:11 2011
@@ -27,49 +27,22 @@
 
 package org.apache.http.impl.nio.reactor;
 
-import org.apache.http.annotation.ThreadSafe;
-import org.apache.http.nio.reactor.EventMask;
-import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.nio.reactor.SessionBufferStatus;
-import org.apache.http.params.HttpParams;
-
 import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLEngine;
-import javax.net.ssl.SSLEngineResult;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.SSLEngineResult.HandshakeStatus;
-import javax.net.ssl.SSLEngineResult.Status;
 import javax.net.ssl.SSLException;
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.ByteChannel;
-import java.nio.channels.SelectionKey;
+
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.params.HttpParams;
 
 /**
  * A decorator class intended to transparently extend an {@link IOSession}
  * with transport layer security capabilities based on the SSL/TLS protocol.
  *
  * @since 4.0
+ *
+ * @deprecated use {@link org.apache.http.nio.reactor.ssl.SSLIOSession}
  */
-@ThreadSafe
-public class SSLIOSession implements IOSession, SessionBufferStatus {
-
-    private final IOSession session;
-    private final SSLEngine sslEngine;
-    private final ByteBuffer inEncrypted;
-    private final ByteBuffer outEncrypted;
-    private final ByteBuffer inPlain;
-    private final ByteBuffer outPlain;
-    private final InternalByteChannel channel;
-    private final SSLSetupHandler handler;
-
-    private int appEventMask;
-    private SessionBufferStatus appBufferStatus;
-
-    private boolean endOfStream;
-    private volatile int status;
+@Deprecated
+public class SSLIOSession extends org.apache.http.nio.reactor.ssl.SSLIOSession {
 
     /**
      * @since 4.1
@@ -78,468 +51,38 @@ public class SSLIOSession implements IOS
             final IOSession session,
             final SSLContext sslContext,
             final SSLSetupHandler handler) {
-        super();
-        if (session == null) {
-            throw new IllegalArgumentException("IO session may not be null");
-        }
-        if (sslContext == null) {
-            throw new IllegalArgumentException("SSL context may not be null");
-        }
-        this.session = session;
-        this.appEventMask = session.getEventMask();
-        this.channel = new InternalByteChannel();
-        this.handler = handler;
-
-        // Override the status buffer interface
-        this.session.setBufferStatus(this);
-
-        SocketAddress address = session.getRemoteAddress();
-        if (address instanceof InetSocketAddress) {
-            String hostname = ((InetSocketAddress) address).getHostName();
-            int port = ((InetSocketAddress) address).getPort();
-            this.sslEngine = sslContext.createSSLEngine(hostname, port);
-        } else {
-            this.sslEngine = sslContext.createSSLEngine();
-        }
-
-        // Allocate buffers for network (encrypted) data
-        int netBuffersize = this.sslEngine.getSession().getPacketBufferSize();
-        this.inEncrypted = ByteBuffer.allocate(netBuffersize);
-        this.outEncrypted = ByteBuffer.allocate(netBuffersize);
-
-        // Allocate buffers for application (unencrypted) data
-        int appBuffersize = this.sslEngine.getSession().getApplicationBufferSize();
-        this.inPlain = ByteBuffer.allocate(appBuffersize);
-        this.outPlain = ByteBuffer.allocate(appBuffersize);
+        super(session, org.apache.http.nio.reactor.ssl.SSLMode.CLIENT,
+                sslContext, handler != null ? new SSLSetupHandlerAdaptor(handler) : null);
     }
 
-    /**
-     * @deprecated
-     */
-    @Deprecated
     public SSLIOSession(
             final IOSession session,
             final SSLContext sslContext,
             final SSLIOSessionHandler handler) {
-        this(session, sslContext, handler != null ? new SSLIOSessionHandlerAdaptor(handler)
: null);
+        super(session, org.apache.http.nio.reactor.ssl.SSLMode.CLIENT,
+                sslContext, handler != null ? new SSLIOSessionHandlerAdaptor(handler) : null);
     }
 
     public synchronized void bind(
             final SSLMode mode,
             final HttpParams params) throws SSLException {
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
-        switch (mode) {
-        case CLIENT:
-            this.sslEngine.setUseClientMode(true);
-            break;
-        case SERVER:
-            this.sslEngine.setUseClientMode(false);
-            break;
-        }
-        if (this.handler != null) {
-            this.handler.initalize(this.sslEngine, params);
-        }
-        this.sslEngine.beginHandshake();
-        doHandshake();
-    }
-
-    /**
-     * @since 4.2
-     */
-    public synchronized SSLSession getSSLSession() {
-        return this.sslEngine.getSession();
-    }
-
-    // A works-around for exception handling craziness in Sun/Oracle's SSLEngine
-    // implementation.
-    //
-    // sun.security.pkcs11.wrapper.PKCS11Exception is re-thrown as
-    // plain RuntimeException in sun.security.ssl.Handshaker#checkThrown
-    private SSLException convert(final RuntimeException ex) throws SSLException {
-		Throwable cause = ex.getCause();
-		if (cause == null) {
-			cause = ex;
-		}
-		return new SSLException(cause);
-    }
-
-    private SSLEngineResult doWrap(final ByteBuffer src, final ByteBuffer dst) throws SSLException
{
-    	try {
-        	return this.sslEngine.wrap(src, dst);
-    	} catch (RuntimeException ex) {
-    		throw convert(ex);
-    	}
-    }
-
-    private SSLEngineResult doUnwrap(final ByteBuffer src, final ByteBuffer dst) throws SSLException
{
-    	try {
-        	return this.sslEngine.unwrap(src, dst);
-    	} catch (RuntimeException ex) {
-    		throw convert(ex);
-    	}
-    }
-
-    private void doRunTask() throws SSLException {
-    	try {
-            Runnable r = this.sslEngine.getDelegatedTask();
-            if (r != null) {
-            	r.run();
-            }
-    	} catch (RuntimeException ex) {
-    		throw convert(ex);
-    	}
-    }
-
-    private void doHandshake() throws SSLException {
-        boolean handshaking = true;
-
-        SSLEngineResult result = null;
-        while (handshaking) {
-            switch (this.sslEngine.getHandshakeStatus()) {
-            case NEED_WRAP:
-                // Generate outgoing handshake data
-                this.outPlain.flip();
-                result = doWrap(this.outPlain, this.outEncrypted);
-                this.outPlain.compact();
-                if (result.getStatus() != Status.OK) {
-                    handshaking = false;
-                }
-                break;
-            case NEED_UNWRAP:
-                // Process incoming handshake data
-                this.inEncrypted.flip();
-                result = doUnwrap(this.inEncrypted, this.inPlain);
-                this.inEncrypted.compact();
-                if (result.getStatus() != Status.OK) {
-                    handshaking = false;
-                }
-                break;
-            case NEED_TASK:
-            	doRunTask();
-                break;
-            case NOT_HANDSHAKING:
-                handshaking = false;
-                break;
-            case FINISHED:
-                break;
-            }
-        }
-
-        // The SSLEngine has just finished handshaking. This value is only generated by a
call
-        // to SSLEngine.wrap()/unwrap() when that call finishes a handshake.
-        // It is never generated by SSLEngine.getHandshakeStatus().
-        if (result != null && result.getHandshakeStatus() == HandshakeStatus.FINISHED)
{
-            if (this.handler != null) {
-                this.handler.verify(this.session, this.sslEngine.getSession());
-            }
-        }
-    }
-
-    private void updateEventMask() {
-        if (this.status == CLOSING && this.sslEngine.isOutboundDone()
-                && (this.endOfStream || this.sslEngine.isInboundDone())) {
-            this.status = CLOSED;
-        }
-        if (this.status == CLOSED) {
-            this.session.close();
-            return;
-        }
-        // Need to toggle the event mask for this channel?
-        int oldMask = this.session.getEventMask();
-        int newMask = oldMask;
-        switch (this.sslEngine.getHandshakeStatus()) {
-        case NEED_WRAP:
-            newMask = EventMask.READ_WRITE;
-            break;
-        case NEED_UNWRAP:
-            newMask = EventMask.READ;
-            break;
-        case NOT_HANDSHAKING:
-            newMask = this.appEventMask;
-            break;
-        case NEED_TASK:
-            break;
-        case FINISHED:
-            break;
-        }
-
-        // Do we have encrypted data ready to be sent?
-        if (this.outEncrypted.position() > 0) {
-            newMask = newMask | EventMask.WRITE;
-        }
-
-        // Update the mask if necessary
-        if (oldMask != newMask) {
-            this.session.setEventMask(newMask);
-        }
-    }
-
-    private int sendEncryptedData() throws IOException {
-        this.outEncrypted.flip();
-        int bytesWritten = this.session.channel().write(this.outEncrypted);
-        this.outEncrypted.compact();
-        return bytesWritten;
-    }
-
-    private int receiveEncryptedData() throws IOException {
-        if (this.endOfStream) {
-            return -1;
-        }
-        return this.session.channel().read(this.inEncrypted);
-    }
-
-    private boolean decryptData() throws SSLException {
-        boolean decrypted = false;
-        SSLEngineResult.Status opStatus = Status.OK;
-        while (this.inEncrypted.position() > 0 && opStatus == Status.OK) {
-            this.inEncrypted.flip();
-            SSLEngineResult result = doUnwrap(this.inEncrypted, this.inPlain);
-            this.inEncrypted.compact();
-
-            opStatus = result.getStatus();
-            if (opStatus == Status.OK) {
-                decrypted = true;
-            }
-        }
-        return decrypted;
-    }
-
-    public synchronized boolean isAppInputReady() throws IOException {
-        int bytesRead = receiveEncryptedData();
-        if (bytesRead == -1) {
-            this.endOfStream = true;
-        }
-        doHandshake();
-        decryptData();
-        // Some decrypted data is available or at the end of stream
-        return (this.appEventMask & SelectionKey.OP_READ) > 0
-            && (this.inPlain.position() > 0
-                    || (this.appBufferStatus != null && this.appBufferStatus.hasBufferedInput())
-                    || (this.endOfStream && this.status == ACTIVE));
-    }
-
-    /**
-     * @throws IOException - not thrown currently
-     */
-    public synchronized boolean isAppOutputReady() throws IOException {
-        return (this.appEventMask & SelectionKey.OP_WRITE) > 0
-            && this.status == ACTIVE
-            && this.sslEngine.getHandshakeStatus() == HandshakeStatus.NOT_HANDSHAKING;
-    }
-
-    /**
-     * @throws IOException - not thrown currently
-     */
-    public synchronized void inboundTransport() throws IOException {
-        updateEventMask();
-    }
-
-    public synchronized void outboundTransport() throws IOException {
-        sendEncryptedData();
-        doHandshake();
-        updateEventMask();
-    }
-
-    private synchronized int writePlain(final ByteBuffer src) throws SSLException {
-        if (src == null) {
-            throw new IllegalArgumentException("Byte buffer may not be null");
-        }
-        if (this.status != ACTIVE) {
-            return -1;
-        }
-        if (this.outPlain.position() > 0) {
-            this.outPlain.flip();
-            doWrap(this.outPlain, this.outEncrypted);
-            this.outPlain.compact();
-        }
-        if (this.outPlain.position() == 0) {
-            SSLEngineResult result = doWrap(src, this.outEncrypted);
-            if (result.getStatus() == Status.CLOSED) {
-                this.status = CLOSED;
-            }
-            return result.bytesConsumed();
-        } else {
-            return 0;
-        }
-    }
-
-    /**
-     * @throws SSLException - not thrown currently
-     */
-    private synchronized int readPlain(final ByteBuffer dst) throws SSLException {
-        if (dst == null) {
-            throw new IllegalArgumentException("Byte buffer may not be null");
-        }
-        if (this.inPlain.position() > 0) {
-            this.inPlain.flip();
-            int n = Math.min(this.inPlain.remaining(), dst.remaining());
-            for (int i = 0; i < n; i++) {
-                dst.put(this.inPlain.get());
-            }
-            this.inPlain.compact();
-            return n;
-        } else {
-            if (this.endOfStream) {
-                return -1;
-            } else {
-                return 0;
-            }
-        }
-    }
-
-    public synchronized void close() {
-        if (this.status >= CLOSING) {
-            return;
-        }
-        this.status = CLOSING;
-        this.sslEngine.closeOutbound();
-        updateEventMask();
-    }
-
-    public synchronized void shutdown() {
-        if (this.status == CLOSED) {
-            return;
+        org.apache.http.nio.reactor.ssl.SSLSetupHandler handler = getSSLSetupHandler();
+        if (handler instanceof SSLIOSessionHandlerAdaptor) {
+            ((SSLIOSessionHandlerAdaptor) handler).setParams(params);
+        } else if (handler instanceof SSLSetupHandlerAdaptor) {
+            ((SSLSetupHandlerAdaptor) handler).setParams(params);
         }
-        this.status = CLOSED;
-        this.session.shutdown();
-    }
-
-    public int getStatus() {
-        return this.status;
-    }
-
-    public boolean isClosed() {
-        return this.status >= CLOSING;
-    }
-
-    public synchronized boolean isInboundDone() {
-        return this.sslEngine.isInboundDone();
-    }
-
-    public synchronized boolean isOutboundDone() {
-        return this.sslEngine.isOutboundDone();
+        initialize(convert(mode));
     }
 
-    public ByteChannel channel() {
-        return this.channel;
-    }
-
-    public SocketAddress getLocalAddress() {
-        return this.session.getLocalAddress();
-    }
-
-    public SocketAddress getRemoteAddress() {
-        return this.session.getRemoteAddress();
-    }
-
-    public synchronized int getEventMask() {
-        return this.appEventMask;
-    }
-
-    public synchronized void setEventMask(int ops) {
-        this.appEventMask = ops;
-        updateEventMask();
-    }
-
-    public synchronized void setEvent(int op) {
-        this.appEventMask = this.appEventMask | op;
-        updateEventMask();
-    }
-
-    public synchronized void clearEvent(int op) {
-        this.appEventMask = this.appEventMask & ~op;
-        updateEventMask();
-    }
-
-    public int getSocketTimeout() {
-        return this.session.getSocketTimeout();
-    }
-
-    public void setSocketTimeout(int timeout) {
-        this.session.setSocketTimeout(timeout);
-    }
-
-    public synchronized boolean hasBufferedInput() {
-        return (this.appBufferStatus != null && this.appBufferStatus.hasBufferedInput())
-            || this.inEncrypted.position() > 0
-            || this.inPlain.position() > 0;
-    }
-
-    public synchronized boolean hasBufferedOutput() {
-        return (this.appBufferStatus != null && this.appBufferStatus.hasBufferedOutput())
-            || this.outEncrypted.position() > 0
-            || this.outPlain.position() > 0;
-    }
-
-    public synchronized void setBufferStatus(final SessionBufferStatus status) {
-        this.appBufferStatus = status;
-    }
-
-    public Object getAttribute(final String name) {
-        return this.session.getAttribute(name);
-    }
-
-    public Object removeAttribute(final String name) {
-        return this.session.removeAttribute(name);
-    }
-
-    public void setAttribute(final String name, final Object obj) {
-        this.session.setAttribute(name, obj);
-    }
-
-    @Override
-    public String toString() {
-        StringBuilder buffer = new StringBuilder();
-        buffer.append(this.session);
-        buffer.append("[");
-        switch (this.status) {
-        case ACTIVE:
-            buffer.append("ACTIVE");
-            break;
-        case CLOSING:
-            buffer.append("CLOSING");
-            break;
-        case CLOSED:
-            buffer.append("CLOSED");
-            break;
-        }
-        buffer.append("][");
-        buffer.append(this.sslEngine.getHandshakeStatus());
-        if (this.endOfStream) {
-            buffer.append("][EOF][");
-        }
-        buffer.append("][");
-        buffer.append(this.inEncrypted.position());
-        buffer.append("][");
-        buffer.append(this.inPlain.position());
-        buffer.append("][");
-        buffer.append(this.outEncrypted.position());
-        buffer.append("][");
-        buffer.append(this.outPlain.position());
-        buffer.append("]");
-        return buffer.toString();
-    }
-
-    private class InternalByteChannel implements ByteChannel {
-
-        public int write(final ByteBuffer src) throws IOException {
-            return SSLIOSession.this.writePlain(src);
-        }
-
-        public int read(final ByteBuffer dst) throws IOException {
-            return SSLIOSession.this.readPlain(dst);
-        }
-
-        public void close() throws IOException {
-            SSLIOSession.this.close();
-        }
-
-        public boolean isOpen() {
-            return !SSLIOSession.this.isClosed();
+    private org.apache.http.nio.reactor.ssl.SSLMode convert(final SSLMode mode) {
+        switch(mode) {
+        case CLIENT:
+            return org.apache.http.nio.reactor.ssl.SSLMode.CLIENT;
+        case SERVER:
+            return org.apache.http.nio.reactor.ssl.SSLMode.SERVER;
         }
-
+        return null;
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSessionHandlerAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSessionHandlerAdaptor.java?rev=1164856&r1=1164855&r2=1164856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSessionHandlerAdaptor.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSessionHandlerAdaptor.java
Sat Sep  3 12:38:11 2011
@@ -32,24 +32,31 @@ import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLSession;
 
 import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpParams;
 
 @Deprecated
-class SSLIOSessionHandlerAdaptor implements SSLSetupHandler {
+class SSLIOSessionHandlerAdaptor implements org.apache.http.nio.reactor.ssl.SSLSetupHandler
{
 
     private final SSLIOSessionHandler handler;
 
+    private HttpParams params;
+
     public SSLIOSessionHandlerAdaptor(final SSLIOSessionHandler handler) {
         super();
         this.handler = handler;
     }
 
-    public void initalize(final SSLEngine sslengine, final HttpParams params) throws SSLException
{
-        this.handler.initalize(sslengine, params);
+    public void initalize(final SSLEngine sslengine) throws SSLException {
+        this.handler.initalize(sslengine, this.params != null ? this.params : new BasicHttpParams());
     }
 
     public void verify(final IOSession iosession, final SSLSession sslsession) throws SSLException
{
         this.handler.verify(iosession.getRemoteAddress(), sslsession);
     }
 
+    public void setParams(final HttpParams params) {
+        this.params = params;
+    }
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java?rev=1164856&r1=1164855&r2=1164856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java
Sat Sep  3 12:38:11 2011
@@ -39,7 +39,10 @@ import org.apache.http.params.HttpParams
  * the TLS/SSl protocol.
  *
  * @since 4.1
+ *
+ * @deprecated use {@link org.apache.http.nio.reactor.ssl.SSLSetupHandler}
  */
+@Deprecated
 public interface SSLSetupHandler {
 
     /**

Added: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java?rev=1164856&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java
(added)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java
Sat Sep  3 12:38:11 2011
@@ -0,0 +1,62 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.nio.reactor;
+
+import javax.net.ssl.SSLEngine;
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLSession;
+
+import org.apache.http.nio.reactor.IOSession;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
+
+@Deprecated
+class SSLSetupHandlerAdaptor implements org.apache.http.nio.reactor.ssl.SSLSetupHandler {
+
+    private final SSLSetupHandler handler;
+
+    private HttpParams params;
+
+    public SSLSetupHandlerAdaptor(final SSLSetupHandler handler) {
+        super();
+        this.handler = handler;
+    }
+
+    public void initalize(final SSLEngine sslengine) throws SSLException {
+        this.handler.initalize(sslengine, this.params != null ? this.params : new BasicHttpParams());
+    }
+
+    public void verify(final IOSession iosession, final SSLSession sslsession) throws SSLException
{
+        this.handler.verify(iosession, sslsession);
+    }
+
+    public void setParams(final HttpParams params) {
+        this.params = params;
+    }
+
+}

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
(from r1164217, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java&r1=1164217&r2=1164856&rev=1164856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLIOSession.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLIOSession.java
Sat Sep  3 12:38:11 2011
@@ -25,13 +25,12 @@
  *
  */
 
-package org.apache.http.impl.nio.reactor;
+package org.apache.http.nio.reactor.ssl;
 
 import org.apache.http.annotation.ThreadSafe;
 import org.apache.http.nio.reactor.EventMask;
 import org.apache.http.nio.reactor.IOSession;
 import org.apache.http.nio.reactor.SessionBufferStatus;
-import org.apache.http.params.HttpParams;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
@@ -51,12 +50,13 @@ import java.nio.channels.SelectionKey;
  * A decorator class intended to transparently extend an {@link IOSession}
  * with transport layer security capabilities based on the SSL/TLS protocol.
  *
- * @since 4.0
+ * @since 4.2
  */
 @ThreadSafe
 public class SSLIOSession implements IOSession, SessionBufferStatus {
 
     private final IOSession session;
+    private final SSLMode defaultMode;
     private final SSLEngine sslEngine;
     private final ByteBuffer inEncrypted;
     private final ByteBuffer outEncrypted;
@@ -71,11 +71,9 @@ public class SSLIOSession implements IOS
     private boolean endOfStream;
     private volatile int status;
 
-    /**
-     * @since 4.1
-     */
     public SSLIOSession(
             final IOSession session,
+            final SSLMode defaultMode,
             final SSLContext sslContext,
             final SSLSetupHandler handler) {
         super();
@@ -86,6 +84,7 @@ public class SSLIOSession implements IOS
             throw new IllegalArgumentException("SSL context may not be null");
         }
         this.session = session;
+        this.defaultMode = defaultMode;
         this.appEventMask = session.getEventMask();
         this.channel = new InternalByteChannel();
         this.handler = handler;
@@ -113,23 +112,11 @@ public class SSLIOSession implements IOS
         this.outPlain = ByteBuffer.allocate(appBuffersize);
     }
 
-    /**
-     * @deprecated
-     */
-    @Deprecated
-    public SSLIOSession(
-            final IOSession session,
-            final SSLContext sslContext,
-            final SSLIOSessionHandler handler) {
-        this(session, sslContext, handler != null ? new SSLIOSessionHandlerAdaptor(handler)
: null);
+    protected SSLSetupHandler getSSLSetupHandler() {
+        return this.handler;
     }
 
-    public synchronized void bind(
-            final SSLMode mode,
-            final HttpParams params) throws SSLException {
-        if (params == null) {
-            throw new IllegalArgumentException("HTTP parameters may not be null");
-        }
+    public synchronized void initialize(final SSLMode mode) throws SSLException {
         switch (mode) {
         case CLIENT:
             this.sslEngine.setUseClientMode(true);
@@ -139,15 +126,16 @@ public class SSLIOSession implements IOS
             break;
         }
         if (this.handler != null) {
-            this.handler.initalize(this.sslEngine, params);
+            this.handler.initalize(this.sslEngine);
         }
         this.sslEngine.beginHandshake();
         doHandshake();
     }
 
-    /**
-     * @since 4.2
-     */
+    public void initialize() throws SSLException {
+        initialize(this.defaultMode);
+    }
+
     public synchronized SSLSession getSSLSession() {
         return this.sslEngine.getSession();
     }

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLMode.java
(from r1164217, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLMode.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLMode.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLMode.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLMode.java&r1=1164217&r2=1164856&rev=1164856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLMode.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLMode.java
Sat Sep  3 12:38:11 2011
@@ -25,10 +25,10 @@
  *
  */
 
-package org.apache.http.impl.nio.reactor;
+package org.apache.http.nio.reactor.ssl;
 
 /**
- * @since 4.0
+ * @since 4.2
  */
 public enum SSLMode {
 

Copied: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLSetupHandler.java
(from r1164217, httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLSetupHandler.java?p2=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLSetupHandler.java&p1=httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java&r1=1164217&r2=1164856&rev=1164856&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SSLSetupHandler.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLSetupHandler.java
Sat Sep  3 12:38:11 2011
@@ -25,14 +25,13 @@
  *
  */
 
-package org.apache.http.impl.nio.reactor;
+package org.apache.http.nio.reactor.ssl;
 
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.SSLSession;
 
 import org.apache.http.nio.reactor.IOSession;
-import org.apache.http.params.HttpParams;
 
 /**
  * Callback interface that can be used to customize various aspects of
@@ -51,8 +50,7 @@ public interface SSLSetupHandler {
      * @param params HTTP parameters.
      * @throws SSLException if case of SSL protocol error.
      */
-    void initalize(SSLEngine sslengine, HttpParams params)
-        throws SSLException;
+    void initalize(SSLEngine sslengine) throws SSLException;
 
     /**
      * Triggered when the SSL connection has been established and initial SSL
@@ -65,7 +63,6 @@ public interface SSLSetupHandler {
      * @param sslsession newly created SSL session.
      * @throws SSLException if case of SSL protocol error.
      */
-    void verify(IOSession iosession, SSLSession sslsession)
-        throws SSLException;
+    void verify(IOSession iosession, SSLSession sslsession) throws SSLException;
 
 }



Mime
View raw message