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

« back to all changes in this revision

Viewing changes to examples/org/jboss/remoting/samples/config/factories/FactoryConfigSSLSample.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 2006, 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
 
package org.jboss.remoting.samples.config.factories;
23
 
 
24
 
import java.io.ByteArrayInputStream;
25
 
import java.io.File;
26
 
import java.util.HashMap;
27
 
 
28
 
import javax.management.MBeanServer;
29
 
import javax.management.MBeanServerFactory;
30
 
import javax.management.ObjectName;
31
 
import javax.net.ServerSocketFactory;
32
 
import javax.net.SocketFactory;
33
 
import javax.xml.parsers.DocumentBuilderFactory;
34
 
 
35
 
import junit.framework.TestCase;
36
 
 
37
 
import org.jboss.logging.Logger;
38
 
import org.jboss.remoting.Client;
39
 
import org.jboss.remoting.InvokerLocator;
40
 
import org.jboss.remoting.ServerInvoker;
41
 
import org.jboss.remoting.samples.config.factories.FactoryConfigSample.CallbackHandler;
42
 
import org.jboss.remoting.samples.config.factories.FactoryConfigSample.SampleInvocationHandler;
43
 
import org.jboss.remoting.security.SSLServerSocketFactoryService;
44
 
import org.jboss.remoting.security.SSLSocketBuilder;
45
 
import org.jboss.remoting.security.SSLSocketFactoryService;
46
 
import org.jboss.remoting.transport.Connector;
47
 
import org.jboss.remoting.transport.PortUtil;
48
 
import org.w3c.dom.Document;
49
 
 
50
 
/**
51
 
 * These methods illustrate configuring socket factories and server socket factories
52
 
 * on the server side and on the client side.  The numbered
53
 
 * options mentioned refer to the lists of configuration options discussed in the
54
 
 * Remoting documentation in the subsections "Server side configuration" and
55
 
 * "Client side configuration" of the section called "Socket factories and server
56
 
 * socket factories".
57
 
 * <p>
58
 
 * The configuration options illustrated in this class are specific to SSL
59
 
 * sockets and server sockets.  The methods
60
 
 * <code>getDefaultServerSocketFactory()</code>,
61
 
 * <code>getDefaultSocketFactory()</code>,
62
 
 * <code>getDefaultCallbackServerSocketFactory()</code> and
63
 
 * <code>getDefaultCallbackSocketFactory()</code> 
64
 
 * illustrate the use of the class <code>SSLSocketBuilder</code> to
65
 
 * create custom SSL socket factories and SSL server socket factories.
66
 
 * <p>
67
 
 * @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
68
 
 * <p>
69
 
 * Copyright (c) Jul 20, 2006
70
 
 * </p>
71
 
 */
72
 
public class FactoryConfigSSLSample extends TestCase
73
 
