Results 1 to 7 of 7

Thread: RMI Inbound Adapter exception

  1. #1
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default RMI Inbound Adapter exception

    Hi all
    i am trying to expose some of my spring integ functionality via RMI

    i have checked apidocs for RmiInboundGAtway, and what i am trying to do is to define an inbound gateway for receiving messges and an outbound for posting them
    here's my config file

    Code:
    <bean id="rmiOutGateway" class="org.springframework.integration.rmi.RmiOutboundGateway">
            <constructor-arg value="rmi://localhost:12345"/>
            <property name="replyChannel" ref="replies"/>
        </bean>
    
        <bean id="rmiInGateway" class="org.springframework.integration.rmi.RmiInboundGateway">
            <property name="registryHost" value="localhost"/>
            <property name="registryPort" value="12345"/>
            <property name="requestChannel" ref="requests"/>
        </bean>
    I am getting this exception

    Code:
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rmiInGateway' defined in class path resource [rmi-server-context.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanInitializationException: failed to initialize; nested exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: 
            java.net.ConnectException: Connection refused
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
            at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
            at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
            at com.sample.services.SIStartUp.main(SIStartUp.java:18)
    Caused by: org.springframework.beans.factory.BeanInitializationException: failed to initialize; nested exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: 
            java.net.ConnectException: Connection refused
            at org.springframework.integration.context.IntegrationObjectSupport.afterPropertiesSet(IntegrationObjectSupport.java:104)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
            ... 12 more
    Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is: 
            java.net.ConnectException: Connection refused
            at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601)

    My guess is that if i want to use the RMI adapter, i have to configure an RMI server using RmiServiceExporter. Is that correct?
    could anyone point me to a spring integ rmi sample, as i was unable to find it?

    w/kindest regards
    marco

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,022

    Default

    No, Spring Integration will create the exporter.

    The problem is that if you declare a registry host on the gateway (and therefore the exporter) we look for an external registry. You must omit the host if you want the exporter to create a registry.

    Just remove the registryHost property on the inbound gateway and you should be ok.

    By the way, the easiest way to configure Spring Integration is to use the XML namespace support for the various modules (including RMI).

    We don't yet have an RMI sample but you can see examples in the test cases...

    https://github.com/SpringSource/spri...arserTests.xml

    and

    https://github.com/SpringSource/spri...arserTests.xml

    e.g.

    Code:
    <rmi:inbound-gateway id="gatewayWithPort" request-channel="testChannel" registry-port="1234"/>
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default

    HI Gary
    thanks a lot for the reply.
    i managed to start the RMI gateway, however i am failing to connect uisng my spring client

    I am trying to connect using RmiSpringProxyFactoryBean (as i want to c onnect to the RMI gateway from an external swing application)

    the following setup didnt work.. could you suggest me what is the correct SErviceInterface implemented by the Rmi Inbound Gateway created by SI?
    Code:
    <bean id="rmiServer" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
    	<property name="serviceUrl" value="rmi://localhost:1234/org.springframework.integration.rmiGateway.testChannel"/>
    	<property name="serviceInterface" value="org.springframework.integration.gateway.RequestReplyExchanger "/>
        </bean>
    i might have misstyped the service URL, but that is what i got when i use plain RMI with the code below.
    Code:
    Registry registry = LocateRegistry.getRegistry(1234);
    
    for (String name : registry.list()){
       System.err.println(name);
    this just return a Proxy...

    thanks in advance and regards
    marco

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,022

    Default

    As you appear to have discovered, the service interface is RequestReplyExchanger. Since that interface depends on Message you will need some SI jars on the client. If you do that, then why not use a snippet of SI and use the RmiOutboundGateway on the client (downstream of an SI gateway)?

    Why are you hand-rolling your service exporter instead of using the RmiInboundGateway?

    If you don't want to include SI jars in the client, you will probably be better off using your own service interface and then using a gateway to enter the SI flow on the server; something like...

    Code:
    public interface SiGateway {
    
        MyReturnObject sendAndReceive(MyRequestObject in);
    
    }
    
    public interface RmiService {
    
        MyReturnObject someMethod(MyRequestObject in);
    
    }
    
    public class MyRmiSiBridge implements MyRmiService {
    
        @Autowired
        MySiGateway gateway;
    
        public MyReturnObject someMethod(MyRequestObject in) {
    
           return gateway.sendAndReceive(in);
        }
    }
    
    
    
    <bean ... >  <!-- RMI Service Exporter (bridge) ->
    </bean>
    
    <bean ...> <!-- RMI-SI Bridge
    </bean>
    
    <int:gateway service-interface="...SiGateway" default-request-channel="inbound"/>
    Messages in 'inbound' will have a payload of type MyRequestObject.

    HTH
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Sep 2004
    Location
    London
    Posts
    311

    Default

    Hello Gary
    thanks for the useful reply.
    I am trying not to expose SI to the client, that's why i m rolling out my own service exporter. i'll see how many jars i need to include on the clientside, and then either use RmiINboundGateway or use the solution you describe

    w/kindest regards
    marco

  6. #6

    Default

    Hi Gary,
    this is exactly what I am trying to achieve too.
    http://forum.springsource.org/showth...t&goto=newpost

    A combination of spring (or SI) based RMI server - but the client is not really there yet and is plain simple RMI client.
    This post got my attention and will try out this approach myself too.
    Just wanted to confirm though, this will help in this situation where I dont have to include any new jars on client side and client is
    not aware of the spring or SI based implementation of the server. Right ?

    thanks for this post.

  7. #7
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,022

    Default

    If you don't want any Spring on the client, you will have to use pure RMI and all its nastiness (UnicastRemoteObject, RemoteException etc). But, essentially, yes; if you use standard RMI to talk the server and your remote object uses a gateway to invoke the SI flow, the client doesn't need anything more than your Remote interface.

    Spring Remoting makes RMI much easier to use, however.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Posting Permissions

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