Author: ron.sigal(a)jboss.com
Date: 2008-09-08 02:18:18 -0400 (Mon, 08 Sep 2008)
New Revision: 4551
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/transporter/custom/server/JNDIServer.java
Log:
JBREM-1033: Creates NamingBeanImpl reflectively to enable use of older jnpserver.jar.
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java 2008-09-08
06:16:03 UTC (rev 4550)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/detection/jndi/JNDIDetector.java 2008-09-08
06:18:18 UTC (rev 4551)
@@ -31,7 +31,6 @@
import org.jboss.remoting.util.SecurityUtility;
import org.jnp.interfaces.NamingContextFactory;
import org.jnp.server.Main;
-import org.jnp.server.NamingBeanImpl;
import javax.naming.Binding;
import javax.naming.Context;
@@ -40,12 +39,9 @@
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
-import java.io.IOException;
-import java.net.InetAddress;
+import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.Map;
import java.util.Properties;
@@ -444,9 +440,20 @@
{
log.info("JNDI Server configuration information not present so will
create a local server.");
- SecurityUtility.setSystemProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
- NamingBeanImpl namingBean = new NamingBeanImpl();
- namingBean.start();
+ Object namingBean = null;
+ Class namingBeanClass = null;
+ try
+ {
+ namingBeanClass =
Class.forName("org.jnp.server.NamingBeanImpl");
+ namingBean = namingBeanClass.newInstance();
+ Method startMethod = namingBeanClass.getMethod("start", new
Class[] {});
+ SecurityUtility.setSystemProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
+ startMethod.invoke(namingBean, new Object[] {});
+ }
+ catch (Exception e)
+ {
+ log.debug("Cannot find NamingBeanImpl: must be running jdk
1.4");
+ }
host = SecurityUtility.getLocalHostName();
port = PortUtil.findFreePort(host);
@@ -456,7 +463,11 @@
//If no server information provided, then start one of our own by default
Main server = new Main();
- server.setNamingInfo(namingBean);
+ if (namingBean != null)
+ {
+ Method setNamingInfoMethod =
server.getClass().getMethod("setNamingInfo", new Class[] {namingBeanClass});
+ setNamingInfoMethod.invoke(server, new Object[] {namingBean});
+ }
server.setPort(port);
server.setBindAddress(host);
server.start();
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java 2008-09-08
06:16:03 UTC (rev 4550)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/detection/jndi/SimpleJNDIServer.java 2008-09-08
06:18:18 UTC (rev 4551)
@@ -2,8 +2,8 @@
import org.jboss.remoting.util.SecurityUtility;
import org.jnp.server.Main;
-import org.jnp.server.NamingBeanImpl;
+import java.lang.reflect.Method;
import java.net.InetAddress;
/**
@@ -88,15 +88,30 @@
private void setupJNDIServer() throws Exception
{
- SecurityUtility.setSystemProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
- NamingBeanImpl namingBean = new NamingBeanImpl();
- namingBean.start();
+ Object namingBean = null;
+ Class namingBeanClass = null;
+ try
+ {
+ namingBeanClass = Class.forName("org.jnp.server.NamingBeanImpl");
+ namingBean = namingBeanClass.newInstance();
+ Method startMethod = namingBeanClass.getMethod("start", new Class[]
{});
+ SecurityUtility.setSystemProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
+ startMethod.invoke(namingBean, new Object[] {});
+ }
+ catch (Exception e)
+ {
+ SimpleJNDIServer.println("Cannot find NamingBeanImpl: must be running jdk
1.4");
+ }
// start JNDI server
String detectorHost = InetAddress.getLocalHost().getHostName();
Main JNDIServer = new Main();
- JNDIServer.setNamingInfo(namingBean);
+ if (namingBean != null)
+ {
+ Method setNamingInfoMethod =
JNDIServer.getClass().getMethod("setNamingInfo", new Class[]
{namingBeanClass});
+ setNamingInfoMethod.invoke(JNDIServer, new Object[] {namingBean});
+ }
JNDIServer.setPort(detectorPort);
JNDIServer.setBindAddress(detectorHost);
JNDIServer.start();
Modified:
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/transporter/custom/server/JNDIServer.java
===================================================================
---
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/transporter/custom/server/JNDIServer.java 2008-09-08
06:16:03 UTC (rev 4550)
+++
remoting2/branches/2.x/src/main/org/jboss/remoting/samples/transporter/custom/server/JNDIServer.java 2008-09-08
06:18:18 UTC (rev 4551)
@@ -21,10 +21,11 @@
*/
package org.jboss.remoting.samples.transporter.custom.server;
+import org.jboss.remoting.samples.detection.jndi.SimpleJNDIServer;
import org.jboss.remoting.util.SecurityUtility;
import org.jnp.server.Main;
-import org.jnp.server.NamingBeanImpl;
+import java.lang.reflect.Method;
import java.net.InetAddress;
/**
@@ -38,14 +39,29 @@
{
try
{
- SecurityUtility.setSystemProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
- NamingBeanImpl namingBean = new NamingBeanImpl();
- namingBean.start();
+ Object namingBean = null;
+ Class namingBeanClass = null;
+ try
+ {
+ namingBeanClass = Class.forName("org.jnp.server.NamingBeanImpl");
+ namingBean = namingBeanClass.newInstance();
+ Method startMethod = namingBeanClass.getMethod("start", new Class[]
{});
+ SecurityUtility.setSystemProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
+ startMethod.invoke(namingBean, new Object[] {});
+ }
+ catch (Exception e)
+ {
+ SimpleJNDIServer.println("Cannot find NamingBeanImpl: must be running
jdk 1.4");
+ }
String host = InetAddress.getLocalHost().getHostAddress();
Main jserver = new Main();
- jserver.setNamingInfo(namingBean);
+ if (namingBean != null)
+ {
+ Method setNamingInfoMethod =
jserver.getClass().getMethod("setNamingInfo", new Class[] {namingBeanClass});
+ setNamingInfoMethod.invoke(jserver, new Object[] {namingBean});
+ }
int port = JNDI_PORT;
jserver.setPort(port);
jserver.setBindAddress(host);
Show replies by date