1 7 package org.jboss.test.remoting.transport.http.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 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 HTTPSInvokerTestServer.SampleInvocationHandler invocationHandler = new HTTPSInvokerTestServer.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 ServerSocketFactory serverSocketFactory = null; 69 70 String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile(); 73 System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath); 74 System.setProperty("javax.net.ssl.keyStorePassword", "opensource"); 75 76 SSLSocketBuilder server = new SSLSocketBuilder(); 77 serverSocketFactory = server.createSSLServerSocketFactory(); 78 79 return serverSocketFactory; 80 } 81 82 protected void setUp() throws Exception 83 { 84 setupServer(); 85 } 86 87 protected void tearDown() throws Exception 88 { 89 if(connector != null) 90 { 91 connector.stop(); 92 connector.destroy(); 93 } 94 } 95 96 97 100 public static class SampleInvocationHandler implements ServerInvocationHandler 101 { 102 103 104 111 public Object invoke(InvocationRequest invocation) throws Throwable 112 { 113 System.out.println("Invocation request is: " + invocation.getParameter()); 115 if(NULL_RETURN_PARAM.equals(invocation.getParameter())) 116 { 117 return null; 118 } 119 else if(invocation.getParameter() instanceof ComplexObject) 120 { 121 return OBJECT_RESPONSE_VALUE; 122 } 123 else 124 { 125 return RESPONSE_VALUE; 127 } 128 } 129 130 136 public void addListener(InvokerCallbackHandler callbackHandler) 137 { 138 } 140 141 147 public void removeListener(InvokerCallbackHandler callbackHandler) 148 { 149 } 151 152 157 public void setMBeanServer(MBeanServer server) 158 { 159 } 161 162 167 public void setInvoker(ServerInvoker invoker) 168 { 169 } 171 172 } 173 174 } | Popular Tags |