KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > httpclient > protocol > SSLProtocolSocketFactory


1 /*
2  * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/protocol/SSLProtocolSocketFactory.java,v 1.5.2.2 2004/02/22 18:21:16 olegk Exp $
3  * $Revision: 1.5.2.2 $
4  * $Date: 2004/02/22 18:21:16 $
5  *
6  * ====================================================================
7  *
8  * Copyright 2002-2004 The Apache Software Foundation
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ====================================================================
22  *
23  * This software consists of voluntary contributions made by many
24  * individuals on behalf of the Apache Software Foundation. For more
25  * information on the Apache Software Foundation, please see
26  * <http://www.apache.org/>.
27  *
28  * [Additional notices, if required by prior licensing conditions]
29  *
30  */

31
32 package org.apache.commons.httpclient.protocol;
33
34 import java.io.IOException JavaDoc;
35 import java.net.InetAddress JavaDoc;
36 import java.net.Socket JavaDoc;
37 import java.net.UnknownHostException JavaDoc;
38
39 import javax.net.ssl.SSLSocketFactory;
40
41 /**
42  * A SecureProtocolSocketFactory that uses JSSE to create sockets.
43  *
44  * @author Michael Becke
45  * @author <a HREF="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
46  *
47  * @since 2.0
48  */

49 public class SSLProtocolSocketFactory implements SecureProtocolSocketFactory {
50
51     /**
52      * The factory singleton.
53      */

54     private static final SSLProtocolSocketFactory factory = new SSLProtocolSocketFactory();
55     
56     /**
57      * Gets an singleton instance of the SSLProtocolSocketFactory.
58      * @return a SSLProtocolSocketFactory
59      */

60     static SSLProtocolSocketFactory getSocketFactory() {
61         return factory;
62     }
63     
64     /**
65      * Constructor for SSLProtocolSocketFactory.
66      */

67     public SSLProtocolSocketFactory() {
68         super();
69     }
70
71     /**
72      * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int)
73      */

74     public Socket JavaDoc createSocket(
75         String JavaDoc host,
76         int port,
77         InetAddress JavaDoc clientHost,
78         int clientPort)
79         throws IOException JavaDoc, UnknownHostException JavaDoc {
80         return SSLSocketFactory.getDefault().createSocket(
81             host,
82             port,
83             clientHost,
84             clientPort
85         );
86     }
87
88     /**
89      * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int)
90      */

91     public Socket JavaDoc createSocket(String JavaDoc host, int port)
92         throws IOException JavaDoc, UnknownHostException JavaDoc {
93         return SSLSocketFactory.getDefault().createSocket(
94             host,
95             port
96         );
97     }
98
99     /**
100      * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean)
101      */

102     public Socket JavaDoc createSocket(
103         Socket JavaDoc socket,
104         String JavaDoc host,
105         int port,
106         boolean autoClose)
107         throws IOException JavaDoc, UnknownHostException JavaDoc {
108         return ((SSLSocketFactory) SSLSocketFactory.getDefault()).createSocket(
109             socket,
110             host,
111             port,
112             autoClose
113         );
114     }
115
116     /**
117      * All instances of SSLProtocolSocketFactory are the same.
118      */

119     public boolean equals(Object JavaDoc obj) {
120         return ((obj != null) && obj.getClass().equals(SSLProtocolSocketFactory.class));
121     }
122
123     /**
124      * All instances of SSLProtocolSocketFactory have the same hash code.
125      */

126     public int hashCode() {
127         return SSLProtocolSocketFactory.class.hashCode();
128     }
129     
130 }
131
Popular Tags