Wire Level Debug for ActiveResource

Posted by dave
on February 13, 2007 @ 08:08 AM

ActiveResource provides the mechanism to implement RESTful Ruby clients in Rails 1.2. If you want to see wire level debug output from the Net::HTTP layer you can enable it by editing:


[activeresource]/lib/activeresource/connection.rb

Add the set_debug_output line to the (private) http method.

1
2
3
4
5
6
7
8
9
10
11
12

     def http
        unless @http
          @http             = Net::HTTP.new(@site.host, @site.port)
          @http.use_ssl     = @site.is_a?(URI::HTTPS)
          @http.verify_mode = OpenSSL::SSL::VERIFY_NONE if @http.use_ssl
          # enable debug http wirelevel dumps
          @http.set_debug_output $stderr
        end

        @http
      end
Very handy for debugging ActiveResource with a Rails console.

Switched to Mephisto

Posted by dave
on February 06, 2007 @ 10:18 PM
Thanks to Bluehosts shenanigans of upgrading the underlying version of Rails without any notice, I've had to say farewell to Typo. I've made the switch to Mephisto. Still managed to keep the Scribbish theme but live search is no more and theres a couple of other issues to sort out (haven't managed to get the del.icio.us plugin working yet).

Adding ActiveResource support to Rails 1.2

Posted by dave
on January 25, 2007 @ 10:00 AM

Rails 1.2 was released earlier in the week with lots of cool new features but w/o ActiveResource or an ActiveResource gem. The good news is that you can add ActiveResource support by moving your application to edge rails and then check out ActiveResource as shown below.

>rails myapp
>cd myapp
>rake rails:freeze:edge
>cd vendor/rails
>svn co http://dev.rubyonrails.org/svn/rails/trunk/activeresource activeresource

Now you have a Rails app with ActiveResource support.

Note: I tried just checking ActiveResource into vendor/plugins but it conflicted with version 1.4.0 of ActiveSupport that ships with Rails 1.2. I had to move to edge rails to make it work.

Invoking backend SOAP/HTTP Web Services with Ruby

Posted by dave
on October 06, 2006 @ 10:54 AM
So ya wanna invoke on a backend SOAP/HTTP Web Service from Rails do ye? SOAP4R (SOAP 4 Ruby) gets the job done as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
require 'soap/wsdlDriver'
URL = 'http://localhost/hello_world.wsdl'

factory = SOAP::WSDLDriverFactory.new(URL)
driver = factory.create_rpc_driver
driver.wiredump_dev =  STDERR

begin
 
 // Invoke on the webservice here
 result = driver.sayHi
 result = driver.greetMe("dave")
 puts result

rescue Exception => e

  #Handle SOAP Faults here

end
This code snippet uses SOAP4R 1.5.5. This is a somewhat simplified example as theres only two methods defined in the wsdl, sayHi takes 0 parameters and greetMe just takes a string. Needless to say, this can be placed inside your Ruby on Rails controller too. If you have complextypes it looks as though you need to use wsdl2ruby to generate helper classes for the complextypes. I might be doing something wrong, but this version of SOAP4R looks to have some problems handling one particular rpc/literal wsdl I have here, but a bit more digging is required.