I was originally using rsolr to generate and connect to solr cores on my local machine. This all worked fine in ruby until we moved to jruby. I now receive a 504 gateway error for localhost http requests. This comes from Open-uri. We do have a proxy and I have unset it, set it and used Net::HTTP::Proxy to attempt to connect to localhost.
The error I get is:
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)'
I have also tried aliases for localhost -> 127.0.0.1, 0.0.0.0 and my actual local ip 192..
Any idea why this is. Can Open URI in jruby not handle redirects?
EDIT: it does connect if the real local IP is used i.e 192.... (but not on 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/>>
Thanks for any help in advance
EDIT:
This is essentially a duplicate of:
Make JRuby inherit Java proxy settings
See Make JRuby inherit Java proxy settings
Which essentially states:
I have had the same issue. I found that java or net::http doesn't obey the nonProxyHosts option. The best way to get around this is to modify the ENV_JAVA settings to account for this.
The steps I took to ensure nonProxyHosts was used were the following:
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"
Keep in mind that at least for java1.7 the nonProxyHosts should not have quotations see here.
Now I find that either net::http or java itself doesn't actually honour the nonProxyHosts option.
However you can get around this by doing the following in 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
Or at least this is the only way I could get it to work
Related
I'm getting this error:
CONNECTION ERROR: Couldn't connect to node http://localhost:8545, is it running?
I'm currently trying to use a Meteor app with a node on a private test network. I've also tried running it on a real node on the real network as well. I am able to access the web3.eth objects, but I can't seem to connect to my node! It's so frustrating!
My app runs on http://localhost:3000
I've tried the following in launching my nodes, neither of them work (they launch okay, but I cannot connect to them through my browser):
geth --networkid 8545 --genesis ~/genesis_block.json --datadir ~/.ethereum_experiment console
geth --rpccorsdomain "*" --rpc --networkid 8545 --minerthreads "1" --datadir ~/.ethereum_experiment --mine
This is what I use to set the provider in the browser console:
web3.setProvider(new web3.providers.HttpProvider("http://localhost:8545"));
I think I was getting the same error, when was trying to run geth in a VM. And in that case the issue was with RPC listening to localhost only. Binding it to all addresses with --rpcaddr "0.0.0.0" solved the problem:
geth --rpc --rpcaddr "0.0.0.0" --rpcport 8545 --nodiscover --networkid "$NETWORKID" --datadir ~/.ethereum_experiment --genesis ~/genesis_block.json
Important thing to note here is that with a such configuration the port will be open to connections from the outside world, if it's not on a private network or not protected with a firewall.
You can also check if the RPC port is open by trying to connect to it with telnet:
telnet localhost 8545
A simple solution is to use a node provider like Alchemy or Infura!
https://docs.alchemy.com/alchemy/introduction/getting-started
Make an Alchemy key by signing up for an account and creating an app
Replace your web3 setup with something like this:
const { createAlchemyWeb3 } = require("#alch/alchemy-web3"); // Using HTTPS const web3 = createAlchemyWeb3("https://eth-mainnet.alchemyapi.io/<api-key>");
You can use free nodes from one of these node providers and avoid the hassle of maintaining your nodes yourself.
I recently uploaded a Symfony2 project to GoDaddy and I'm having trouble accesing it because I get the message:
An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user 'root'#'127.0.0.1' (using password: NO)
Obviously the message is clear, so I checked and rechecked my parameters.yml, and the message don't even match what I have there, which I have changed several times to try to fix. This is my parameters.yml:
parameters:
database_driver: pdo_mysql
database_host: localhost
database_port: null
database_name: database1
database_user: database1user
database_password: mytestpassword
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: RandomTokenThatWillBeChanged
debug_toolbar: true
debug_redirects: false
use_assetic_controller: true
So, the error message doesn't tell me what is my real problem, or it is loading the parameters from some cached version that I haven't found yet. Any ideas of what else could cause or where could a cached version of this data be?
One of the best practice when developing a Symfony application is to
make it configurable via a parameters.yml file. It contains
information such as the database name, the mailer hostname, and custom
configuration parameters.
As those parameters can be different on your local machine, your
testing environment, your production servers, and even between
developers working on the same project, it is not recommended to store
it in the project repository. Instead, the repository should contain a
paramaters.yml.dist file with sensible defaults that can be used as a
good starting point for everyone.
Then, whenever a developer starts working on the project, the
parameters`.yml file must be created by using the parameters.yml.dist
as a template. That works quite well, but whenever a new value is
added to the template, you must remember to update the main parameter
file accordingly.
As of Symfony 2.3, the Standard Edition comes with a new bundle that
automates the tedious work. Whenever you run composer install, a
script creates the parameters.yml file if it does not exist and allows
you to customize all the values interactively. Moreover, if you use
the --no-interaction flag, it will silently fallback to the default
values.
http://symfony.com/blog/new-in-symfony-2-3-interactive-management-of-the-parameters-yml-file
So, is it not possible that your paramaters.yml is overwritten by paramaters.yml.dist?
You can also try to completely clear the cache
In Dev:
php app/console cache:clear
In Production:
php app/console cache:clear --env=prod --no-debug
I am trying to create some Vagrant VM's, but whenever I use vagrant box add, it says my box doesn't have the metadata.json file. This is also sometimes caused when the metadata.json file exists but does not have the provider line required by Vagrant. However, all the boxes I have tried have had this file with the required text, in correct JSON format. Usually I have the file say:
{
"provider": "virtualbox"
}
I don't believe white space matters, you could probably have hundreds of blank lines & tabs & spaces. The fact that it doesn't throw a different error (usually Could not resolve host) means it is finding the VM's.
The funny thing is, my system has the precise32 sample VM, and Vagrant didn't complain when I vagrant uped that. I even copied the metadata.json file from there to one of my VM's and tarred it again, but it still didn't work.
I'm not sure if it's related, but when I tried adding the --provider flag (as in vagrant add box /box/path --provider), it threw the error,
c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.3.5/lib/vagrant/plugin/v2/comm
and.rb:51:in `parse_options': missing argument: --provider (OptionParser::Missin
gArgument)
from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.3.5/plugins/comma
nds/box/command/add.rb:29:in `execute'
from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.3.5/plugins/comma
nds/box/command/root.rb:47:in `execute'
from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.3.5/lib/vagrant/c
li.rb:38:in `execute'
from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.3.5/lib/vagrant/e
nvironment.rb:478:in `cli'
from c:/HashiCorp/Vagrant/embedded/gems/gems/vagrant-1.3.5/bin/vagrant:9
6:in `<top (required)>'
from c:/HashiCorp/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `load'
from c:/HashiCorp/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `<main>
'
Not sure, if you are still looking for an answer. Just in case, if some one else is looking for
metadata.json should be at the root of the structure when you are
creating the tar
Try this tar -czf server-image.box ./*
instead of tar -czf server-image.box server-image-folder
I am developing a simple iOS app, which uses a Rails app as a server backend. I'm using the Restkit framework for the management of the server networking / requests and on the iOS side all seems to be OK.
When I make a PUT request, I get a 200 response back, and the logs in XCode seem to suggest all is well. When I look at the logs for the Rails app, it also seems to suggest all is well, with the following output:
2011-12-19T18:15:17+00:00 app[web.1]: Started PUT "/lists/3/tasks/6" for 109.156.183.65 at 2011-12-19 18:15:17 +0000
2011-12-19T18:15:17+00:00 app[web.1]: Parameters: {"created_at"=>"2011-12-12 22:37:00 +0000", "id"=>"6", "updated_at"=>"2011-12-12 22:37:00 +0000", "description"=>"Create a home page", "list_id"=>"3", "completed"=>"1"}
2011-12-19T18:15:17+00:00 app[web.1]: Task Load (4.3ms) SELECT "tasks".* FROM "tasks" WHERE "tasks"."id" = $1 LIMIT 1 [["id", "6"]]
2011-12-19T18:15:17+00:00 app[web.1]: Processing by TasksController#update as JSON
2011-12-19T18:15:17+00:00 app[web.1]: (4.7ms) BEGIN
2011-12-19T18:15:17+00:00 app[web.1]: (1.5ms) COMMIT
2011-12-19T18:15:17+00:00 app[web.1]: Completed 200 OK in 48ms (Views: 1.1ms | ActiveRecord: 16.0ms)
2011-12-19T18:15:17+00:00 heroku[nginx]: 109.156.183.65 - - [19/Dec/2011:10:15:17 -0800] "PUT /lists/3/tasks/6 HTTP/1.1" 200 154 "-" "TaskM8/1.0 CFNetwork/485.13.9 Darwin/11.2.0" taskm8.com
2011-12-19T18:15:17+00:00 heroku[router]: PUT taskm8.com/lists/3/tasks/6 dyno=web.1 queue=0 wait=0ms service=114ms status=200 bytes=154
However, when I make another get request, or use the standard web views to look at the data, the change I was expecting from the PUT request (Completed = 1 - which is a BOOL field), no change has been made.
I can see from the rails log that my iOS app is passing the correct parameters, so it seems to be something on the rails side. I've been through the loop of overcoming the CSRF error message, so don't think it's that.
On a local version of the rails app, I've also run general logging against the MySql database to monitor the queries being run, trying to see if the PUT does anything at all, or anything which would fail... in the log, you don't see anything other than:
BEGIN
COMMIT
The same as the rails log.
So, does anyone have any idea about why the PUT is not making the changes to the data, or how I can debug the PUT further?
Apologies if this is a real simple question, I'm slowly getting back into development and am somewhat rusty!
Are you using any kind of automated tests? If not, start there.
Another way (though rubbish) would be to call your controller action from a webpage and see if it works.
You can also add logger.debug in your rails code to add traces.
If you have control over the MySQL server I would suggest that you enable the general log aka the query log, that way you can see what really happens.
SET GLOBAL general_log_file = '/tmp/query.log'
SET GLOBAL general_log = 'ON';
[n00b alert] I'm probably doing this all wrong... RSpec outputs this failure:
1)... #skipped irrelevant info
Failure/Error: graph.read_db('example1')
Not connected to any DB. #error msg
#./prim.rb:135:in 'read_db'
#./prim_spec.rb:171:in 'block (2 levels) in <top (required)>'
I have set up a MySQL database on the same machine. The program provides an algorithm for computing a graph's minimum spanning tree. Has methods for file I/O, database I/O using ActiveRecord, etc. All WORKS WELL except RSpec tests.
Code (irrelevant parts left out):
prim_spec.rb
describe PGraph, "online" do
before (:all) do
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:host => "localhost",
:username => "root",
:password => "xxxxx",
:database => "rubytasks" )
#the exact same statement works perfectly when running the program itself, but fails in RSpec
end
before (:each) do
#graph = PGraph.new
end
it "should correctly retrieve data from database" do
#graph.read_db('example1') #line 171
#business part goes here
end
end
prim.rb
class PGraph
def read_db(graphID)
#the error which is raised (line 135):
raise "Not connected to any DB." unless ActiveRecord::Base.connected?
#reading goes here
end
end
Connection and PGraph manipulation is performed in ui.rb.
So, ummm, what's the correct way to access a real DB (I'm lazy) for testing (or is the problem elsewhere?)? Preferably something simple, since this is just a school assignment. And without messing with Rails or other gems.
PS: I'm using the most recent versions of all gems and server. On Windows 7 x86. Ruby 1.9.2. Thanks.
I'm guessing not everything is loaded properly when you run your rspec tests. Are all classes that setup your database connection loaded properly and with the right parameters when running rspec?