2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.transport.socket.ssl.basic;
25
import org.jboss.jrunit.extensions.ServerTestCase;
26
import org.jboss.logging.Logger;
27
import org.jboss.remoting.InvokerLocator;
28
import org.jboss.remoting.ServerInvocationHandler;
29
import org.jboss.remoting.security.SSLSocketBuilder;
30
import org.jboss.remoting.transport.Connector;
31
import org.jboss.test.remoting.TestUtil;
32
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
33
import org.jboss.test.remoting.transport.socket.ssl.SSLInvokerConstants;
35
import javax.net.ServerSocketFactory;
36
import java.io.IOException;
37
import java.security.KeyManagementException;
38
import java.security.KeyStoreException;
39
import java.security.NoSuchAlgorithmException;
40
import java.security.UnrecoverableKeyException;
41
import java.security.cert.CertificateException;
42
import java.util.Iterator;
47
* This is the concrete test for invoker server.
49
* @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
51
public class InvokerServerTest extends ServerTestCase implements SSLInvokerConstants
53
private int serverPort;
54
private Connector connector = null;
56
private static final Logger log = Logger.getLogger(InvokerServerTest.class);
58
public void init(Map metatdata) throws Exception
60
serverPort = getPort();
63
serverPort = TestUtil.getRandomPort();
65
log.debug("port = " + serverPort);
67
connector = new Connector();
68
InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata));
69
connector.setInvokerLocator(locator.getLocatorURI());
71
ServerSocketFactory svrSocketFactory = createServerSocketFactory();
72
connector.setServerSocketFactory(svrSocketFactory);
75
connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
79
protected String getTransport()
84
protected int getPort()
89
private ServerSocketFactory createServerSocketFactory()
90
throws NoSuchAlgorithmException, KeyManagementException, IOException,
91
CertificateException, UnrecoverableKeyException, KeyStoreException
93
ServerSocketFactory serverSocketFactory = null;
95
// since doing basic (using default ssl server socket factory)
96
// need to set the system properties to the keystore and password
97
String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile();
98
System.setProperty("javax.net.ssl.keyStore", keyStoreFilePath);
99
System.setProperty("javax.net.ssl.keyStorePassword", "unit-tests-server");
101
SSLSocketBuilder server = new SSLSocketBuilder();
102
serverSocketFactory = server.createSSLServerSocketFactory();
104
return serverSocketFactory;
107
private String buildLocatorURI(Map metadata)
109
if(metadata == null || metadata.size() == 0)
111
return getTransport() + "://" + host + ":" + serverPort;
115
StringBuffer uriBuffer = new StringBuffer(getTransport() + "://localhost:" + serverPort);
117
Set keys = metadata.keySet();
120
uriBuffer.append("/?");
123
Iterator itr = keys.iterator();
126
String key = (String) itr.next();
127
String value = (String) metadata.get(key);
128
uriBuffer.append(key + "=" + value + "&");
130
return uriBuffer.substring(0, uriBuffer.length() - 1);
134
protected String getSubsystem()
139
protected ServerInvocationHandler getServerInvocationHandler()
141
return new MockServerInvocationHandler();
144
protected void setUp() throws Exception
149
protected void tearDown() throws Exception
151
if(connector != null)
158
public static void main(String[] args)
160
InvokerServerTest server = new InvokerServerTest();
165
Thread.sleep(1200000);