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.
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.
22
package org.jboss.test.remoting.ipv6;
24
import java.io.InputStream;
25
import java.io.OutputStream;
26
import java.net.InetAddress;
27
import java.net.ServerSocket;
28
import java.net.Socket;
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.Client;
41
import org.jboss.remoting.InvocationRequest;
42
import org.jboss.remoting.InvokerLocator;
43
import org.jboss.remoting.ServerInvocationHandler;
44
import org.jboss.remoting.ServerInvoker;
45
import org.jboss.remoting.callback.Callback;
46
import org.jboss.remoting.callback.HandleCallbackException;
47
import org.jboss.remoting.callback.InvokerCallbackHandler;
48
import org.jboss.remoting.transport.Connector;
49
import org.jboss.remoting.transport.PortUtil;
54
* Unit test for JBREM-852.
56
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
57
* @version $Revision: 1.1 $
59
* Copyright Dec 4, 2007
62
public class IPv6TestCase extends TestCase
64
private static Logger log = Logger.getLogger(IPv6TestCase.class);
66
private static boolean firstTime = true;
67
private static boolean ipv6IsAvailable = true;
69
// remoting server connector
70
private Connector connector;
71
private InvokerLocator serverLocator;
72
private TestInvocationHandler invocationHandler;
75
public void setUp() throws Exception
80
Logger.getLogger("org.jboss.remoting").setLevel(Level.DEBUG);
81
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
82
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
83
PatternLayout layout = new PatternLayout(pattern);
84
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
85
Logger.getRootLogger().addAppender(consoleAppender);
86
log.info("java.version: " + System.getProperty("java.version"));
90
InetAddress addr = InetAddress.getByName("[::1]");
91
new ServerSocket(3333, 200, addr);
95
if ("Protocol family unavailable".equalsIgnoreCase(e.getMessage()) ||
96
"Protocol family not supported".equalsIgnoreCase(e.getMessage()))
98
ipv6IsAvailable = false;
99
log.info("ipV6 is not available");
106
public void tearDown()
111
public void testRawIPv6() throws Throwable
113
log.info("entering " + getName());
114
if (!ipv6IsAvailable) return;
116
final InetAddress addr = InetAddress.getByName("[::1]");
124
ServerSocket ss = new ServerSocket(4446, 200, addr);
125
log.info("ss address: " + ss.getInetAddress());
126
Socket s = ss.accept();
127
InputStream is = s.getInputStream();
128
log.info("read: " + is.read());
134
log.error("error", e);
142
Socket s = new Socket(addr, 4446);
143
log.info("s address: " + s.getInetAddress());
144
log.info("s local address: " + s.getLocalAddress());
145
OutputStream os = s.getOutputStream();
147
log.info("wrote 17");
149
log.info(getName() + " PASSES");
154
public void testRemotingIPv6Loopback() throws Throwable
156
log.info("entering " + getName());
157
if (!ipv6IsAvailable) return;
159
doRemotingTest("[::1]");
160
log.info(getName() + " PASSES");
164
public void testRemotingIPv6Any() throws Throwable
166
log.info("entering " + getName());
167
if (!ipv6IsAvailable) return;
168
doRemotingTest("[::]");
169
log.info(getName() + " PASSES");
173
public void testRemotingIPv4Mapped() throws Throwable
175
if (!ipv6IsAvailable) return;
176
doRemotingTest("[::ffff:127.0.0.1]");
180
protected void doRemotingTest(String host) throws Throwable
183
InetAddress[] addresses = InetAddress.getAllByName("localhost");
184
for (int i = 0; i < addresses.length; i++)
186
log.info("addresses[" + i + "]: " + addresses[i]);
189
int port = PortUtil.findFreePort(host);
190
String locatorURI = "socket://" + host + ":" + port + "/?timeout=10000";
191
serverLocator = new InvokerLocator(locatorURI);
192
log.info("Starting remoting server with locator uri of: " + locatorURI);
193
HashMap config = new HashMap();
194
config.put(InvokerLocator.FORCE_REMOTE, "true");
195
addExtraServerConfig(config);
196
connector = new Connector(serverLocator, config);
198
invocationHandler = new TestInvocationHandler();
199
connector.addInvocationHandler("sample", invocationHandler);
203
InvokerLocator clientLocator1 = new InvokerLocator(locatorURI);
204
HashMap clientConfig = new HashMap();
205
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
206
addExtraClientConfig(clientConfig);
207
Client client = new Client(clientLocator1, clientConfig);
209
log.info("client is connected");
212
assertEquals("abc", client.invoke("abc"));
213
log.info("connection is good");
220
protected String getTransport()
226
protected void addExtraClientConfig(Map config) {}
227
protected void addExtraServerConfig(Map config) {}
230
static class TestInvocationHandler implements ServerInvocationHandler
232
public void addListener(InvokerCallbackHandler callbackHandler) {}
233
public Object invoke(final InvocationRequest invocation) throws Throwable
235
return invocation.getParameter();
237
public void removeListener(InvokerCallbackHandler callbackHandler) {}
238
public void setMBeanServer(MBeanServer server) {}
239
public void setInvoker(ServerInvoker invoker) {}
243
static class TestCallbackHandler implements InvokerCallbackHandler
245
public void handleCallback(Callback callback) throws HandleCallbackException
247
log.info("received callback");
b'\\ No newline at end of file'