0

I'm calling a java service via its http endpoint (embedded jetty). The service handles async http requests with a timeout of 5s, and reliably works when I call it from the browser with url params, or curl or py script.

When I call it from a ruby script with net/http or rest-client, it times out half the time?! Any idea what could be causing this and what a possible solution might be (with ruby)?

I'm using ruby 1.9.3-p125 and the ruby and python scripts are all <10 lines (I'd normally be making the call from a larger piece of code, but the small version doesn't work either).

net/http

paramStr = "rid=#{rid}&id=#{id}&json=#{json}"
uri = URI.parse(URI.escape(proxy_server_addr+"?"+paramStr))
response = Net::HTTP.get_response(uri)

rest-client

resource = RestClient::Resource.new('http://myserver.com:9001', :timeout => 10)
response = resource["/"].get :params => {:id => id, :rid => rid, :json => json}

curl

curl 'http://myserver:9001/?id=...'

py

import urllib2
print urllib2.urlopen("http://myserver.com:9001?id=...").read()

enter image description here

nflacco
  • 4,972
  • 8
  • 45
  • 78

1 Answers1

0

You're overcomplicating it. The ruby equivalent of urllib2 is open-uri:

require 'open-uri'
puts open("http://myserver.com:9001?id=...").read
pguardiario
  • 53,827
  • 19
  • 119
  • 159
  • That works perfectly. Any idea why the other libraries would time out? – nflacco May 21 '12 at 07:07
  • Yes, from what I can tell, you were using them completely wrong :) – pguardiario May 21 '12 at 07:10
  • ah! I managed to get rest client to work too... but neither open-uri or rest-client work consistently remotely. It's bizarre. Here's my follow up question http://stackoverflow.com/questions/10693959/http-calls-behave-differnent-locally-vs-aws-is-it-ruby-or-aws – nflacco May 21 '12 at 23:36