{
74
 
   private static Logger log = Logger.getLogger(FactoryConfigSSLSample.class);
75
 
   
76
 
   
77
 
   
78
 
   /** This test illustrates the following set of configuration options:
79
 
    * <p>
80
 
    * <table border cellpadding="5">
81
 
    *  <tr><td align="center"><b>side<td align="center"><b>factory<td><b>option</tr>
82
 
    *  <tr><td>server side<td align="center">server socket<td align="center">4</tr>
83
 
    *  <tr><td>server side<td align="center">socket       <td align="center">4</tr>
84
 
    *  <tr><td>client side<td align="center">server socket<td align="center">1</tr>
85
 
    *  <tr><td>client side<td align="center">socket       <td align="center">1</tr>
86
 
    * </table>
87
 
    */
88
 
   public void testFactoriesByPassingMBeanInXml()
89
 
   {
90
 
      try
91
 
      {
92
 
         /////////////////////////////////////
93
 
         /////    Set up server side.     //// 
94
 
         /////////////////////////////////////
95
 
         HashMap sconfig = new HashMap();
96
 
         
97
 
         // Make callback Client use remote invoker.
98
 
         sconfig.put(InvokerLocator.FORCE_REMOTE, "true");
99
 
           
100
 
         // Create ServerSocketFactory MBean.
101
 
         ServerSocketFactory service = getDefaultServerSocketFactory();
102
 
         String serverSocketFactoryName = "jboss:type=serversocketfactory";
103
 
         ObjectName objName = new ObjectName(serverSocketFactoryName);
104
 
         MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
105
 
         mbeanServer.registerMBean(service, objName);
106
 
         
107
 
         // Get Connector.
108
 
         int freeport = PortUtil.findFreePort(getHostName());
109
 
         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
110
 
         Connector connector = new Connector(sconfig);
111
 
         mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
112
 
         
113
 
         // Set xml configuration element.
114
 
         StringBuffer buf = new StringBuffer();
115
 
         buf.append("<?xml version=\"1.0\"?>\n");
116
 
         buf.append("<config>");
117
 
         buf.append(   "<invoker transport=\"" + getTransport() +"\">");
118
 
         buf.append(      "<attribute name=\"serverBindAddress\">" + getHostName() + "</attribute>");
119
 
         buf.append(      "<attribute name=\"serverBindPort\">" + freeport + "</attribute>");
120
 
         buf.append(      "<attribute name=\"serverSocketFactory\">" );
121
 
         buf.append(          serverSocketFactoryName);
122
 
         buf.append(      "</attribute>");
123
 
         buf.append(   "</invoker>");
124
 
         buf.append("</config>");
125
 
         ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
126
 
         Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
127
 
         connector.setConfiguration(xml.getDocumentElement());
128
 
         
129
 
         connector.create();
130
 
         connector.addInvocationHandler("sample", new SampleInvocationHandler());
131
 
         connector.start();
132
 
         
133
 
         
134
 
         /////////////////////////////////////
135
 
         /////    Set up client side.     //// 
136
 
         /////////////////////////////////////
137
 
         HashMap cconfig = new HashMap();
138
 
 
139
 
         // Make Client use remote invoker.
140
 
         cconfig.put(InvokerLocator.FORCE_REMOTE, "true");
141
 
         
142
 
         // Create Client.
143
 
         Client client = new Client(locator, cconfig);
144
 
         
145
 
         // Set SocketFactory in Client.
146
 
         // Note. There is no provision for using xml configuration on client side.
147
 
         SocketFactory sf = getDefaultSocketFactory();
148
 
         client.setSocketFactory(sf);
149
 
         client.connect();
150
 
         System.out.println(getName() + ": " + client.invoke("test invoke()"));
151
 
 
152
 
         
153
 
         //////////////////////////////////////////////
154
 
         /////       Set up callback handling.     //// 
155
 
         //////////////////////////////////////////////
156
 
 
157
 
         // Start callback Connector.
158
 
         // Note: there is no provision for using MBeanServer on client side.
159
 
         freeport = PortUtil.findFreePort(getHostName());
160
 
         InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
161
 
         Connector callbackConnector = new Connector(callbackLocator.getLocatorURI());
162
 
         ServerSocketFactory ssf = getDefaultCallbackServerSocketFactory();
163
 
         callbackConnector.setServerSocketFactory(ssf);
164
 
         callbackConnector.create();
165
 
         callbackConnector.addInvocationHandler("sample", new FactoryConfigSample.SampleInvocationHandler());
166
 
         callbackConnector.start();
167
 
         
168
 
         // Add callback handler.
169
 
         CallbackHandler callbackHandler = new FactoryConfigSample.CallbackHandler();
170
 
         String callbackHandleObject = "myCallbackHandleObject";
171
 
         client.addListener(callbackHandler, callbackLocator, callbackHandleObject);
172
 
         
173
 
         client.disconnect();
174
 
         callbackConnector.stop();
175
 
         connector.stop();
176
 
      }
177
 
      catch (Throwable t)
178
 
      {
179
 
         log.error(t);
180
 
         t.printStackTrace();
181
 
         fail();
182
 
      }
183
 
   }
184
 
   
185
 
   
186
 
   /** This test illustrates the following set of configuration options:
187
 
    * <p>
188
 
    * <table border cellpadding="5">
189
 
    *  <tr><td align="center"><b>side<td align="center"><b>factory<td><b>option</tr>
190
 
    *  <tr><td>server side<td align="center">server socket<td align="center">6</tr>
191
 
    *  <tr><td>server side<td align="center">socket       <td align="center">5</tr>
192
 
    *  <tr><td>client side<td align="center">server socket<td align="center">1</tr>
193
 
    *  <tr><td>client side<td align="center">socket       <td align="center">1</tr>
194
 
    * </table>
195
 
    * <p>
196
 
    * <b>Note.</b>  There is no provision for using an <code>MBeanServer</code> on
197
 
    * the client side.  
198
 
    */
199
 
   public void testFactoriesByPassingMBeanInConfig()
200
 
   {
201
 
      try
202
 
      {
203
 
         /////////////////////////////////////
204
 
         /////    Set up server side.     //// 
205
 
         /////////////////////////////////////
206
 
         HashMap sconfig = new HashMap();
207
 
         
208
 
         // Put ServerSocketFactory MBean name in config map.
209
 
         ServerSocketFactory service = getDefaultServerSocketFactory();
210
 
         String serverSocketFactoryName = "jboss:type=serversocketfactory";
211
 
         ObjectName objName = new ObjectName(serverSocketFactoryName);
212
 
         MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
213
 
         mbeanServer.registerMBean(service, objName);
214
 
         sconfig.put(ServerInvoker.SERVER_SOCKET_FACTORY, serverSocketFactoryName);
215
 
         
216
 
         // Make callback Client use remote invoker.
217
 
         sconfig.put(InvokerLocator.FORCE_REMOTE, "true");
218
 
 
219
 
         // Start Connector.
220
 
         int freeport = PortUtil.findFreePort(getHostName());
221
 
         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
222
 
         Connector connector = new Connector(locator, sconfig);
223
 
         mbeanServer.registerMBean(connector, new ObjectName("test:type=connector"));
224
 
         connector.create();
225
 
         connector.addInvocationHandler("sample", new FactoryConfigSample.SampleInvocationHandler());
226
 
         connector.start();
227
 
 
228
 
         
229
 
         /////////////////////////////////////
230
 
         /////    Set up client side.     //// 
231
 
         /////////////////////////////////////
232
 
         HashMap cconfig = new HashMap();
233
 
         
234
 
         // Make Client use remote invoker.
235
 
         cconfig.put(InvokerLocator.FORCE_REMOTE, "true");
236
 
         
237
 
         // Create Client.
238
 
         Client client = new Client(locator, cconfig);
239
 
         
240
 
         // Set server socket factory on Client.
241
 
         // Note: There is no provision for using MBeanServer on client side.         
242
 
         SocketFactory sf = getDefaultSocketFactory();
243
 
         client.setSocketFactory(sf);
244
 
         client.connect();
245
 
         System.out.println(getName() + ": " + client.invoke("test invoke()"));
246
 
         
247
 
 
248
 
         //////////////////////////////////////////////
249
 
         /////       Set up callback handling.     //// 
250
 
         //////////////////////////////////////////////
251
 
 
252
 
         // Start callback Connector.
253
 
         // Note: there is no provision for using MBeanServer on client side.
254
 
         freeport = PortUtil.findFreePort(getHostName());
255
 
         InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
256
 
         Connector callbackConnector = new Connector(callbackLocator.getLocatorURI());
257
 
         ServerSocketFactory ssf = getDefaultCallbackServerSocketFactory();
258
 
         callbackConnector.setServerSocketFactory(ssf);
259
 
         callbackConnector.create();
260
 
         callbackConnector.addInvocationHandler("sample", new FactoryConfigSample.SampleInvocationHandler());
261
 
         callbackConnector.start();
262
 
         
263
 
         // Add callback handler.
264
 
         CallbackHandler callbackHandler = new FactoryConfigSample.CallbackHandler();
265
 
         String callbackHandleObject = "myCallbackHandleObject";
266
 
         client.addListener(callbackHandler, callbackLocator, callbackHandleObject);
267
 
 
268
 
         client.disconnect();
269
 
         callbackConnector.stop();
270
 
         connector.stop();
271
 
      }
272
 
      catch (Throwable t)
273
 
      {
274
 
         log.error(t);
275
 
         t.printStackTrace();
276
 
         fail();
277
 
      }
278
 
   }
279
 
   
280
 
   
281
 
   /** This test illustrates the following set of configuration options:
282
 
    * <p>
283
 
    * <table border cellpadding="5">
284
 
    *  <tr><td align="center"><b>side<td align="center"><b>factory<td><b>option</tr>
285
 
    *  <tr><td>server side<td align="center">server socket<td align="center">8</tr>
286
 
    *  <tr><td>server side<td align="center">socket       <td align="center">8</tr>
287
 
    *  <tr><td>client side<td align="center">server socket<td align="center">6</tr>
288
 
    *  <tr><td>client side<td align="center">socket       <td align="center">5</tr>
289
 
    * </table>
290
 
    */
291
 
   public void testFactoriesFromSSLParameters()
292
 
   {
293
 
      try
294
 
      {
295
 
         /////////////////////////////////////
296
 
         /////    Set up server side.     //// 
297
 
         /////////////////////////////////////
298
 
         HashMap sconfig = new HashMap();
299
 
 
300
 
         // Make callback Client use remote invoker.
301
 
         sconfig.put(InvokerLocator.FORCE_REMOTE, "true");
302
 
         
303
 
         // Put SSL keystore parameters in config map.
304
 
         sconfig.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "false");
305
 
         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
306
 
         String keyStoreFilePath = getKeystoreFilePath();
307
 
         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
308
 
         sconfig.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
309
 
         
310
 
         // Start Connector.
311
 
         int freeport = PortUtil.findFreePort(getHostName());
312
 
         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
313
 
         Connector connector = new Connector(locator, sconfig);
314
 
         connector.create();
315
 
         connector.addInvocationHandler("sample", new FactoryConfigSample.SampleInvocationHandler());
316
 
         connector.start();
317
 
         
318
 
         
319
 
         /////////////////////////////////////
320
 
         /////    Set up client side.     //// 
321
 
         /////////////////////////////////////
322
 
         HashMap cconfig = new HashMap();
323
 
         
324
 
         // Make Client use remote invoker.
325
 
         cconfig.put(InvokerLocator.FORCE_REMOTE, "true");
326
 
         
327
 
         // Put SSL parameters in config map.
328
 
         cconfig.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "true");
329
 
         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
330
 
         String trustStoreFilePath = getTruststoreFilePath();
331
 
         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
332
 
         cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
333
 
         
334
 
         // Create Client.
335
 
         Client client = new Client(locator, cconfig);
336
 
         client.connect();
337
 
         System.out.println(getName() + ": " + client.invoke("test invoke()"));
338
 
   
339
 
         
340
 
         //////////////////////////////////////////////
341
 
         /////       Set up callback handling.     //// 
342
 
         //////////////////////////////////////////////
343
 
 
344
 
         // Start callback Connector.
345
 
         HashMap cbconfig = new HashMap();
346
 
         
347
 
         // Put SSL parameters in config map.
348
 
         cbconfig.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "true");
