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.
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.
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.
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.
23
package org.jboss.test.remoting.transport.http;
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;
32
import javax.management.MBeanServer;
34
import junit.framework.TestCase;
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;
56
* Unit test for JBREM-1168.
58
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
61
* Copyright Dec 13, 2009
64
public class EmptyURITestCase extends TestCase
66
private static Logger log = Logger.getLogger(EmptyURITestCase.class);
68
private static boolean firstTime = true;
70
protected String host;
72
protected String locatorURI;
73
protected InvokerLocator serverLocator;
74
protected Connector connector;
75
protected TestInvocationHandler invocationHandler;
78
public void setUp() throws Exception
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);
90
AccessController.doPrivileged( new PrivilegedAction()
94
InvokerRegistry.registerInvokerFactories("http", TransportClientFactory.class, TestCoyoteInvokerFactory.class);
102
public void tearDown()
107
public void testEmptyURI() throws Throwable
109
log.info("entering " + getName());
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);
121
log.info("client is connected");
126
Object response = client.invoke("abc");
127
fail("expected CannotConnectException, got: " + response);
129
catch (CannotConnectException e)
131
log.info("got expected CannotConnectException");
135
fail("expected CannotConnectException, got: " + t);
140
log.info(getName() + " PASSES");
144
protected String getTransport()
150
protected void addExtraClientConfig(Map config) {}
151
protected void addExtraServerConfig(Map config) {}
154
protected void setupServer() throws Exception
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)
162
locatorURI += "/?" + metadata;
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);
171
invocationHandler = new TestInvocationHandler();
172
connector.addInvocationHandler("test", invocationHandler);
177
protected void shutdownServer() throws Exception
179
if (connector != null)
184
static class TestInvocationHandler implements ServerInvocationHandler
186
public void addListener(InvokerCallbackHandler callbackHandler) {}
187
public Object invoke(final InvocationRequest invocation) throws Throwable
189
return invocation.getParameter();
191
public void removeListener(InvokerCallbackHandler callbackHandler) {}
192
public void setMBeanServer(MBeanServer server) {}
193
public void setInvoker(ServerInvoker invoker) {}
196
static public class TestCoyoteInvokerFactory implements ServerFactory
198
public ServerInvoker createServerInvoker(InvokerLocator locator, Map config) throws IOException
200
return new TestCoyoteInvoker(locator, config);
202
public boolean supportsSSL()
209
static class TestCoyoteInvoker extends CoyoteInvoker
211
public TestCoyoteInvoker(InvokerLocator locator)
216
public TestCoyoteInvoker(InvokerLocator locator, Map configuration)
218
super(locator, configuration);
221
public void service(org.apache.coyote.Request req, org.apache.coyote.Response res) throws Exception
223
byte[] b = new byte[]{};
224
req.requestURI().setBytes(b, 0, 0);
225
log.info(this + ".service()");
226
super.service(req, res);
b'\\ No newline at end of file'