1 45 package org.exolab.jms.net.http; 46 47 import java.security.Principal ; 48 49 import org.apache.commons.logging.LogFactory; 50 import org.apache.commons.logging.Log; 51 52 import org.exolab.jms.net.connector.Authenticator; 53 import org.exolab.jms.net.connector.ConnectionFactory; 54 import org.exolab.jms.net.connector.ConnectionManager; 55 import org.exolab.jms.net.connector.ConnectionRequestInfo; 56 import org.exolab.jms.net.connector.ManagedConnection; 57 import org.exolab.jms.net.connector.ManagedConnectionAcceptor; 58 import org.exolab.jms.net.connector.ResourceException; 59 import org.exolab.jms.net.socket.SocketRequestInfo; 60 61 62 69 public class HTTPSManagedConnectionFactory 70 extends AbstractHTTPManagedConnectionFactory { 71 72 75 private static boolean _sslInit = false; 76 77 80 private static final String PROTOCOL_HANDLER_PKGS 81 = "java.protocol.handler.pkgs"; 82 83 86 private static final String SUN_PACKAGE 87 = "com.sun.net.ssl.internal.www.protocol"; 88 89 92 private static final Log _log = 93 LogFactory.getLog(HTTPSManagedConnectionFactory.class); 94 95 102 public ConnectionFactory createConnectionFactory(ConnectionManager manager) 103 throws ResourceException { 104 return new HTTPSConnectionFactory(this, manager); 105 } 106 107 115 public ManagedConnection createManagedConnection(Principal principal, 116 ConnectionRequestInfo info) 117 throws ResourceException { 118 if (!(info instanceof HTTPRequestInfo)) { 119 throw new ResourceException("Argument 'info' must be of type " 120 + HTTPRequestInfo.class.getName()); 121 } 122 initSSL(); 123 124 return new HTTPSManagedConnection(principal, (HTTPRequestInfo) info); 125 } 126 127 135 public ManagedConnectionAcceptor createManagedConnectionAcceptor( 136 Authenticator authenticator, ConnectionRequestInfo info) 137 throws ResourceException { 138 139 if (!(info instanceof SocketRequestInfo)) { 140 throw new ResourceException("Argument 'info' must be of type " 141 + SocketRequestInfo.class.getName()); 142 } 143 144 return new HTTPSManagedConnectionAcceptor(authenticator, 145 (SocketRequestInfo) info); 146 } 147 148 159 private static synchronized void initSSL() { 160 if (!_sslInit) { 161 try { 162 String value = System.getProperty(PROTOCOL_HANDLER_PKGS); 163 if (value == null) { 164 value = SUN_PACKAGE; 165 } else if (value.indexOf(SUN_PACKAGE) == -1) { 166 if (value.length() > 0) { 167 value += "|"; 168 } 169 value += SUN_PACKAGE; 170 } 171 System.setProperty(PROTOCOL_HANDLER_PKGS, SUN_PACKAGE); 172 _sslInit = true; 173 } catch (SecurityException exception) { 174 if (_log.isDebugEnabled()) { 175 _log.debug("Failed to set property=" 176 + PROTOCOL_HANDLER_PKGS, exception); 177 } 178 } 179 } 180 } 181 182 183 } 184 | Popular Tags |