349
 
         cbconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
350
 
         cbconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
351
 
         cbconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
352
 
         
353
 
         freeport = PortUtil.findFreePort(getHostName());
354
 
         InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
355
 
         Connector callbackConnector = new Connector(callbackLocator.getLocatorURI(), cbconfig);
356
 
         callbackConnector.create();
357
 
         callbackConnector.addInvocationHandler("sample", new FactoryConfigSample.SampleInvocationHandler());
358
 
         callbackConnector.start();
359
 
         
360
 
         // Add callback handler.
361
 
         CallbackHandler callbackHandler = new CallbackHandler();
362
 
         String callbackHandleObject = "myCallbackHandleObject";
363
 
         client.addListener(callbackHandler, callbackLocator, callbackHandleObject);
364
 
 
365
 
         client.disconnect();
366
 
         callbackConnector.stop();
367
 
         connector.stop();
368
 
      }
369
 
      catch (Throwable t)
370
 
      {
371
 
         log.error(t);
372
 
         t.printStackTrace();
373
 
         fail();
374
 
      }
375
 
   }
376
 
   
377
 
   
378
 
   /** This test illustrates the following set of configuration options:
379
 
    * <p>
380
 
    * <table border cellpadding="5">
381
 
    *  <tr><td align="center"><b>side<td align="center"><b>factory<td><b>option</tr>
382
 
    *  <tr><td>server side<td align="center">server socket<td align="center">9</tr>
383
 
    *  <tr><td>server side<td align="center">socket       <td align="center">9</tr>
384
 
    *  <tr><td>client side<td align="center">server socket<td align="center">7</tr>
385
 
    *  <tr><td>client side<td align="center">socket       <td align="center">6</tr>
386
 
    * </table>
387
 
    */
