1 7 package org.jboss.test.remoting.transport.http.ssl.custom; 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 javax.management.MBeanServer ; 16 import javax.net.ServerSocketFactory; 17 import org.jboss.jrunit.extensions.ServerTestCase; 18 import org.jboss.remoting.InvocationRequest; 19 import org.jboss.remoting.InvokerLocator; 20 import org.jboss.remoting.ServerInvocationHandler; 21 import org.jboss.remoting.ServerInvoker; 22 import org.jboss.remoting.callback.InvokerCallbackHandler; 23 import org.jboss.remoting.security.SSLSocketBuilder; 24 import org.jboss.remoting.transport.Connector; 25 import org.jboss.remoting.transport.http.ssl.HTTPSServerInvoker; 26 import org.jboss.test.remoting.transport.http.ssl.SSLInvokerConstants; 27 import org.jboss.test.remoting.transport.web.ComplexObject; 28 29 32 public class HTTPSInvokerTestServer extends ServerTestCase implements SSLInvokerConstants 33 { 34 public static final String RESPONSE_VALUE = "This is the return to SampleInvocationHandler invocation"; 36 public static final ComplexObject OBJECT_RESPONSE_VALUE = new ComplexObject(5, "dub", false); 37 38 public static final String NULL_RETURN_PARAM = "return_null"; 39 public static final String OBJECT_RETURN_PARAM = "return_object"; 40 41 private Connector connector = null; 42 43 public void setupServer() throws Exception 44 { 45 String locatorURI = transport + "://" + host + ":" + port; 46 InvokerLocator locator = new InvokerLocator(locatorURI); 47 System.out.println("Starting remoting server with locator uri of: " + locatorURI); 48 connector = new Connector(); 49 connector.setInvokerLocator(locator.getLocatorURI()); 50 connector.create(); 51 52 ServerSocketFactory svrSocketFactory = createServerSocketFactory(); 53 HTTPSServerInvoker httpsSvrInvoker = (HTTPSServerInvoker) connector.getServerInvoker(); 54 httpsSvrInvoker.setServerSocketFactory(svrSocketFactory); 55 56 SampleInvocationHandler invocationHandler = new SampleInvocationHandler(); 57 connector.addInvocationHandler("sample", invocationHandler); 59 60 connector.start(); 61 62 } 63 64 private ServerSocketFactory createServerSocketFactory() 65 throws NoSuchAlgorithmException , KeyManagementException , IOException , 66 CertificateException , UnrecoverableKeyException , KeyStoreException 67 { 68 69 ServerSocketFactory serverSocketFactory = null; 70 71 SSLSocketBuilder server = new SSLSocketBuilder(); 72 server.setUseSSLServerSocketFactory(false); 73 74 server.setSecureSocketProtocol("SSL"); 75 server.setKeyManagementAlgorithm("SunX509"); 76 77 server.setKeyStoreType("JKS"); 78 String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile(); 79 server.setKeyStoreURL(keyStoreFilePath); 80 server.setKeyStorePassword("opensource"); 81 85 87 serverSocketFactory = server.createSSLServerSocketFactory(); 88 89 return serverSocketFactory; 90 } 91 92 protected void setUp() throws Exception 93 { 94 setupServer(); 95 } 96 97 protected void tearDown() throws Exception 98 { 99 if(connector != null) 100 { 101 connector.stop(); 102 connector.destroy(); 103 } 104 } 105 106 107 110 public static class SampleInvocationHandler implements ServerInvocationHandler 111 { 112 113 114 121 public Object invoke(InvocationRequest invocation) throws Throwable 122 { 123 System.out.println("Invocation request is: " + invocation.getParameter()); 125 if(NULL_RETURN_PARAM.equals(invocation.getParameter())) 126 { 127 return null; 128 } 129 else if(invocation.getParameter() instanceof ComplexObject) 130 { 131 return OBJECT_RESPONSE_VALUE; 132 } 133 else 134 { 135 return RESPONSE_VALUE; 137 } 138 } 139 140 146 public void addListener(InvokerCallbackHandler callbackHandler) 147 { 148 } 150 151 157 public void removeListener(InvokerCallbackHandler callbackHandler) 158 { 159 } 161 162 167 public void setMBeanServer(MBeanServer server) 168 { 169 } 171 172 177 public void setInvoker(ServerInvoker invoker) 178 { 179 } 181 182 } 183 184 } | Popular Tags |