gpt4 book ai didi

java - 外部访问cloudbees中的Spring Java RMI服务

转载 作者:行者123 更新时间:2023-12-01 14:37:38 24 4
gpt4 key购买 nike

我已成功将 spring rmi Web 应用程序(WAR 文件)部署到 cloudbees。该应用程序包含名为“greetingRmiService”的简单 RMI 服务,该服务返回包含问候消息的字符串。这是服务器日志部分,表明它成功部署了我的 rmi 服务。

INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@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 与服务器连接。当我从外部连接到 cloudbees 服务器时,它是我应该使用的正确 rmi 端点吗?

谢谢!

最佳答案

为了使 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

关于java - 外部访问cloudbees中的Spring Java RMI服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16330520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com