388
 
   public void testFactoriesFromSystemSSLParameters()
389
 
   {
390
 
      try
391
 
      {
392
 
         /////////////////////////////////////
393
 
         /////    Set up server side.     //// 
394
 
         /////////////////////////////////////
395
 
         HashMap sconfig = new HashMap();
396
 
 
397
 
         // Make callback Client use remote invoker.
398
 
         sconfig.put(InvokerLocator.FORCE_REMOTE, "true");
399
 
         
400
 
         // Set SSL system properties.
401
 
         System.setProperty(SSLSocketBuilder.STANDARD_KEY_STORE_TYPE, "JKS");
402
 
         String keyStoreFilePath = getKeystoreFilePath();
403
 
         System.setProperty(SSLSocketBuilder.STANDARD_KEY_STORE_FILE_PATH, keyStoreFilePath);
404
 
         System.setProperty(SSLSocketBuilder.STANDARD_KEY_STORE_PASSWORD, "unit-tests-server");
405
 
         System.setProperty(SSLSocketBuilder.STANDARD_TRUST_STORE_TYPE, "JKS");
406
 
         String trustStoreFilePath = getTruststoreFilePath();
407
 
         System.setProperty(SSLSocketBuilder.STANDARD_TRUST_STORE_FILE_PATH, trustStoreFilePath);
408
 
         System.setProperty(SSLSocketBuilder.STANDARD_TRUST_STORE_PASSWORD, "unit-tests-client");
409
 
         
410
 
         // Start Connector.
411
 
         int freeport = PortUtil.findFreePort(getHostName());
412
 
         InvokerLocator locator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
413
 
         Connector connector = new Connector(locator, sconfig);
414
 
         connector.create();
415
 
         connector.addInvocationHandler("sample", new FactoryConfigSample.SampleInvocationHandler());
416
 
         connector.start();
417
 
         
418
 
         
419
 
         /////////////////////////////////////
420
 
         /////    Set up client side.     //// 
421
 
         /////////////////////////////////////
422
 
         HashMap cconfig = new HashMap();
423
 
         
424
 
         // Make Client use remote invoker.
425
 
         cconfig.put(InvokerLocator.FORCE_REMOTE, "true");
426
 
     
427
 
         // Create Client.
428
 
         Client client = new Client(locator, cconfig);
429
 
         client.connect();
430
 
         System.out.println(getName() + ": " + client.invoke("test invoke()"));
431
 
         
432
 
         
433
 
         //////////////////////////////////////////////
434
 
         /////       Set up callback handling.     //// 
435
 
         //////////////////////////////////////////////
436
 
 
437
 
         // Start callback Connector.
438
 
         HashMap cbconfig = new HashMap();
439
 
         
440
 
         // Make callback Connector server socket run in client mode.
441
 
         cbconfig.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "true");
442
 
         
443
 
         freeport = PortUtil.findFreePort(getHostName());
444
 
         InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
445
 
         Connector callbackConnector = new Connector(callbackLocator.getLocatorURI(), cbconfig);
446
 
         callbackConnector.create();
447
 
         callbackConnector.addInvocationHandler("sample", new FactoryConfigSample.SampleInvocationHandler());
448
 
         callbackConnector.start();
449
 
         
450
 
         // Add callback handler.
451
 
         CallbackHandler callbackHandler = new CallbackHandler();
452
 
         String callbackHandleObject = "myCallbackHandleObject";
453
 
         client.addListener(callbackHandler, callbackLocator, callbackHandleObject);
454
 
 
455
 
         client.disconnect();
456
 
         callbackConnector.stop();
457
 
         connector.stop();
458
 
      }
