~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/http/EmptyURITestCase.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 2009, Red Hat Middleware LLC, and individual contributors
 
4
 * as indicated by the @author tags. See the copyright.txt file in the
 
5
 * distribution for a 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.http;
 
24
 
 
25
import java.io.IOException;
 
26
import java.net.InetAddress;
 
27
import java.security.AccessController;
 
28
import java.security.PrivilegedAction;
 
29
import java.util.HashMap;
 
30
import java.util.Map;
 
31
 
 
32
import javax.management.MBeanServer;
 
33
 
 
34
import junit.framework.TestCase;
 
35
 
 
36
import org.apache.log4j.ConsoleAppender;
 
37
import org.apache.log4j.Level;
 
38
import org.apache.log4j.Logger;
 
39
import org.apache.log4j.PatternLayout;
 
40
import org.jboss.remoting.CannotConnectException;
 
41
import org.jboss.remoting.Client;
 
42
import org.jboss.remoting.InvocationRequest;
 
43
import org.jboss.remoting.InvokerLocator;
 
44
import org.jboss.remoting.InvokerRegistry;
 
45
import org.jboss.remoting.ServerInvocationHandler;
 
46
import org.jboss.remoting.ServerInvoker;
 
47
import org.jboss.remoting.callback.InvokerCallbackHandler;
 
48
import org.jboss.remoting.transport.Connector;
 
49
import org.jboss.remoting.transport.PortUtil;
 
50
import org.jboss.remoting.transport.ServerFactory;
 
51
import org.jboss.remoting.transport.coyote.CoyoteInvoker;
 
52
import org.jboss.remoting.transport.http.TransportClientFactory;
 
53
 
 
54
 
 
55
/**
 
56
 * Unit test for JBREM-1168.
 
57
 * 
 
58
 * @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
 
59
 * @version $Rev$
 
60
 * <p>
 
61
 * Copyright Dec 13, 2009
 
62
 * </p>
 
63
 */
 
64
public class EmptyURITestCase extends TestCase
 
