1 17 package org.apache.excalibur.source.impl; 18 19 import java.security.Provider ; 20 import java.security.Security ; 21 22 import org.apache.avalon.framework.parameters.ParameterException; 23 import org.apache.avalon.framework.parameters.Parameters; 24 import org.apache.commons.httpclient.protocol.Protocol; 25 import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory; 26 27 38 public class HTTPSClientSourceFactory extends HTTPClientSourceFactory 39 { 40 43 public static final String SSL_PROVIDER = "provider"; 44 45 48 public static final String SOCKET_FACTORY = "socket-factory"; 49 50 53 public static final String HTTPS = "https"; 54 55 61 public void parameterize( final Parameters params ) 62 throws ParameterException 63 { 64 super.parameterize( params ); 65 66 setProvider( params ); 67 setSocketFactory( params ); 68 } 69 70 77 private void setProvider( final Parameters params ) 78 throws ParameterException 79 { 80 String provider = null; 81 82 try 83 { 84 provider = params.getParameter( SSL_PROVIDER ); 85 } 86 catch ( final ParameterException e ) 87 { 88 return; } 90 91 Security.addProvider( (Provider ) getInstance( provider ) ); 92 } 93 94 101 private void setSocketFactory( final Parameters params ) 102 throws ParameterException 103 { 104 String factoryName = null; 105 106 try 107 { 108 factoryName = params.getParameter( SOCKET_FACTORY ); 109 } 110 catch ( final ParameterException e ) 111 { 112 return; } 114 115 final Protocol protocol = 116 new Protocol( 117 HTTPS, 118 ( SecureProtocolSocketFactory ) getInstance( factoryName ), 119 443 120 ); 121 Protocol.registerProtocol( HTTPS, protocol ); 122 } 123 124 132 private Object getInstance( final String className ) 133 throws ParameterException 134 { 135 try 136 { 137 return Class.forName( className ).newInstance(); 138 } 139 catch ( final Exception e ) 140 { 141 throw new ParameterException( 142 "Unable to instantiate: " + className, e 143 ); 144 } 145 } 146 } 147 | Popular Tags |