459
 
      catch (Throwable t)
460
 
      {
461
 
         log.error(t);
462
 
         t.printStackTrace();
463
 
         fail();
464
 
      }
465
 
   }
466
 
   
467
 
   
468
 
   protected String getHostName()
469
 
   {
470
 
      return "localhost";
471
 
   }
472
 
   
473
 
   
474
 
   protected String getTransport()
475
 
   {
476
 
      return "sslsocket";
477
 
   }
478
 
   
479
 
   
480
 
   protected String getKeystoreFilePath()
481
 
   {
482
 
      File file = new File(FactoryConfigSSLSample.class.getResource("keystore").getFile());
483
 
      return file.getPath();
484
 
   }
485
 
   
486
 
   
487
 
   protected static String getTruststoreFilePath()
488
 
   {
489
 
      File file = new File(FactoryConfigSSLSample.class.getResource("truststore").getFile());
490
 
      return file.getPath();
491
 
   }
492
 
   
493
 
   
494
 
   protected ServerSocketFactory getDefaultServerSocketFactory() throws Exception
495
 
   {
496
 
      HashMap config = new HashMap();
497
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
498
 
      String keyStoreFilePath = getKeystoreFilePath();
499
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
500
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
501
 
      config.put(SSLSocketBuilder.REMOTING_SSL_PROTOCOL, "SSL");
502
 
      SSLSocketBuilder builder = new SSLSocketBuilder(config);
503
 
      builder.setUseSSLServerSocketFactory(false);
504
 
      SSLServerSocketFactoryService service = new SSLServerSocketFactoryService();
505
 
      service.setSSLSocketBuilder(builder);
506
 
      service.start();
507
 
      return service;
508
 
   }
