1 7 package org.jboss.test.remoting.transport.socket.ssl.basic; 8 9 import java.io.IOException ; 10 import java.security.KeyManagementException ; 11 import java.security.KeyStoreException ; 12 import java.security.NoSuchAlgorithmException ; 13 import java.security.UnrecoverableKeyException ; 14 import java.security.cert.CertificateException ; 15 import java.util.Iterator ; 16 import java.util.Map ; 17 import java.util.Set ; 18 import javax.net.ServerSocketFactory; 19 import org.jboss.jrunit.extensions.ServerTestCase; 20 import org.jboss.logging.Logger; 21 import org.jboss.remoting.InvokerLocator; 22 import org.jboss.remoting.ServerInvocationHandler; 23 import org.jboss.remoting.security.SSLSocketBuilder; 24 import org.jboss.remoting.transport.Connector; 25 import org.jboss.remoting.transport.socket.ssl.SSLSocketServerInvoker; 26 import org.jboss.test.remoting.TestUtil; 27 import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler; 28 import org.jboss.test.remoting.transport.socket.ssl.SSLInvokerConstants; 29 30 35 public class InvokerServerTest extends ServerTestCase implements SSLInvokerConstants 36 { 37 private int serverPort = port; 38 private Connector connector = null; 39 40 private static final Logger log = Logger.getLogger(InvokerServerTest.class); 41 42 public void init(Map metatdata) throws Exception 43 { 44 if(serverPort < 0) 45 { 46 serverPort = TestUtil.getRandomPort(); 47 } 48 log.debug("port = " + serverPort); 49 50 connector = new Connector(); 51 InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata)); 52 connector.setInvokerLocator(locator.getLocatorURI()); 53 connector.create(); 54 55 ServerSocketFactory svrSocketFactory = createServerSocketFactory(); 56 SSLSocketServerInvoker socketSvrInvoker = (SSLSocketServerInvoker) connector.getServerInvoker(); 57 socketSvrInvoker.setServerSocketFactory(svrSocketFactory); 58 59 connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler()); 60 connector.start(); 61 } 62 63 private ServerSocketFactory createServerSocketFactory() 64 throws NoSuchAlgorithmException , KeyManagementException , IOException , 65 CertificateException , UnrecoverableKeyException , KeyStoreException 66 { 67 ServerSocketFactory serverSocketFactory = null; 68 69 String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile(); 72 System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath); 73 System.setProperty("javax.net.ssl.keyStorePassword", "opensource"); 74 75 SSLSocketBuilder server = new SSLSocketBuilder(); 76 serverSocketFactory = server.createSSLServerSocketFactory(); 77 78 return serverSocketFactory; 79 } 80 81 private String buildLocatorURI(Map metadata) 82 { 83 if(metadata == null || metadata.size() == 0) 84 { 85 return transport + "://" + host + ":" + serverPort; 86 } 87 else 88 { 89 StringBuffer uriBuffer = new StringBuffer (transport + "://localhost:" + serverPort); 90 91 Set keys = metadata.keySet(); 92 Iterator itr = keys.iterator(); 93 while(itr.hasNext()) 94 { 95 String key = (String ) itr.next(); 96 String value = (String ) metadata.get(key); 97 uriBuffer.append(key + "=" + value + ","); 98 } 99 return uriBuffer.substring(0, uriBuffer.length() - 1); 100 } 101 } 102 103 protected String getSubsystem() 104 { 105 return "mock"; 106 } 107 108 protected ServerInvocationHandler getServerInvocationHandler() 109 { 110 return new MockServerInvocationHandler(); 111 } 112 113 protected void setUp() throws Exception 114 { 115 init(null); 116 } 117 118 protected void tearDown() throws Exception 119 { 120 if(connector != null) 121 { 122 connector.stop(); 123 connector.destroy(); 124 } 125 } 126 127 } 128 | Popular Tags |