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.detection.jndi.startup;
24
import org.apache.log4j.Level;
25
import org.jboss.jrunit.extensions.ServerTestCase;
26
import org.jboss.remoting.InvokerLocator;
27
import org.jboss.remoting.detection.jndi.JNDIDetector;
28
import org.jboss.remoting.network.NetworkRegistry;
29
import org.jboss.remoting.samples.detection.jndi.SimpleJNDIServer;
30
import org.jboss.remoting.transport.Connector;
31
import org.jboss.remoting.util.SecurityUtility;
32
import org.jboss.test.remoting.TestUtil;
33
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
34
import org.jnp.server.Main;
35
import javax.management.MBeanServer;
36
import javax.management.MBeanServerFactory;
37
import javax.management.ObjectName;
39
import java.lang.reflect.Method;
40
import java.net.InetAddress;
41
import java.security.AccessController;
42
import java.security.PrivilegedActionException;
43
import java.security.PrivilegedExceptionAction;
46
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
48
public class JNDIDetectorServer extends ServerTestCase
50
private int detectorPort = 1099;
51
private String contextFactory = "org.jnp.interfaces.NamingContextFactory";
52
private String urlPackage = "org.jboss.naming:org.jnp.interfaces";
54
private JNDIDetector detector;
55
private Connector connector;
56
private NetworkRegistry registry;
58
public void setUp() throws Exception
61
Object namingBean = null;
62
Class namingBeanImplClass = null;
65
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
66
namingBean = namingBeanImplClass.newInstance();
67
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
68
setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
69
startMethod.invoke(namingBean, new Object[] {});
73
SimpleJNDIServer.println("Cannot find NamingBeanImpl: must be running jdk 1.4");
77
String host = InetAddress.getLocalHost().getHostName();
78
Main JNDIServer = new Main();
79
if (namingBean != null)
81
Class namingBeanClass = Class.forName("org.jnp.server.NamingBean");
82
Method setNamingInfoMethod = JNDIServer.getClass().getMethod("setNamingInfo", new Class[] {namingBeanClass});
83
setNamingInfoMethod.invoke(JNDIServer, new Object[] {namingBean});
85
JNDIServer.setPort(port);
86
JNDIServer.setBindAddress(host);
88
System.out.println("Started JNDI server on " + host + ":" + port);
90
String detectorHost = InetAddress.getLocalHost().getHostName();
92
detector = new JNDIDetector();
93
detector.setCleanDetectionNumber(2);
95
System.setProperty("jboss.identity", String.valueOf(System.currentTimeMillis()));
96
System.out.println("jboss.identity = " + System.getProperty("jboss.identity"));
98
MBeanServer server = MBeanServerFactory.createMBeanServer();
100
registry = NetworkRegistry.getInstance();
101
server.registerMBean(registry, new ObjectName("remoting:type=NetworkRegistry"));
103
port = TestUtil.getRandomPort();
104
System.out.println("port = " + port);
106
String bindAddr = System.getProperty("jrunit.bind_addr", host);
107
InvokerLocator locator = new InvokerLocator("socket://" + bindAddr + ":" + port);
109
System.out.println("Starting remoting server with locator uri of: " + locator.getLocatorURI());
110
connector = new Connector();
111
connector.setInvokerLocator(locator.getLocatorURI());
114
MockServerInvocationHandler handler = new MockServerInvocationHandler();
115
connector.addInvocationHandler("mock", handler);
117
ObjectName obj = new ObjectName("jboss.remoting:type=Connector,transport=" + locator.getProtocol());
118
server.registerMBean(connector, obj);
119
//connector.create();
122
//Need to set new domain for identity
123
server.registerMBean(detector, new ObjectName("remoting:type=JNDIDetector"));
125
// set config info for detector and start it.
126
detector.setPort(detectorPort);
127
detector.setHost(detectorHost);
128
detector.setContextFactory(contextFactory);
129
detector.setURLPackage(urlPackage);
134
public void tearDown() throws Exception
136
if (detector != null)
140
if (connector != null)
147
public static void main(String[] args)
149
org.apache.log4j.BasicConfigurator.configure();
150
org.apache.log4j.Category.getRoot().setLevel(Level.DEBUG);
154
JNDIDetectorServer test = new JNDIDetectorServer();
165
static private void setSystemProperty(final String name, final String value)
167
if (SecurityUtility.skipAccessControl())
169
System.setProperty(name, value);
175
AccessController.doPrivileged( new PrivilegedExceptionAction()
177
public Object run() throws Exception
179
return System.setProperty(name, value);
183
catch (PrivilegedActionException e)
185
throw (RuntimeException) e.getCause();
b'\\ No newline at end of file'