Hi, 

thanks - it seems to mean something in China, probably in India too...
Once I tried to buy deyan.com to use it for my personal e-mail but it
was already taken.So a Chinese guy contacted me trying to offer me
"Deyan for my business" . 
The world is small :)

So on the issue: finally I managed to start OFBiz using a single
interface ( in my case 192.168.1.200 - a virtual network interface
wlan0:0 ). 

$ netstat -anp | grep java
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp6       0      0 :::9989                 :::*
LISTEN      3901/java       
tcp6       0      0 :::9990                 :::*
LISTEN      3901/java       
tcp6       0      0 192.168.1.200:8009      :::*
LISTEN      3901/java       
tcp6       0      0 192.168.1.200:1099      :::*
LISTEN      3901/java       
tcp6       0      0 192.168.1.200:8080      :::*
LISTEN      3901/java       
tcp6       0      0 :::56434                :::*
LISTEN      3901/java       
tcp6       0      0 192.168.1.200:8443      :::*
LISTEN      3901/java       
tcp6       0      0 127.0.0.1:10523         :::*
LISTEN      3901/java       
tcp6       0      0 127.0.0.1:39653         127.0.0.1:5432
ESTABLISHED 3901/java       
tcp6       0      0 127.0.0.1:39717         127.0.0.1:5432
ESTABLISHED 3901/java

I have got only the following ports bound on all interfaces: 
- 9989, 9990 - the beanshell telnet service - which could be turned off
for production usage. 
- 10523 - the admin port, which IMHO is better to remain on 127.0.0.1
for security reasons. It's not a big deal to change it in startofbiz.sh
and stopofbiz.sh and document it somewhere :)
- 56434 - which I still know nothing about. 

The most important thing is that I managed to run the RMI registry on
the specified interface: 192.168.1.200:1099  . 
I had to create a new java.rmi.server.RMISocketFactory implementantion
and patch a little bit  org.ofbiz.base.container.NamingServiceContainer.
I am attaching the patch file. Please review it, I'm ready to discuss
it. 

The idea behind all this is that if one ( in this case - me :) has to
host many ( more than one )  OFBiz instances on 1 server it would be a
real pain 
to configure different ports for each OFBiz instance. This way OFBiz
could become like netweaver -  the first digit of the port number is the
instance number :) 
( 28080 - instance 2, port 8080 )

So I am offering a simple solution to the problem. The next step could
probably be to create a global config entry for the interface to which
we want ofbiz to bind all its server sockets. 
This would minimize the chance to forget modifying some of the config
files. 

An example of a config file that could be easily forgotten to modify
is :

$OFBIZ_HOME/framework/service/config/serviceengine.xml

which in my case I modified to : 

    <service-location name
$OFBIZ_HOME/framework/service/config/serviceengine.xml="main-rmi"
location="rmi://192.168.1.200:1099/RMIDispatcher"/>
        <service-location name="main-http"
location="http://192.168.1.200:8080/webtools/control/httpService"/>

        <service-location name="entity-sync-rmi"
location="rmi://192.168.1.200:1099/RMIDispatcher"/>
        <service-location name="entity-sync-http"
location="http://192.168.1.200:8080/webtools/control/httpService"/>

        <service-location name="rita-rmi"
location="rmi://192.168.1.200:1099/RMIDispatcher"/>
        <service-location name="eedcc-test"
location="http://192.168.1.200:8080/webtools/control/httpService"/>


That's all for now from me, 
waiting for comments. 

Best regards, 
Deyan 


On Mon, 2009-05-25 at 18:43 +0530, Ashish Vijaywargiya wrote:

