1 10 11 package org.mule.providers.http; 12 13 import org.apache.commons.lang.StringUtils; 14 import org.mule.providers.AbstractConnector; 15 import org.mule.umo.UMOComponent; 16 import org.mule.umo.endpoint.UMOEndpoint; 17 import org.mule.umo.lifecycle.InitialisationException; 18 19 import javax.net.ServerSocketFactory; 20 import javax.net.ssl.SSLContext; 21 import javax.net.ssl.SSLServerSocket; 22 23 import java.io.IOException ; 24 import java.net.InetAddress ; 25 import java.net.ServerSocket ; 26 import java.net.URI ; 27 import java.security.KeyManagementException ; 28 import java.security.NoSuchAlgorithmException ; 29 import java.security.SecureRandom ; 30 31 38 39 public class HttpsMessageReceiver extends HttpMessageReceiver 40 { 41 public HttpsMessageReceiver(AbstractConnector connector, UMOComponent component, UMOEndpoint endpoint) 42 throws InitialisationException 43 { 44 super(connector, component, endpoint); 45 } 46 47 protected ServerSocket createSocket(URI uri) 48 throws IOException , NoSuchAlgorithmException , KeyManagementException 49 { 50 HttpsConnector cnn; 51 ServerSocketFactory ssf; 52 cnn = (HttpsConnector)connector; 53 SSLContext sslc = SSLContext.getInstance(cnn.getSslType(), cnn.getProvider()); 56 57 sslc.init(cnn.getKeyManagerFactory().getKeyManagers(), cnn.getTrustManagerFactory() 59 .getTrustManagers(), 60 new SecureRandom ()); 62 63 ssf = sslc.getServerSocketFactory(); 64 65 String host = StringUtils.defaultIfEmpty(uri.getHost(), "localhost"); 66 int backlog = cnn.getBacklog(); 67 SSLServerSocket serverSocket; 68 69 InetAddress inetAddress = InetAddress.getByName(host); 70 if (inetAddress.equals(InetAddress.getLocalHost()) || inetAddress.isLoopbackAddress() 71 || host.trim().equals("localhost")) 72 { 73 serverSocket = (SSLServerSocket)ssf.createServerSocket(uri.getPort(), backlog); 74 } 75 else 76 { 77 serverSocket = (SSLServerSocket)ssf.createServerSocket(uri.getPort(), backlog, inetAddress); 78 } 79 serverSocket.setNeedClientAuth(cnn.isRequireClientAuthentication()); 81 return serverSocket; 82 } 83 } 84 | Popular Tags |