Greg Hauptmann
2007-Mar-05 04:39 UTC
Routing Error when using "Net::HTTP.start" but doesn''t occur when testing via Browser
Hi all, I''m stuck on a Routing Error I''m getting when calling my application (App2) from a test/stub application (App1), however when I enter the same request to App2 via the browser I do NOT get this routing issue and it works. My problem is in more detail (if anyone can help) that: [1] when I call an action in App2 from App1 I get a ROUTING ERROR, "Recognition failed for /mycontroller/myaction" - this seems to come from App2''s inbuilt Rails framework which somehow sees a routing problem and immediately sends back a "Routing Error" message without ever getting to my code within App2. [2] when I use the browser with same " http://localhost:3000/mycontroller/myaction" URL (i.e. that App1 seems to be correctly producing, although I don''t have a HTTP trace mechanism to 100% prove this) App2 seems to work fine [3] again I don''t see any log info turn up in App2 (as if the rails framework picked up on the routing error first and then bounced it prior to my code getting involved) [4] some details of my code below Code Used (which resides in App1 running on port 3001 - it''s calling App2 running on port 3000) url = " http://localhost:3000/mycontroller/myaction" uri = URI.parse(url) response = nil Net::HTTP.start(uri.host, uri.port) do |request| response = request.post(uri.path, postData) end Note that "response.body" here gives: <html> <head> <title>Action Controller: Exception caught</title> << CUT >> </head> <body> <h1>Routing Error</h1> <p><pre>Recognition failed for "/mycontroller/myaction"</pre></p> </body> </html> Browser Test * Yet when I call the same URL from my browser it works (and doesn''t give this message). The URL I use here would be: http://localhost:3000/mycontroller/myaction Any ideas/help? I can''t seem to see what I''m doing wrong. Any way to trace the HTTP coming directly into App2 to see for myself what Rails is doing? What about a way to turn up the logging/trace for rails re HTTP? Thanks in advance Greg (TextEdit / MacBook) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Mead
2007-Mar-05 06:07 UTC
Re: Routing Error when using "Net::HTTP.start" but doesn''t occur when testing via Browser
You could print/log debug information from the Dispatcher.dispatch method where a ActionController::CgiRequest gets created. Also note that you are doing a GET in your browser test, but a POST with Net::HTTP. -- James. http://blog.floehopper.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Conrad Taylor
2007-Mar-05 06:37 UTC
Re: Routing Error when using "Net::HTTP.start" but doesn''t occur when testing via Browser
Hi, are you really posting data to the form location? If this is truly the case, you can do something like the following: BEGIN CODE: require ''net/http'' require ''uri'' url = " http://localhost:3000/mycontroller/myaction " res = Net::HTTP.post_form( URI.parse( url ), post_data ) puts res.body END CODE: Note: The post data should be represented as a hash. Good luck, -Conrad On 3/4/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I''m stuck on a Routing Error I''m getting when calling my application (App2) > from a test/stub application (App1), however when I enter the same request > to App2 via the browser I do NOT get this routing issue and it works. > > My problem is in more detail (if anyone can help) that: > > [1] when I call an action in App2 from App1 I get a ROUTING ERROR, > "Recognition failed for /mycontroller/myaction" - this seems to come from > App2''s inbuilt Rails framework which somehow sees a routing problem and > immediately sends back a "Routing Error" message without ever getting to my > code within App2. > [2] when I use the browser with same > "http://localhost:3000/mycontroller/myaction" URL (i.e. > that App1 seems to be correctly producing, although I don''t have a HTTP > trace mechanism to 100% prove this) App2 seems to work fine > [3] again I don''t see any log info turn up in App2 (as if the rails > framework picked up on the routing error first and then bounced it prior to > my code getting involved) > [4] some details of my code below > > Code Used (which resides in App1 running on port 3001 - it''s calling App2 > running on port 3000) > url = " http://localhost:3000/mycontroller/myaction " > uri = URI.parse(url) > response = nil > Net::HTTP.start(uri.host, uri.port) do |request| > response = request.post(uri.path, postData) > end > > Note that "response.body " here gives: > <html> > <head> > <title>Action Controller: Exception caught</title> > << CUT >> > </head> > <body> > <h1>Routing Error</h1> > <p><pre>Recognition failed for > "/mycontroller/myaction"</pre></p> > </body> > </html> > > Browser Test > * Yet when I call the same URL from my browser it works (and doesn''t give > this message). The URL I use here would be: > http://localhost:3000/mycontroller/myaction > > > Any ideas/help? I can''t seem to see what I''m doing wrong. Any way to trace > the HTTP coming directly into App2 to see for myself what Rails is doing? > What about a way to turn up the logging/trace for rails re HTTP? > > > Thanks in advance > Greg > (TextEdit / MacBook) > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Mar-05 07:31 UTC
Re: Routing Error when using "Net::HTTP.start" but doesn''t occur when testing via Browser
to give some more detail calling application is my PalPal stub, and it''s making a HTTP call to my application to simulate the PalPal IPN call. So all I have in my application is a "handle_IPN" action in my PayPal controller. Does this clarify things? I''ll try the "Net::HTTP.post_form" approach instead of "Net::HTTP.start" then to see if this helps...I don''t fully understand the difference. Perhaps I need to use a Net:HTTP method that simulates a GET rather than a POST? (noting James''s point) Tks Greg On 3/5/07, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Hi, are you really posting data to the form location? If this is > truly the case, you can do something like the following: > > BEGIN CODE: > > require ''net/http'' > require ''uri'' > > url = " http://localhost:3000/mycontroller/myaction " > res = Net::HTTP.post_form( URI.parse( url ), post_data ) > > puts res.body > > END CODE: > > Note: The post data should be represented as a hash. > > Good luck, > > -Conrad > > On 3/4/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi all, > > > > I''m stuck on a Routing Error I''m getting when calling my application > (App2) > > from a test/stub application (App1), however when I enter the same > request > > to App2 via the browser I do NOT get this routing issue and it works. > > > > My problem is in more detail (if anyone can help) that: > > > > [1] when I call an action in App2 from App1 I get a ROUTING ERROR, > > "Recognition failed for /mycontroller/myaction" - this seems to come > from > > App2''s inbuilt Rails framework which somehow sees a routing problem and > > immediately sends back a "Routing Error" message without ever getting to > my > > code within App2. > > [2] when I use the browser with same > > "http://localhost:3000/mycontroller/myaction" URL (i.e. > > that App1 seems to be correctly producing, although I don''t have a HTTP > > trace mechanism to 100% prove this) App2 seems to work fine > > [3] again I don''t see any log info turn up in App2 (as if the rails > > framework picked up on the routing error first and then bounced it prior > to > > my code getting involved) > > [4] some details of my code below > > > > Code Used (which resides in App1 running on port 3001 - it''s calling > App2 > > running on port 3000) > > url = " http://localhost:3000/mycontroller/myaction " > > uri = URI.parse(url) > > response = nil > > Net::HTTP.start(uri.host, uri.port) do |request| > > response = request.post(uri.path, postData) > > end > > > > Note that "response.body " here gives: > > <html> > > <head> > > <title>Action Controller: Exception caught</title> > > << CUT >> > > </head> > > <body> > > <h1>Routing Error</h1> > > <p><pre>Recognition failed for > > "/mycontroller/myaction"</pre></p> > > </body> > > </html> > > > > Browser Test > > * Yet when I call the same URL from my browser it works (and doesn''t > give > > this message). The URL I use here would be: > > http://localhost:3000/mycontroller/myaction > > > > > > Any ideas/help? I can''t seem to see what I''m doing wrong. Any way to > trace > > the HTTP coming directly into App2 to see for myself what Rails is > doing? > > What about a way to turn up the logging/trace for rails re HTTP? > > > > > > Thanks in advance > > Greg > > (TextEdit / MacBook) > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---