From: Ron S. <ron...@ya...> - 2006-03-28 02:44:08
|
User: rsigal Date: 06/03/27 21:44:03 Modified: src/tests/org/jboss/test/remoting/transport/socket/ssl/custom InvokerServerTest.java InvokerTestCase.java InvokerClientTest.java Log: Revision Changes Path 1.9 +22 -8 JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/ssl/custom/InvokerServerTest.java (In the diff below, changes in quantity of whitespace are not shown.) Index: InvokerServerTest.java =================================================================== RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/ssl/custom/InvokerServerTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -b -r1.8 -r1.9 --- InvokerServerTest.java 14 Mar 2006 18:32:55 -0000 1.8 +++ InvokerServerTest.java 28 Mar 2006 02:44:03 -0000 1.9 @@ -28,17 +28,20 @@ import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; +import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; + import javax.net.ServerSocketFactory; + import org.jboss.jrunit.extensions.ServerTestCase; import org.jboss.logging.Logger; import org.jboss.remoting.InvokerLocator; import org.jboss.remoting.ServerInvocationHandler; import org.jboss.remoting.security.SSLSocketBuilder; import org.jboss.remoting.transport.Connector; -import org.jboss.remoting.transport.socket.ssl.SSLSocketServerInvoker; +import org.jboss.remoting.util.socket.RemotingSSLSocketFactory; import org.jboss.test.remoting.TestUtil; import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler; import org.jboss.test.remoting.transport.socket.ssl.SSLInvokerConstants; @@ -63,19 +66,30 @@ } log.debug("port = " + serverPort); - Connector connector = new Connector(); + Map config = new HashMap(); + config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_TYPE, "JKS"); + String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile(); + config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath); + config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server"); + config.put(RemotingSSLSocketFactory.REMOTING_USE_CLIENT_MODE, "false"); + + Connector connector = new Connector(config); InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata)); connector.setInvokerLocator(locator.getLocatorURI()); connector.create(); ServerSocketFactory svrSocketFactory = createServerSocketFactory(); - SSLSocketServerInvoker socketSvrInvoker = (SSLSocketServerInvoker) connector.getServerInvoker(); - socketSvrInvoker.setServerSocketFactory(svrSocketFactory); + connector.getServerInvoker().setServerSocketFactory(svrSocketFactory); connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler()); connector.start(); } + protected String getTransport() + { + return transport; + } + private ServerSocketFactory createServerSocketFactory() throws NoSuchAlgorithmException, KeyManagementException, IOException, CertificateException, UnrecoverableKeyException, KeyStoreException @@ -107,11 +121,11 @@ { if(metadata == null || metadata.size() == 0) { - return transport + "://localhost:" + serverPort; + return getTransport() + "://localhost:" + serverPort; } else { - StringBuffer uriBuffer = new StringBuffer(transport + "://localhost:" + serverPort); + StringBuffer uriBuffer = new StringBuffer(getTransport() + "://localhost:" + serverPort); Set keys = metadata.keySet(); if(keys.size() > 0) 1.6 +1 -1 JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/ssl/custom/InvokerTestCase.java (In the diff below, changes in quantity of whitespace are not shown.) Index: InvokerTestCase.java =================================================================== RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/ssl/custom/InvokerTestCase.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -b -r1.5 -r1.6 --- InvokerTestCase.java 30 Dec 2005 05:26:49 -0000 1.5 +++ InvokerTestCase.java 28 Mar 2006 02:44:03 -0000 1.6 @@ -1,4 +1,4 @@ -/* + /* * JBoss, Home of Professional Open Source * Copyright 2005, JBoss Inc., and individual contributors as indicated * by the @authors tag. See the copyright.txt in the distribution for a 1.5 +253 -49 JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/ssl/custom/InvokerClientTest.java (In the diff below, changes in quantity of whitespace are not shown.) Index: InvokerClientTest.java =================================================================== RCS file: /cvsroot/jboss/JBossRemoting/src/tests/org/jboss/test/remoting/transport/socket/ssl/custom/InvokerClientTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -b -r1.4 -r1.5 --- InvokerClientTest.java 30 Dec 2005 05:26:49 -0000 1.4 +++ InvokerClientTest.java 28 Mar 2006 02:44:03 -0000 1.5 @@ -1,61 +1,85 @@ /* -* JBoss, Home of Professional Open Source -* Copyright 2005, JBoss Inc., and individual contributors as indicated -* by the @authors tag. See the copyright.txt in the distribution for a -* full listing of individual contributors. -* -* This is free software; you can redistribute it and/or modify it -* under the terms of the GNU Lesser General Public License as -* published by the Free Software Foundation; either version 2.1 of -* the License, or (at your option) any later version. -* -* This software is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -* Lesser General Public License for more details. -* -* You should have received a copy of the GNU Lesser General Public -* License along with this software; if not, write to the Free -* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -* 02110-1301 USA, or see the FSF site: http://www.fsf.org. -*/ + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt in the distribution for a + * full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ package org.jboss.test.remoting.transport.socket.ssl.custom; -import java.rmi.server.UID; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.management.MBeanServer; +import javax.net.ServerSocketFactory; + +import junit.framework.TestCase; + import org.jboss.logging.Logger; import org.jboss.remoting.Client; +import org.jboss.remoting.InvocationRequest; import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.RemoteClientInvoker; +import org.jboss.remoting.ServerInvocationHandler; +import org.jboss.remoting.ServerInvoker; +import org.jboss.remoting.callback.Callback; +import org.jboss.remoting.callback.HandleCallbackException; +import org.jboss.remoting.callback.InvokerCallbackHandler; import org.jboss.remoting.invocation.NameBasedInvocation; +import org.jboss.remoting.security.SSLSocketBuilder; +import org.jboss.remoting.transport.Connector; +import org.jboss.remoting.util.socket.RemotingSSLSocketFactory; import org.jboss.test.remoting.transport.socket.ssl.SSLInvokerConstants; -import junit.framework.TestCase; - /** - * This is the actual concrete test for the invoker client. Uses socket transport by default. - * - * @author <a href="mailto:te...@e2...">Tom Elrod</a> + * @author <a href="mailto:to...@jb...">Tom Elrod</a> + * @version $Revision: 1.5 $ + * <p> + * Copyright (c) Mar 23, 2006 + * </p> */ public class InvokerClientTest extends TestCase implements SSLInvokerConstants { private static final Logger log = Logger.getLogger(InvokerClientTest.class); - private String sessionId = new UID().toString(); - private Client client; public void init() { try { - // since doing basic (using default ssl server socket factory) - // need to set the system properties to the truststore + Map config = new HashMap(); + config.put(RemotingSSLSocketFactory.REMOTING_TRUST_STORE_TYPE, "JKS"); String trustStoreFilePath = this.getClass().getResource("../.truststore").getFile(); - System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath); + config.put(RemotingSSLSocketFactory.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath); + config.put(RemotingSSLSocketFactory.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client"); - InvokerLocator locator = new InvokerLocator(transport + "://localhost:" + port); - client = new Client(locator, "mock"); + InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + port); + client = new Client(locator, config); client.connect(); } catch(Exception e) @@ -67,7 +91,6 @@ public void testRemoteCall() throws Throwable { log.debug("running testRemoteCall()"); - log.debug("client.getInvoker().getLocator()" + client.getInvoker().getLocator()); // simple invoke, should return bar @@ -85,6 +108,82 @@ } + public void xtestSocketFactoryParameters() + { + try + { + Map config = new HashMap(); + config.put(RemotingSSLSocketFactory.REMOTING_TRUST_STORE_TYPE, "JKS"); + String trustStoreFilePath = this.getClass().getResource("../.truststore").getFile(); + config.put(RemotingSSLSocketFactory.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath); + config.put(RemotingSSLSocketFactory.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client"); + + config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_TYPE, "JKS"); + String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile(); + config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath); + config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server"); + + InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + port); + client = new Client(locator, config); + + // Test that parameters are properly set. + RemoteClientInvoker clientInvoker = (RemoteClientInvoker) client.getInvoker(); + RemotingSSLSocketFactory socketFactory = (RemotingSSLSocketFactory) clientInvoker.getSocketFactory(); + assertTrue(socketFactory.getTrustStoreType().equals("JKS")); + // assertTrue(socketFactory.gett.equals("JKS")); + } + catch (Throwable t) + { + log.error(t); + t.printStackTrace(); + fail(); + } + + } + + public void testCallbacks() + { + try + { + InvokerLocator locator = new InvokerLocator(getTransport() + "://localhost:" + callbackPort); + Connector callbackConnector = new Connector(locator.getLocatorURI()); + callbackConnector.start(); + callbackConnector.getServerInvoker().setServerSocketFactory(createServerSocketFactory()); + callbackConnector.addInvocationHandler("sample", new SampleInvocationHandler()); + + CallbackHandler callbackHandler = new CallbackHandler(); + String callbackHandleObject = "myCallbackHandleObject"; + client.addListener(callbackHandler, locator, callbackHandleObject); + solicitCallback("abc"); + + // need to wait for brief moment so server can callback + Thread.sleep(500); + + // remove callback handler from server + client.removeListener(callbackHandler); + + // shut down callback server + callbackConnector.stop(); + callbackConnector.destroy(); + callbackConnector = null; + +// List callbacks = callbackHandler.getCallbacks(); +// assertEquals(callbacks.size(), 1); +// assertEquals(callbacks.get(0), "abc"); + } + catch (Throwable t) + { + log.error(t); + t.printStackTrace(); + fail(); + } + } + + protected String getTransport() + { + return transport; + } + private Object makeInvocation(String method, String param) throws Throwable { Object ret = client.invoke(new NameBasedInvocation(method, @@ -95,6 +194,16 @@ return ret; } + private Object solicitCallback(String param) throws Throwable + { + Object ret = client.invoke(new NameBasedInvocation("test", + new Object[]{param}, + new String[]{String.class.getName()}), + null); + + return ret; + } + public void setUp() throws Exception { init(); @@ -110,4 +219,99 @@ } + private ServerSocketFactory createServerSocketFactory() + throws NoSuchAlgorithmException, KeyManagementException, IOException, + CertificateException, UnrecoverableKeyException, KeyStoreException + { + ServerSocketFactory serverSocketFactory = null; + + SSLSocketBuilder server = new SSLSocketBuilder(); + server.setUseSSLServerSocketFactory(false); + + server.setSecureSocketProtocol("SSL"); + server.setKeyManagementAlgorithm("SunX509"); + + server.setKeyStoreType("JKS"); + String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile(); + server.setKeyStoreURL(keyStoreFilePath); + server.setKeyStorePassword("unit-tests-server"); + server.setUseClientMode(true); + /* + * This is optional since if not set, will use + * the key store password (and are the same in this case) + */ + //server.setKeyPassword("unit-tests-server"); + + serverSocketFactory = server.createSSLServerSocketFactory(); + + return serverSocketFactory; + } + + + static class SampleInvocationHandler implements ServerInvocationHandler + { + public Object invoke(InvocationRequest invocation) throws Throwable + { + return new Integer(0); + } + + public void addListener(InvokerCallbackHandler callbackHandler) + { + System.out.println("entering addListener()"); + + try + { + Callback callback = new Callback(new Integer(1)); + callbackHandler.handleCallback(callback); + System.out.println("sent first callback"); + callback = new Callback(new Integer(2)); + callbackHandler.handleCallback(callback); + System.out.println("sent second callback"); + } + catch(Exception e) + { + e.printStackTrace(); + } + } + + public void removeListener(InvokerCallbackHandler callbackHandler) + { + } + + public void setMBeanServer(MBeanServer server) + { + // NO OP as do not need reference to MBeanServer for this handler + } + + public void setInvoker(ServerInvoker invoker) + { + // NO OP as do not need reference back to the server invoker + } + } + + + static class CallbackHandler implements InvokerCallbackHandler + { + private ArrayList callbacks = new ArrayList(); + + public ArrayList getCallbacks() + { + return callbacks; + } + + /** + * Will take the callback and print out its values. + * + * @param callback + * @throws org.jboss.remoting.callback.HandleCallbackException + * + */ + public void handleCallback(Callback callback) throws HandleCallbackException + { + log.info("Received push callback."); + log.info("Received callback value of: " + callback.getCallbackObject()); + log.info("Received callback server invoker of: " + callback.getServerLocator()); + callbacks.add(callback); + } + } } |