509
 
   
510
 
   protected SocketFactory getDefaultSocketFactory() throws Exception
511
 
   {
512
 
      HashMap config = new HashMap();
513
 
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
514
 
      String trustStoreFilePath = getTruststoreFilePath();
515
 
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
516
 
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
517
 
      config.put(SSLSocketBuilder.REMOTING_SSL_PROTOCOL, "SSL");
518
 
      SSLSocketBuilder builder = new SSLSocketBuilder(config);
519
 
      builder.setUseSSLSocketFactory(false);
520
 
      SSLSocketFactoryService service = new SSLSocketFactoryService();
521
 
      service.setSSLSocketBuilder(builder);
522
 
      service.start();
523
 
      return service;
524
 
   }
525
 
   
526
 
   protected ServerSocketFactory getDefaultCallbackServerSocketFactory() throws Exception
527
 
   {
528
 
      HashMap config = new HashMap();
529
 
      config.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "true");
530
 
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
531
 
      String trustStoreFilePath = getTruststoreFilePath();
532
 
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
533
 
      config.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
534
 
      config.put(SSLSocketBuilder.REMOTING_SSL_PROTOCOL, "SSL");
535
 
      SSLSocketBuilder builder = new SSLSocketBuilder(config);
536
 
      builder.setUseSSLServerSocketFactory(false);
537
 
      SSLServerSocketFactoryService service = new SSLServerSocketFactoryService();
538
 
      service.setSSLSocketBuilder(builder);
539
 
      service.start();
540
 
      return service;
541
 
   }
542
 
   
543
 
   protected SocketFactory getDefaultCallbackSocketFactory() throws Exception
544
 
   {
545
 
      HashMap config = new HashMap();
546
 
      config.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "false");
547
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_TYPE, "JKS");
548
 
      String keyStoreFilePath = getKeystoreFilePath();
549
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_FILE_PATH, keyStoreFilePath);
550
 
      config.put(SSLSocketBuilder.REMOTING_KEY_STORE_PASSWORD, "unit-tests-server");
551
 
      config.put(SSLSocketBuilder.REMOTING_SSL_PROTOCOL, "SSL");
552
 
      SSLSocketBuilder builder = new SSLSocketBuilder(config);
553
 
      builder.setUseSSLSocketFactory(false);
554
 
      SSLSocketFactoryService service = new SSLSocketFactoryService();
555
 
      service.setSSLSocketBuilder(builder);
556
 
      service.start();
557
 
      return builder.createSSLSocketFactory();
558
 
   }
559
 
}