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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/transport/socket/ssl/basic/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.basic;
 
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.Iterator;
 
43
import java.util.Map;
 
44
import java.util.Set;
 
45
 
 
46
/**
 
47
 * This is the concrete test for invoker server.
 
48
 *
 
49
 * @author <a href="mailto:telrod@e2technologies.net">Tom Elrod</a>
 
50
 */
 
51
public class InvokerServerTest extends ServerTestCase implements SSLInvokerConstants
 
52
{
 
53
   private int serverPort;
 
54
   private Connector connector = null;
 
55
 
 
56
   private static final Logger log = Logger.getLogger(InvokerServerTest.class);
 
57
 
 
58
   public void init(Map metatdata) throws Exception
 
59
   {
 
60
      serverPort = getPort();
 
61
      if(serverPort < 0)
 
62
      {
 
63
         serverPort = TestUtil.getRandomPort();
 
64
      }
 
65
      log.debug("port = " + serverPort);
 
66
 
 
67
      connector = new Connector();
 
68
      InvokerLocator locator = new InvokerLocator(buildLocatorURI(metatdata));
 
69
      connector.setInvokerLocator(locator.getLocatorURI());
 
70
 
 
71
      ServerSocketFactory svrSocketFactory = createServerSocketFactory();
 
72
      connector.setServerSocketFactory(svrSocketFactory);
 
73
      
 
74
      connector.create();
 
75
      connector.addInvocationHandler(getSubsystem(), getServerInvocationHandler());
 
76
      connector.start();
 
77
   }
 
78
   
 
79
   protected String getTransport()
 
80
   {
 
81
      return transport;
 
82
   }
 
83
   
 
84
   protected int getPort()
 
85
   {
 
86
      return port;
 
87
   }
 
88
   
 
89
   private ServerSocketFactory createServerSocketFactory()
 
90
         throws NoSuchAlgorithmException, KeyManagementException, IOException,
 
91
                CertificateException, UnrecoverableKeyException, KeyStoreException
 
92
   {
 
93
      ServerSocketFactory serverSocketFactory = null;
 
94
 
 
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");
 
100
 
 
101
      SSLSocketBuilder server = new SSLSocketBuilder();
 
102
      serverSocketFactory = server.createSSLServerSocketFactory();
 
103
 
 
104
      return serverSocketFactory;
 
105
   }
 
106
 
 
107
   private String buildLocatorURI(Map metadata)
 
108
   {
 
109
      if(metadata == null || metadata.size() == 0)
 
110
      {
 
111
         return getTransport() + "://" + host + ":" + serverPort;
 
112
      }
 
113
      else
 
114
      {
 
115
         StringBuffer uriBuffer = new StringBuffer(getTransport() + "://localhost:" + serverPort);
 
116
         
 
117
         Set keys = metadata.keySet();
 
118
         if(keys.size() > 0)
 
119
         {
 
120
            uriBuffer.append("/?");
 
121
         }
 
122
 
 
123
         Iterator itr = keys.iterator();
 
124
         while(itr.hasNext())
 
125
         {
 
126
            String key = (String) itr.next();
 
127
            String value = (String) metadata.get(key);
 
128
            uriBuffer.append(key + "=" + value + "&");
 
129
         }
 
130
         return uriBuffer.substring(0, uriBuffer.length() - 1);
 
131
      }
 
132
   }
 
133
 
 
134
   protected String getSubsystem()
 
135
   {
 
136
      return "mock";
 
137
   }
 
138
 
 
139
   protected ServerInvocationHandler getServerInvocationHandler()
 
140
   {
 
141
      return new MockServerInvocationHandler();
 
142
   }
 
143
 
 
144
   protected void setUp() throws Exception
 
145
   {
 
146
      init(null);
 
147
   }
 
148
 
 
149
   protected void tearDown() throws Exception
 
150
   {
 
151
      if(connector != null)
 
152
      {
 
153
         connector.stop();
 
154
         connector.destroy();
 
155
      }
 
156
   }
 
157
 
 
158
   public static void main(String[] args)
 
159
   {
 
160
      InvokerServerTest server = new InvokerServerTest();
 
161
      try
 
162
      {
 
163
         server.setUp();
 
164
 
 
165
         Thread.sleep(1200000);
 
166
      }
 
167
      catch(Exception e)
 
168
      {
 
169
         e.printStackTrace();
 
170
      }
 
171
   }
 
172
 
 
173
}