2013-05-02 21 views
0

我已經成功地爲cloudbees部署了一個spring rmi web應用程序(WAR文件)。此應用程序包含簡單的RMI服務,名爲「greetingRmiService」,它返回一個包含問候消息的String。這是服務器日誌部分,它說它成功地部署了我的rmi服務。外部訪問雲中的Spring Java RMI服務

INFO: Pre-instantiating singletons in org.s[email protected]79d9cd24: defining beans [registry,greetingService,org.springframework.remoting.rmi.RmiServiceExporter#0]; root of factory hierarchy 
May 02, 2013 4:06:20 AM org.springframework.remoting.rmi.RmiRegistryFactoryBean getRegistry 
INFO: Looking for RMI registry at port '1099' 
May 02, 2013 4:06:35 AM org.springframework.remoting.rmi.RmiRegistryFactoryBean getRegistry 
INFO: Could not detect RMI registry - creating new one 
May 02, 2013 4:06:35 AM org.springframework.remoting.rmi.RmiServiceExporter prepare 
INFO: Binding service 'greetingRmiService' to RMI registry: RegistryImpl[UnicastServerRef [liveRef: [endpoint:[10.119.1.56:1099](local),objID:[0:0:0, 0]]]] 

現在我想創建一個客戶端應用程序在我的本地電腦連接這個服務,並調用該服務。我的客戶是一個簡單的Maven應用程序。這裏是客戶端的spring配置bean。

<bean id="greetingService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> 
<property name="serviceUrl" value="rmi://10.119.1.56:1099/greetingRmiService"/> 
<property name="serviceInterface" value="com.main.GreetingService"/> 
</bean> 

客戶主要方法:

public static void main(String[] args) 
{ 

ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:com/config/SpringConfigurationBean.xml"); 
GreetingService service = (GreetingService) ctx.getBean("greetingService"); 
System.out.println(service.sayHello("Lahiru")); 
} 

但是這是行不通的,它給出了一個連接超時異常。我已經使用端點10.119.1.56:1099與服務器連接。當我從外部連接到雲服務器時,是否應該使用正確的rmi端點?

謝謝!

回答

1

爲了使RMI正常工作,您將不得不通過代理/路由層隧道傳輸http(s)。

你可以閱讀更多關於隧道技術:

http://www.java-forums.org/blogs/rmi/730-what-http-tunneling-how-make-rmi-calls-across-firewalls.html

對於Spring應用程序: http://static.springsource.org/spring-integration/docs/2.0.0.RELEASE/reference/html/httpinvoker.html

+0

你知道該怎麼做,在CloudBees的? – 2013-05-06 11:16:12

+0

添加了一個鏈接http://www.java-forums.org/blogs/rmi/730-what-http-tunneling-how-make-rmi-calls-across-firewalls.html - 應該與其他地方一樣工作在這方面。 – 2013-05-06 23:12:33

+0

謝謝邁克爾。發現春天的實施來做到這一點。 http://static.springsource.org/spring-integration/docs/2.0.0.RELEASE/reference/html/httpinvoker.html – 2013-06-09 08:24:12