~ubuntu-branches/ubuntu/wily/libjboss-remoting-java/wily

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/socket/ssl/custom/InvokerServerTest.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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.
6
 
*
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.
11
 
*
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.
16
 
*
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.
21
 
*/
22
 
 
23
 
package org.jboss.test.remoting.transport.socket.ssl.custom;
24
 
 
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;
34
 
 
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.HashMap;
43
 
import java.util.Iterator;
44
 
import java.util.Map;
45
 
import java.util.Set;
46
 
 
47
 
/**
48
 
 * This is the concrete test for invoker server.
49
 
 *
50
 
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
51
 
 */
52
 
public class InvokerServerTest extends ServerTestCase implements SSLInvokerConstants
53
 
{
54
 
   protected int serverPort = port;
55
 
   protected Connector connector = null;
56
 
 
57
 
   private static final Logger log = Logger.getLogger(InvokerServerTest.class);
58
 
 
59
 
   public void init(Map metatdata) throws Exception
60
 
   {
61
 
      if(serverPort < 0)
62
 
      {
63
 
         serverPort = TestUtil.getRandomPort();
64
 
      }
65
 
      log.debug("port = " + serverPort);
66
 
 
67
 
      Map config = new HashMap();
68
 
//      config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_TYPE, "JKS");
69
 
//      String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile();
70
 
//      config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
71
 
//      config.put(RemotingSSLSocketFactory.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
72
 
//      config.put(RemotingSSLSocketFactory.REMOTING_USE_CLIENT_MODE, "false");
73
 
      
74
 
//      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
75
 
//      String trustStoreFilePath = this.getClass().getResource("../.truststore").getFile();
76
 
//      trustStoreFilePath = "output/tests/classes/org/jboss/test/remoting/transport/socket/ssl/.truststore";
77
 
//      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
78
 
//      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
79
 
      
80
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
81
 
      String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile();
82
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
83
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
84
 
      
85
 
      Connector connector = new Connector(config);
86
 
      InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata));
87
 
      connector.setInvokerLocator(locator.getLocatorURI());
88
 
 
89
 
//      ServerSocketFactory svrSocketFactory = createServerSocketFactory();
90
 
//      connector.setServerSocketFactory(svrSocketFactory);
91
 
 
92
 
      connector.create();
93
 
 
94
 
      connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
95
 
      connector.start();
96
 
   }
97
 
   
98
 
   protected String getTransport()
99
 
   {
100
 
      return transport;
101
 
   }
102
 
   
103
 
   private ServerSocketFactory createServerSocketFactory()
104
 
         throws NoSuchAlgorithmException, KeyManagementException, IOException,
105
 
                CertificateException, UnrecoverableKeyException, KeyStoreException
106
 
   {
107
 
      ServerSocketFactory serverSocketFactory = null;
108
 
 
109
 
      SSLSocketBuilder server = new SSLSocketBuilder();
110
 
      server.setUseSSLServerSocketFactory(false);
111
 
 
112
 
      server.setSecureSocketProtocol("SSL");
113
 
      server.setKeyStoreAlgorithm("SunX509");
114
 
 
115
 
      server.setKeyStoreType("JKS");
116
 
      String keyStoreFilePath = this.getClass().getResource("../.keystore").getFile();
117
 
      server.setKeyStoreURL(keyStoreFilePath);
118
 
      server.setKeyStorePassword("unit-tests-server");
119
 
      /*
120
 
       * This is optional since if not set, will use
121
 
       * the key store password (and are the same in this case)
122
 
       */
123
 
      //server.setKeyPassword("unit-tests-server");
124
 
 
125
 
      serverSocketFactory = server.createSSLServerSocketFactory();
126
 
 
127
 
      return serverSocketFactory;
128
 
   }
129
 
 
130
 
   protected String buildLocatorURI(Map metadata)
131
 
   {
132
 
      if(metadata == null || metadata.size() == 0)
133
 
      {
134
 
         return getTransport() + "://localhost:" + serverPort;
135
 
      }
136
 
      else
137
 
      {
138
 
         StringBuffer uriBuffer = new StringBuffer(getTransport() + "://localhost:" + serverPort);
139
 
 
140
 
         Set keys = metadata.keySet();
141
 
         if(keys.size() > 0)
142
 
         {
143
 
            uriBuffer.append("/?");
144
 
         }
145
 
 
146
 
         Iterator itr = keys.iterator();
147
 
         while(itr.hasNext())
148
 
         {
149
 
            String key = (String) itr.next();
150
 
            String value = (String) metadata.get(key);
151
 
            uriBuffer.append(key + "=" + value + "&");
152
 
         }
153
 
         return uriBuffer.substring(0, uriBuffer.length() - 1);
154
 
      }
155
 
   }
156
 
 
157
 
   protected String getSubsystem()
158
 
   {
159
 
      return "mock";
160
 
   }
161
 
 
162
 
   protected ServerInvocationHandler getServerInvocationHandler()
163
 
   {
164
 
      return new MockServerInvocationHandler();
165
 
   }
166
 
 
167
 
   protected void setUp() throws Exception
168
 
   {
169
 
      init(null);
170
 
   }
171
 
 
172
 
   protected void tearDown() throws Exception
173
 
   {
174
 
      if(connector != null)
175
 
      {
176
 
         connector.stop();
177
 
         connector.destroy();
178
 
      }
179
 
   }
180
 
 
181
 
   public static void main(String[] args)
182
 
   {
183
 
      InvokerServerTest test = new InvokerServerTest();
184
 
      try
185
 
      {
186
 
         test.setUp();
187
 
 
188
 
         Thread.currentThread().sleep(20000);
189
 
 
190
 
         test.tearDown();
191
 
      }
192
 
      catch(Exception e)
193
 
      {
194
 
         e.printStackTrace();
195
 
      }
196
 
   }
197
 
 
198
 
 
199
 
}