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

« back to all changes in this revision

Viewing changes to src/tests/org/jboss/test/remoting/marshall/encrypt/EncryptingMarshallerTestServer.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.marshall.encrypt; 
 
24
 
 
25
import javax.management.MBeanServer;
 
26
import org.jboss.jrunit.extensions.ServerTestCase;
 
27
import org.jboss.remoting.InvocationRequest;
 
28
import org.jboss.remoting.InvokerLocator;
 
29
import org.jboss.remoting.ServerInvocationHandler;
 
30
import org.jboss.remoting.ServerInvoker;
 
31
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
32
import org.jboss.remoting.marshal.MarshalFactory;
 
33
import org.jboss.remoting.marshal.encryption.EncryptingMarshaller;
 
34
import org.jboss.remoting.marshal.encryption.EncryptingUnMarshaller;
 
35
import org.jboss.remoting.serialization.SerializationStreamFactory;
 
36
import org.jboss.remoting.transport.Connector;
 
37
 
 
38
 
 
39
/**
 
40
 * A EncryptingMarshallerTestServer.
 
41
 *
 
42
 * @author Anil.Saldhana@jboss.org
 
43
 * @version $Revision: 1402 $ 
 
44
 */
 
45
 
 
46
public class EncryptingMarshallerTestServer extends ServerTestCase
 
47
{
 
48
   private static final Object lock = new Object(); 
 
49
 
 
50
   public void setUp()
 
51
   {
 
52
      String javauri = "socket://localhost:5300/?datatype=encrypt"
 
53
                                      + "&"+ InvokerLocator.SERIALIZATIONTYPE + "=" +
 
54
                                      SerializationStreamFactory.JAVA_ENCRYPT;
 
55
      String jbosslocatorURI = "socket://localhost:5400/?datatype=encrypt"
 
56
                                      + "&"+ InvokerLocator.SERIALIZATIONTYPE + "=" +
 
57
                                      SerializationStreamFactory.JBOSS_ENCRYPT;
 
58
      EncryptionServerThread jbossThread = 
 
59
         new EncryptionServerThread(jbosslocatorURI,2);
 
60
      EncryptionServerThread javaThread = 
 
61
         new EncryptionServerThread(javauri,2);
 
62
      
 
63
      //Start the two threads - one for JBoss Invocation and one for Java invocation
 
64
      jbossThread.start();
 
65
      javaThread.start(); 
 
66
   } 
 
67
 
 
68
    
 
69
 
 
70
   public static void main(String[] args)
 
71
   {
 
72
      try
 
73
      {
 
74
         new EncryptingMarshallerTestServer().setUp();
 
75
      }
 
76
      catch (Exception e)
 
77
      { 
 
78
         e.printStackTrace();
 
79
      }
 
80
   }
 
81
   
 
82
   public class EncryptionServerThread extends Thread
 
83
   {
 
84
      private String locatorURI = null;
 
85
      private int counter = 0;
 
86
      public EncryptionServerThread(String url, int counter)
 
87
      {
 
88
         this.counter = counter;
 
89
         this.locatorURI = url;  
 
90
      }
 
91
      
 
92
      public void run()
 
93
      {
 
94
         try
 
95
         {
 
96
            
 
97
            MarshalFactory.addMarshaller("encrypt", 
 
98
                                         new EncryptingMarshaller(), 
 
99
                                         new EncryptingUnMarshaller()); 
 
100
            InvokerLocator locator = new InvokerLocator(locatorURI);
 
101
            System.out.println("Starting remoting server with locator uri of: " + locatorURI);
 
102
            Connector connector = new Connector();
 
103
            connector.setInvokerLocator(locator.getLocatorURI());
 
104
            connector.create();
 
105
            JavaInvocationHandler invocationHandler = new JavaInvocationHandler(counter);
 
106
            connector.addInvocationHandler("sample", invocationHandler);
 
107
            connector.start();
 
108
 
 
109
            synchronized(lock)
 
110
            {
 
111
               lock.wait();
 
112
            }
 
113
 
 
114
            connector.stop();
 
115
            connector.destroy();
 
116
         }
 
117
         catch(Exception e)
 
118
         {
 
119
            e.printStackTrace();
 
120
         }
 
121
      } 
 
122
   }
 
123
   
 
124
   
 
125
   /**
 
126
    * Noop Invocation Handler
 
127
    * @author <a href="anil.saldhana@jboss.com">Anil Saldhana</a>
 
128
    * @version $Revision: 1402 $
 
129
    */
 
130
   public abstract class AdapterInvocationHandler implements ServerInvocationHandler
 
131
   { 
 
132
      public void addListener(InvokerCallbackHandler callbackHandler)
 
133
      { 
 
134
      }
 
135
 
 
136
      public abstract Object invoke(InvocationRequest invocation) throws Throwable;
 
137
 
 
138
      public void removeListener(InvokerCallbackHandler callbackHandler)
 
139
      { 
 
140
      }
 
141
 
 
142
      public void setInvoker(ServerInvoker invoker)
 
143
      {  
 
144
      }
 
145
 
 
146
      public void setMBeanServer(MBeanServer server)
 
147
      { 
 
148
      } 
 
149
   }
 
150
 
 
151
 
 
152
   /**
 
153
    * Simple invocation handler implementation.
 
154
    * This is the code that will be called with the invocation payload from the client.
 
155
    */
 
156
   public class JavaInvocationHandler extends AdapterInvocationHandler
 
157
   { 
 
158
      private int counter = 0;
 
159
      public JavaInvocationHandler(int counter)
 
160
      {
 
161
         this.counter = counter; 
 
162
      }
 
163
 
 
164
      /**
 
165
       * called to handle a specific invocation
 
166
       *
 
167
       * @param invocation
 
168
       * @return
 
169
       * @throws Throwable
 
170
       */
 
171
      public Object invoke(InvocationRequest invocation) throws Throwable
 
172
      { 
 
173
         if(++counter == 2)
 
174
         { 
 
175
            synchronized(lock)
 
176
            {
 
177
               lock.notify();
 
178
            }
 
179
         }
 
180
         Object obj = invocation.getParameter(); 
 
181
         return obj;
 
182
      } 
 
183
   }
 
184
}
 
185