1 /*
2 * ====================================================================
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 * ====================================================================
20 *
21 * This software consists of voluntary contributions made by many
22 * individuals on behalf of the Apache Software Foundation. For more
23 * information on the Apache Software Foundation, please see
24 * <http://www.apache.org/>.
25 *
26 */
27
28 package org.apache.http.impl.nio.reactor;
29
30 import javax.net.ssl.SSLContext;
31 import javax.net.ssl.SSLException;
32
33 import org.apache.http.nio.reactor.IOSession;
34 import org.apache.http.params.HttpParams;
35
36 /**
37 * A decorator class intended to transparently extend an {@link IOSession}
38 * with transport layer security capabilities based on the SSL/TLS protocol.
39 *
40 * @since 4.0
41 *
42 * @deprecated (4.2) use {@link org.apache.http.nio.reactor.ssl.SSLIOSession}
43 */
44 @Deprecated
45 public class SSLIOSession extends org.apache.http.nio.reactor.ssl.SSLIOSession {
46
47 /**
48 * @since 4.1
49 */
50 public SSLIOSession(
51 final IOSession session,
52 final SSLContext sslContext,
53 final SSLSetupHandler handler) {
54 super(session, org.apache.http.nio.reactor.ssl.SSLMode.CLIENT,
55 sslContext, handler != null ? new SSLSetupHandlerAdaptor(handler) : null);
56 }
57
58 public SSLIOSession(
59 final IOSession session,
60 final SSLContext sslContext,
61 final SSLIOSessionHandler handler) {
62 super(session, org.apache.http.nio.reactor.ssl.SSLMode.CLIENT,
63 sslContext, handler != null ? new SSLIOSessionHandlerAdaptor(handler) : null);
64 }
65
66 public synchronized void bind(
67 final SSLMode mode,
68 final HttpParams params) throws SSLException {
69 org.apache.http.nio.reactor.ssl.SSLSetupHandler handler = getSSLSetupHandler();
70 if (handler instanceof SSLIOSessionHandlerAdaptor) {
71 ((SSLIOSessionHandlerAdaptor) handler).setParams(params);
72 } else if (handler instanceof SSLSetupHandlerAdaptor) {
73 ((SSLSetupHandlerAdaptor) handler).setParams(params);
74 }
75 initialize(convert(mode));
76 }
77
78 private org.apache.http.nio.reactor.ssl.SSLMode convert(final SSLMode mode) {
79 switch(mode) {
80 case CLIENT:
81 return org.apache.http.nio.reactor.ssl.SSLMode.CLIENT;
82 case SERVER:
83 return org.apache.http.nio.reactor.ssl.SSLMode.SERVER;
84 }
85 return null;
86 }
87
88 }