Results 1 to 8 of 8

Thread: Why do I need to define java.rmi.server.hostname?

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Location
    London, England
    Posts
    19

    Default Why do I need to define java.rmi.server.hostname?

    Would anyone care to explain to me why I have to put the following in catalina.sh

    JAVA_OPTS=-Djava.rmi.server.hostname=192.168.1.1

    to get my RmiServiceExporter beans to bind to the correct NIC on my server?

  2. #2

    Default

    By default, the host is localhost (127.0.0.1). I'm using RmiServiceExporter without problems, just declaring the bean.

  3. #3
    Join Date
    Nov 2008
    Location
    London, England
    Posts
    19

    Default what property did you set?

    I tried setting <property name="registryHost" value="192.168.1.12"/> but that doesn't work. Which property are you setting in your config?

  4. #4

    Default

    I just do the following:

    Server:

    Code:
      <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
        <property name="serviceName" value="EmprestimoFachada"/>
        <property name="service" ref="emprestimoFachada"/>
        <property name="serviceInterface" value="br.com.biblioshop.emprestimo.fachada.EmprestimoFachada"/>
      </bean>
    Client:

    Code:
      
      <bean id="emprestimoFachada" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl" value="rmi://localhost:1099/EmprestimoFachada"/>
        <property name="serviceInterface" value="br.com.biblioshop.emprestimo.fachada.EmprestimoFachada"/>
      </bean>

  5. #5
    Join Date
    Nov 2008
    Location
    London, England
    Posts
    19

    Default Is your client on the same host as your server?

    By the look of your client's url rmi://localhost, your client on the same host as your server. My client is on a different machine. That's what appears to cause the problem. Spring's "auto-registry" appears to bind to localhost by default (which is kind of daft for a "remoting" system).
    If I specify the registryHost property explicitly, Spring appears to assume you want to use an existing application server's registry (which I don't have in my case as I'm in Tomcat). Setting "alwaysCreateRegistry" to "true" doesn't appear to do what you would expect either. Hmm.

  6. #6
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    It has nothing to do with Spring, it's how RMI works.

    When you execute an RMI lookup server generates a stub and _hardcodes_ it's own address in it. Stub is then transfered to the client and address generated by the server used for method remoting. The address hardcoded in the stub has nothing to do with an address you used for a lookup. The algorithm used by the server to find it's own address is not very smart and fails to produce a meaningful result in all but trivial network configurations (very often it produces "localhost" so your rmi clients end up sending requests to themselves). That's why, most of the times, it's needed to override the algorithm by setting java.rmi.server.hostname.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •