无法在openshift上打开传出连接(套接字)

时间:2013-06-04 06:40:05

标签: java tcp spring-integration openshift

我正在编写一个小应用程序来检查openshift上几个弹簧功能的功能和配置。你可以在这里找到代码:https://github.com/Laures/openshift-spring-testapp

目前我尝试测试spring-integration tcp / ip支持,因为openshift对绑定到端口的能力有一些严格的限制。服务器套接字部分很简单:选择一个允许的端口并使用内部服务器ip(不是localhost)。

我在客户端部分失败了。我想使用我的公共DNS入口打开一个TCP连接,以连接到我的服务器。据我所知(下面的堆栈跟踪)我的应用程序无法打开本地套接字以进行与我的服务器的传出连接。

17:41:36.309 [pool-3-thread-1] DEBUG o.s.i.i.t.c.TcpNetClientConnectionFactory - Opening new socket connection to springtest-laures.rhcloud.com:4444
17:41:36.317 [pool-3-thread-1] ERROR o.s.i.ip.tcp.TcpOutboundGateway - Tcp Gateway exception
java.net.SocketException: Permission denied
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.7.0_19]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339) ~[na:1.7.0_19]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200) ~[na:1.7.0_19]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182) ~[na:1.7.0_19]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391) ~[na:1.7.0_19]
    at java.net.Socket.connect(Socket.java:579) ~[na:1.7.0_19]
    at java.net.Socket.connect(Socket.java:528) ~[na:1.7.0_19]
    at java.net.Socket.<init>(Socket.java:425) ~[na:1.7.0_19]
    at java.net.Socket.<init>(Socket.java:208) ~[na:1.7.0_19]
    at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:271) ~[na:1.7.0_19]
    at org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory.createSocket(TcpNetClientConnectionFactory.java:89) ~[spring-integration-ip-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory.obtainConnection(TcpNetClientConnectionFactory.java:63) ~[spring-integration-ip-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory.getConnection(AbstractClientConnectionFactory.java:49) ~[spring-integration-ip-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.ip.tcp.TcpOutboundGateway.handleRequestMessage(TcpOutboundGateway.java:116) ~[spring-integration-ip-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:134) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:73) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:115) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:102) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:157) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:128) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.core.MessagingTemplate.doSend(MessagingTemplate.java:288) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.core.MessagingTemplate.doSendAndReceive(MessagingTemplate.java:318) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:239) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.core.MessagingTemplate.convertSendAndReceive(MessagingTemplate.java:274) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:224) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:203) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:306) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:269) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:260) [spring-integration-core-2.2.3.RELEASE.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) [spring-aop-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    at com.sun.proxy.$Proxy22.sendMessage(Unknown Source) [na:na]
    at com.openshift.test.socket.SocketClient.sendMessage(SocketClient.java:24) [SocketClient.class:na]
    at sun.reflect.GeneratedMethodAccessor21.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_19]
    at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_19]
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:64) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53) [spring-context-3.2.2.RELEASE.jar:3.2.2.RELEASE]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [na:1.7.0_19]
    at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) [na:1.7.0_19]
    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) [na:1.7.0_19]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) [na:1.7.0_19]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.7.0_19]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_19]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_19]
    at java.lang.Thread.run(Thread.java:722) [na:1.7.0_19]

编辑1

看起来openshift只允许传出连接使用内部ip。 我查看了spring-integration代码,没有办法为客户端连接设置本地接口。即使有一个javax.net.SocketFactory没有方法只使用目标主机/端口和本地主机获取套接字。

所以现在问题归结为:

如何使用特定的本地IP作为源打开远程地址的客户端套接字

1 个答案:

答案 0 :(得分:2)

SocketFactory has a couple of createSocket methods提供指定本地接口的机制。 Spring Integration不直接使用这些方法。但是,您可以提供自定义TcpSocketFactorySupport(基于DefaultTcpNetSocketFactorySupport),它包装默认套接字工厂并将对createSocket(host, port)的调用委托给其他方法之一。

也可以随意打开Improvement JIRA Issue