> Sure, Let us know what you found, when you are done.
> BTW your name is very nice.... "Deyan"
> 
> --
> Ashish
> 
> Deyan Tsvetanov wrote:
> > Hi Ashish,  
> >
> > thanks for your reply . 
> >
> > As I can see you have chosen the approach to change the port numbers. 
> >
> > I am currently trying the 2nd one - to bind all the ports to a single
> > virtual interface by removing all the localhost, 127.0.0.1 and 0.0.0.0
> > occurances. Currently I am stuck on the RMI registry , as 
> >
> > LocateRegistry.createRegistry(namingPort);
> >
> > ( 
> > org.ofbiz.base.container.NamingServiceContainer.start(NamingServiceContainer.java:62)
> >  ) 
> >
> >  accepts only port number and always binds to localhost. 
> >
> > I'm working on that. If I manage to run 2 of these guys ( ofbiz ) on
> > separate network interfaces without any collisions or cross rmi calls
> > I'll  post a notice.  
> >
> > If I don't succeed than I'll just go on by changing the port numbers
> > only as you have described.
> >
> > So- stay tuned :)
> >
> > Thanks again for your reply. 
> >
> > Cheers, 
> > Deyan 
> >
> >   
> >
Index: framework/base/src/org/ofbiz/base/util/RMIExtendedSocketFactory.java
===================================================================
--- framework/base/src/org/ofbiz/base/util/RMIExtendedSocketFactory.java	(revision 0)
+++ framework/base/src/org/ofbiz/base/util/RMIExtendedSocketFactory.java	(revision 0)
@@ -0,0 +1,73 @@
+package org.ofbiz.base.util;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.rmi.server.RMISocketFactory;
+
+/**
+ * A <code>RMISocketFactory</code> implementation that creates <code>ServerSocket</code>s on a specified interface.  
+ */
+public class RMIExtendedSocketFactory extends RMISocketFactory {
+	
+	private InetAddress hostInetAddress;
+	
+	/**
+	 * Default constructor. Bind the server sockets on all interfaces.
+	 */
+	public RMIExtendedSocketFactory() {
+		// leave hostInetAddress null
+	}
+	
+	public RMIExtendedSocketFactory( InetAddress inetAddress ) {
+		this.hostInetAddress = inetAddress;
+	}
+
+	/**
+	 * 
+	 * @param host The IP address of the interface to bind the server sockets to.
+	 * @throws UnknownHostException If an invalid IP address is provided. 
+	 */
+	public RMIExtendedSocketFactory( String hostIpAddress ) throws UnknownHostException {
+		
+		// check if host is at least "0.0.0.0"
+		if ( hostIpAddress != null && hostIpAddress.length() >= 7 ) {
+			String[] octets = hostIpAddress.split( "\\." );
+			
+			if ( octets == null || octets.length != 4 ) {
+				throw new UnknownHostException( "Invalid IP address: " + hostIpAddress );
+			}
+			
+			byte[] ipAddr = new byte[4];
+			for ( int i = 0; i < octets.length; i++ ) {
+				try {
+					ipAddr[i] = ( byte ) Integer.parseInt( octets[i] );
+				} catch ( NumberFormatException nfEx ) {
+					throw new UnknownHostException( "Invalid IP address: " + hostIpAddress );
+				}
+			}
+			
+			hostInetAddress = InetAddress.getByAddress( ipAddr );
+			
+		}
+		
+		
+	}
+	@Override
+	public ServerSocket createServerSocket(int port) throws IOException {
+		if ( hostInetAddress !=  null ) {
+			return new ServerSocket( port, 0, hostInetAddress );
+		} else {
+			return new ServerSocket( port );
+		}
+	}
+
+	@Override
+	public Socket createSocket(String host, int port) throws IOException {
+		
+		return new Socket( host, port );
+	}
+
+}
Index: framework/base/config/ofbiz-containers.xml
===================================================================
--- framework/base/config/ofbiz-containers.xml	(revision 778426)
+++ framework/base/config/ofbiz-containers.xml	(working copy)
@@ -37,6 +37,7 @@
 
     <!-- load the naming (JNDI) server -->
     <container name="naming-container" class="org.ofbiz.base.container.NamingServiceContainer">
+        <property name="host" value="0.0.0.0"/>
         <property name="port" value="1099"/>
     </container>
 
Index: framework/base/src/org/ofbiz/base/container/NamingServiceContainer.java
===================================================================
--- framework/base/src/org/ofbiz/base/container/NamingServiceContainer.java	(revision 776224)
+++ framework/base/src/org/ofbiz/base/container/NamingServiceContainer.java	(working copy)
@@ -18,12 +18,15 @@
  *******************************************************************************/
 package org.ofbiz.base.container;
 
+import java.net.UnknownHostException;
 import java.rmi.registry.Registry;
 import java.rmi.registry.LocateRegistry;
 import java.rmi.RemoteException;
 import java.rmi.NoSuchObjectException;
 import java.rmi.server.UnicastRemoteObject;
 
+import org.ofbiz.base.util.RMIExtendedSocketFactory;
+
 /**
  * NamingServiceContainer
  *
@@ -37,6 +40,9 @@
     protected boolean isRunning = false;
     protected Registry registry = null;
     protected int namingPort = 1099;
+    protected String namingHost = null;
+    
+    protected RMIExtendedSocketFactory rmiSocketFactory;
 
     public void init(String[] args, String configFile) throws ContainerException {
         this.configFileLocation = configFile;
@@ -52,12 +58,25 @@
                 throw new ContainerException("Invalid port defined in container [naming-container] configuration; not a valid int");
             }
         }
+        
+     // get the telnet-host
+        ContainerConfig.Container.Property host = cfg.getProperty("host");
+        if (host != null && host.value != null) {
+            this.namingHost =  host.value ;
+        }
+        
+        try {
+        	rmiSocketFactory = new RMIExtendedSocketFactory( namingHost );
+        } catch ( UnknownHostException uhEx ) {
+        	throw new ContainerException("Invalid host defined in container [naming-container] configuration; not a valid IP address", uhEx);
+        }
 
     }
 
     public boolean start() throws ContainerException {
         try {
-            registry = LocateRegistry.createRegistry(namingPort);
+            registry = LocateRegistry.createRegistry(namingPort, rmiSocketFactory, rmiSocketFactory);
+        	
         } catch (RemoteException e) {
             throw new ContainerException("Unable to locate naming service", e);
         }

Reply via email to