65
{
 
66
   private static Logger log = Logger.getLogger(EmptyURITestCase.class);
 
67
   
 
68
   private static boolean firstTime = true;
 
69
   
 
70
   protected String host;
 
71
   protected int port;
 
72
   protected String locatorURI;
 
73
   protected InvokerLocator serverLocator;
 
74
   protected Connector connector;
 
75
   protected TestInvocationHandler invocationHandler;
 
76
 
 
77
   
 
78
   public void setUp() throws Exception
 
79
   {
 
80
      if (firstTime)
 
81
      {
 
82
         firstTime = false;
 
83
         Logger.getLogger("org.jboss.remoting").setLevel(Level.INFO);
 
84
         Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
 
85
         String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
 
86
         PatternLayout layout = new PatternLayout(pattern);
 
87
         ConsoleAppender consoleAppender = new ConsoleAppender(layout);
 
88
         Logger.getRootLogger().addAppender(consoleAppender);
 
89
         
 
90
         AccessController.doPrivileged( new PrivilegedAction()
 
91
         {
 
92
            public Object run()
 
93
            {
 
94
               InvokerRegistry.registerInvokerFactories("http", TransportClientFactory.class, TestCoyoteInvokerFactory.class);
 
95
               return null;
 
96
            }
 
97
         });
 
98
      }
 
99
   }
 
100
 
 
101
   
 
102
   public void tearDown()
 
103
   {
 
104
   }
 
105
   
 
106
   
 
107
   public void testEmptyURI() throws Throwable
 
108
   {
 
109
      log.info("entering " + getName());
 
110
      
 
111
      // Start server.
 
112
      setupServer();
 
113
      
 
114
      // Create client.
 
115
      InvokerLocator clientLocator = new InvokerLocator(locatorURI);
 
116
      HashMap clientConfig = new HashMap();
 
117
      clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
 
118
      addExtraClientConfig(clientConfig);
 
119
      Client client = new Client(clientLocator, clientConfig);
 
120
      client.connect();
 
121
      log.info("client is connected");
 
122
      
 
123
      // Test connections.
 
124
      try
 
125
      {
 
126
         Object response = client.invoke("abc");
 
127
         fail("expected CannotConnectException, got: " + response);
 
128
      }
 
129
      catch (CannotConnectException e)
 
130
      {
 
131
         log.info("got expected CannotConnectException");
 
132
      }
 
133
      catch (Throwable t)
 
134
      {
 
135
         fail("expected CannotConnectException, got: " + t);         
 
136
      }
 
137
      
 
138
      client.disconnect();
 
139
      shutdownServer();
 
140
      log.info(getName() + " PASSES");
 
141
   }
 
142
   
 
143
   
 
144
   protected String getTransport()
 
145
   {
 
146
      return "http";
 
147
   }
 
148
   
 
149
   
 
150
   protected void addExtraClientConfig(Map config) {}
 
151
   protected void addExtraServerConfig(Map config) {}
 
152
   
 
153
 
 
154
   protected void setupServer() throws Exception
 
155
   {
 
156
      host = InetAddress.getLocalHost().getHostAddress();
 
157
      port = PortUtil.findFreePort(host);
 
158
      locatorURI = getTransport() + "://" + host + ":" + port;
 
159
      String metadata = System.getProperty("remoting.metadata");
 
160
      if (metadata != null)
 
161
      {
 
162
         locatorURI += "/?" + metadata;
 
163
      }
 
164
      serverLocator = new InvokerLocator(locatorURI);
 
165
      log.info("Starting remoting server with locator uri of: " + locatorURI);
 
166
      HashMap config = new HashMap();
 
167
      config.put(InvokerLocator.FORCE_REMOTE, "true");
 
168
      addExtraServerConfig(config);
 
169
      connector = new Connector(serverLocator, config);
 
170
      connector.create();
 
171
      invocationHandler = new TestInvocationHandler();
 
172
      connector.addInvocationHandler("test", invocationHandler);
 
173
      connector.start();
 
174
   }
 
175
   
 
176
   
 
177
   protected void shutdownServer() throws Exception
 
178
   {
 
179
      if (connector != null)
 
180
         connector.stop();
 
181
   }
 
182
   
 
183
   
 
184
   static class TestInvocationHandler implements ServerInvocationHandler
 
185
   {
 
186
      public void addListener(InvokerCallbackHandler callbackHandler) {}
 
187
      public Object invoke(final InvocationRequest invocation) throws Throwable
 
188
      {
 
189
         return invocation.getParameter();
 
190
      }
 
191
      public void removeListener(InvokerCallbackHandler callbackHandler) {}
 
192
      public void setMBeanServer(MBeanServer server) {}
 
193
      public void setInvoker(ServerInvoker invoker) {}
 
194
   }
 
195
   
 
196
   static public class TestCoyoteInvokerFactory implements ServerFactory
 
197
   {
 
198
      public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
 
199
      {
 
200
         return new TestCoyoteInvoker(locator, config);
 
201
      }
 
202
      public boolean supportsSSL()
 
203
      {
 
204
         return false;
 
205
      }
 
206
   }
 
207
   
 
208
   
 
209
   static class TestCoyoteInvoker extends CoyoteInvoker
 
210
   {
 
211
      public TestCoyoteInvoker(InvokerLocator locator)
 
212
      {
 
213
         super(locator);
 
214
      }
 
215
 
 
216
      public TestCoyoteInvoker(InvokerLocator locator, Map configuration)
 
217
      {
 
218
         super(locator, configuration);
 
219
      }
 
220
      
 
221
      public void service(org.apache.coyote.Request req, org.apache.coyote.Response res) throws Exception
 
222
      {
 
223
         byte[] b = new byte[]{};
 
224
         req.requestURI().setBytes(b, 0, 0);
 
225
         log.info(this + ".service()");
 
226
         super.service(req, res);
 
227
      }
 
228
   }
 
229
}
 
 
b'\\ No newline at end of file'