0

我最初使用 rsolr 生成并连接到本地计算机上的 solr 核心。在我们迁移到 jruby 之前,这一切都在 ruby​​ 中运行良好。我现在收到 localhost http 请求的 504 网关错误。这来自Open-uri. 我们确实有一个代理,我已经取消设置它,设置它并用于Net::HTTP::Proxy尝试连接到本地主机。

我得到的错误是:

require 'open-uri'
open("http://127.0.0.1:8984/solr/")

OpenURI::HTTPError: 504 Gateway Time-out
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:346:in `open_http'
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:775:in `buffer_open'
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:203:in `open_loop'
  from org/jruby/RubyKernel.java:1254:in `catch'
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:201:in `open_loop'
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:146:in `open_uri'
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:677:in `open'
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:33:in `open'
  from (irb):3:in `evaluate'
  from org/jruby/RubyKernel.java:1093:in `eval'
  from org/jruby/RubyKernel.java:1489:in `loop'
  from org/jruby/RubyKernel.java:1254:in `catch'
  from org/jruby/RubyKernel.java:1254:in `catch'
  from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)'

我还尝试了 localhost -> 127.0.0.1、0.0.0.0 和我的实际本地 ip 192 的别名。

知道为什么会这样。jruby中的Open URI可以不处理重定向吗?

编辑:如果使用真实的本地 IP,即 192....(但不在 localhost,127.0.0.1 上),它会连接:

jruby-1.7.4 :013 > open("http://127.0.0.1:8985/solr/")
  OpenURI::HTTPError: 504 Gateway Time-out
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:346:in `open_http'
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:775:in `buffer_open'
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:203:in `open_loop'
    from org/jruby/RubyKernel.java:1254:in `catch'
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:201:in `open_loop'
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:146:in `open_uri'
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:677:in `open'
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/lib/ruby/1.9/open-uri.rb:33:in `open'
    from (irb):13:in `evaluate'
    from org/jruby/RubyKernel.java:1093:in `eval'
    from org/jruby/RubyKernel.java:1489:in `loop'
    from org/jruby/RubyKernel.java:1254:in `catch'
    from org/jruby/RubyKernel.java:1254:in `catch'
    from /Users/adamcryer/.rvm/rubies/jruby-1.7.4/bin/irb:13:in `(root)'
jruby-1.7.4 :014 > open("http://192.168.2.210:8985/solr/")
 => #<StringIO:0x385715 @status=["200", "OK"], @meta={"content-    type"=>"text/html;charset=UTF-8", "x-cache"=>"MISS from pH-squid", "x-cache-lookup"=>"MISS from pH-squid:3128", "via"=>"1.1 pH-squid:3128 (squid/2.7.STABLE9)", "connection"=>"close"}, @base_uri=#<URI::HTTP:0x2a717ef5 URL:http://192.x.x.x:8985/solr/>>

感谢您提前提供任何帮助

编辑:

这本质上是以下内容的副本:

让 JRuby 继承 Java 代理设置

4

1 回答 1

0

请参阅使 JRuby 继承 Java 代理设置

这基本上说明:

我有同样的问题。我发现 java 或 net::http 不遵守 nonProxyHosts 选项。解决此问题的最佳方法是修改 ENV_JAVA 设置以解决此问题。

我为确保使用 nonProxyHosts 而采取的步骤如下:

1) JAVA_OPTS="-Dhttp.proxyHost=192*** -Dhttp.proxyPort=1234 -Dhttp.nonProxyHosts=local|127.0.0.1"
OR
1) JRUBY_OPTS="-J-Dhttp.proxyHost=192*** -J-Dhttp.proxyPort=1234 -J-Dhttp.nonProxyHosts=local|127.0.0.1"

请记住,至少对于 java1.7,nonProxyHosts 不应有引用,请参见此处。

现在我发现 net::http 或 java 本身实际上并不支持 nonProxyHosts 选项。

但是,您可以通过在 JRuby 中执行以下操作来解决此问题

a = URI("http://someurl")
Net::HTTP.new(a).proxy?.should == true
regex = /$#{ENV_JAVA["http.nonProxyHosts"]}/ #dollar needed to behave as expected
if a.hostname.match(regex)
  ENV_JAVA["http.proxyHost"]=nil
end
Net::HTTP.new(a).proxy?.should == false

或者至少这是我让它工作的唯一方法

于 2014-01-10T11:21:47.070 回答