我正在编写一个小应用程序来检查 openshift 上几个 spring 特性的功能和配置。你可以在这里找到代码:https://github.com/Laures/openshift-spring-testapp
目前我尝试测试 spring-integrations tcp/ip 支持,因为 openshift 对绑定(bind)到端口的能力有一些严格的限制。服务器套接字部分很简单:选择一个允许的端口并使用内部服务器 ip(不是本地主机)。
我在客户端部分失败了。我想使用我的公共(public) 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 代码,没有办法为客户端连接设置本地接口(interface)。即使有一个,javax.net.SocketFactory 也没有方法来获取目标主机/端口和本地主机的套接字。
所以现在的问题是:
如何使用特定的本地 ip 作为源打开到远程地址的客户端套接字
最佳答案
SocketFactory has a couple of createSocket methods提供了一种机制来指定本地接口(interface)。 Spring Integration 不直接使用这些方法。但是,您可以提供一个自定义的 TcpSocketFactorySupport(基于 DefaultTcpNetSocketFactorySupport)来包装默认套接字工厂并将调用委托(delegate)给 createSocket(host, port) 到其他方法之一。
也可以随意打开一个Improvement JIRA Issue .
关于java - 无法在 openshift 上打开传出连接(套接字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16911325/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我正在使用Sequel构建一个愿望list系统。我有一个wishlists和itemstable和一个items_wishlists连接表(该名称是续集选择的名称)。items_wishlists表还有一个用于facebookid的额外列(因此我可以存储opengraph操作),这是一个NOTNULL列。我还有Wishlist和Item具有续集many_to_many关联的模型已建立。Wishlist类也有:selectmany_to_many关联的选项设置为select:[:items.*,:items_wishlists__facebook_action_id].有没有一种方法可以
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)