01: /*
02: * SSLSupport.java
03: *
04: * Copyright (C) 2000 Jacob Smullyan
05: *
06: * This file is a supplement to the HTTPClient package by Ronald Tschalär,
07: * Copyright (C) 1996-1999 Ronald Tschalär, and the same license holds.
08: *
09: * This library is free software; you can redistribute it and/or
10: * modify it under the terms of the GNU Lesser General Public
11: * License as published by the Free Software Foundation; either
12: * version 2 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful,
15: * but WITHOUT ANY WARRANTY; without even the implied warranty of
16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17: * Lesser General Public License for more details.
18: *
19: * You should have received a copy of the GNU Lesser General Public
20: * License along with this library; if not, write to the Free
21: * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22: * MA 02111-1307, USA
23: *
24: * For questions, suggestions, bug-reports, enhancement-requests etc.
25: * I may be contacted at:
26: *
27: * ronald@innovation.ch
28: *
29: */
30: package HTTPClient;
31:
32: import java.io.InputStream;
33: import java.io.IOException;
34: import java.net.Socket;
35: import java.util.Properties;
36:
37: /**
38: * A wrapper which helps to the HTTPClient package for
39: * SSL support with Sun's JSSE while making it possible
40: * use the patched client, sans SSL capability, without
41: * the JSSE jars.
42: */
43: public abstract class SSLSupport {
44: public static final String SSL_PROPERTIES = "ssl.properties";
45: public static final String DEFAULT_SSL_SUPPORT_CLASS_PROPERTY = "sslSupportClass";
46: public static final String DEFAULT_SSL_SUPPORT_CLASS = "HTTPClient.jsse.JsseSSLSupport";
47: private static Properties sslProperties;
48: private static SSLSupport defaultSupport = null;
49: private static Boolean canSupport = null;
50:
51: static {
52: sslProperties = new Properties();
53: try {
54: InputStream in = SSLSupport.class
55: .getResourceAsStream(SSL_PROPERTIES);
56: if (in != null)
57: sslProperties.load(in);
58: } catch (Exception oyVeh) {
59: //do nothing
60: }
61: }
62:
63: public static SSLSupport getDefault() {
64: try {
65: Class supportClass = Class
66: .forName(getDefaultSupportClass());
67: defaultSupport = (SSLSupport) supportClass.newInstance();
68: canSupport = new Boolean(true);
69: return defaultSupport;
70: } catch (ClassNotFoundException candida) {
71: //good, we expect this
72: canSupport = new Boolean(false);
73: return null;
74: } catch (Exception e) {
75: //don't know what this is
76: e.printStackTrace();
77: canSupport = new Boolean(false);
78: return null;
79: }
80: }
81:
82: protected static String getDefaultSupportClass() {
83: return sslProperties.getProperty(
84: DEFAULT_SSL_SUPPORT_CLASS_PROPERTY,
85: DEFAULT_SSL_SUPPORT_CLASS);
86: }
87:
88: public static final boolean canSupport() {
89: if (canSupport == null) {
90: getDefault();
91: }
92: return canSupport.booleanValue();
93: }
94:
95: public abstract Socket createSocket(Socket sock, String host,
96: int port) throws IOException;
97:
98: }
|