1 7 package org.jboss.remoting.transport.http.ssl; 8 9 import java.io.IOException ; 10 import java.net.InetAddress ; 11 import java.net.ServerSocket ; 12 import java.util.Map ; 13 import javax.management.MBeanServer ; 14 import javax.management.MBeanServerInvocationHandler ; 15 import javax.management.MalformedObjectNameException ; 16 import javax.management.ObjectName ; 17 import javax.net.ServerSocketFactory; 18 import javax.net.ssl.SSLServerSocketFactory; 19 import org.jboss.remoting.InvokerLocator; 20 import org.jboss.remoting.security.ServerSocketFactoryMBean; 21 import org.jboss.remoting.transport.http.HTTPServerInvoker; 22 23 29 public class HTTPSServerInvoker extends HTTPServerInvoker 30 { 31 protected ServerSocketFactory serverSocketFactory = null; 32 33 public HTTPSServerInvoker(InvokerLocator locator) 34 { 35 super(locator); 36 } 37 38 public HTTPSServerInvoker(InvokerLocator locator, Map configuration) 39 { 40 super(locator, configuration); 41 } 42 43 protected ServerSocket createServerSocket(int serverBindPort, int backlog, InetAddress bindAddress) throws IOException 44 { 45 ServerSocket svrSocket = null; 46 47 Map props = getConfiguration(); 48 49 54 if(serverSocketFactory != null) 55 { 56 svrSocket = serverSocketFactory.createServerSocket(serverBindPort, backlog, bindAddress); 57 } 58 else 59 { 60 61 69 if(props.get("serverSocketFactory") != null) 70 { 71 try 72 { 73 String serverSocketFactoryString = (String ) props.get("serverSocketFactory"); 74 if(serverSocketFactoryString != null) 75 { 76 MBeanServer server = getMBeanServer(); 77 ObjectName serverSocketFactoryObjName = new ObjectName (serverSocketFactoryString); 78 if(server != null) 79 { 80 try 81 { 82 ServerSocketFactoryMBean serverSocketFactory = (ServerSocketFactoryMBean) MBeanServerInvocationHandler.newProxyInstance(server, 83 serverSocketFactoryObjName, 84 ServerSocketFactoryMBean.class, 85 false); 86 svrSocket = serverSocketFactory.createServerSocket(serverBindPort, backlog, bindAddress); 87 } 88 catch(Exception e) 89 { 90 log.error("Error creating mbean proxy for server socket factory for object name: " + serverSocketFactoryObjName, e); 91 throw new IOException ("Error createing custom server socket factory."); 92 } 93 } 94 else 95 { 96 log.error("The 'serverSocketFactory' attribute was set with a value, but the MBeanServer reference is null."); 97 throw new IOException ("Error creating custom server socket factory. The invoker does not have a reference to the mbean server."); 98 } 99 } 100 } 101 catch(MalformedObjectNameException e) 102 { 103 log.error("Error setting the server socket factory due to the attibute value passed not being a valid ObjectName.", e); 104 throw new IOException ("Error creating custom server socket factory. The attributed value passed is not a valid object name."); 105 } 106 catch(NullPointerException e) 107 { 108 log.error("Error setting the server socket factory due to null pointer exception.", e); 109 throw new IOException ("Error creating custom server socket factory."); 110 } 111 } 112 } 113 114 if(svrSocket == null) 115 { 116 log.debug("Creating default server socket."); 117 serverSocketFactory = SSLServerSocketFactory.getDefault(); 118 svrSocket = serverSocketFactory.createServerSocket(serverBindPort, backlog, bindAddress); 119 } 120 121 log.debug("Created server socket: " + svrSocket); 122 123 return svrSocket; 124 125 } 126 127 134 public void setServerSocketFactory(ServerSocketFactory serverSocketFactory) 135 { 136 this.serverSocketFactory = serverSocketFactory; 137 } 138 139 } | Popular Tags |