Showing posts with label RoR. Show all posts
Showing posts with label RoR. Show all posts

Tuesday, April 6, 2010

Faster protoyping with Rails webservices

Well, I just spent about a 1.5 days tweaking/trying to get a VERY simple Maven/CXF/Spring project deployed on WebLogic 10.3.2 (the web service part wasn't the issue... this could have been deployed on Jetty/Tomcat in minutes) - finally got it deploying to WLS from Eclipse (but not JDeveloper of course, but that's another story)

For kicks, I thought I'd see what it would take to set up a webservice in Ruby/Rails. (about 10 mins for the impatient)

There used to be a gem called actionwebservice, but it looks like it's been removed from Rails so install datanoise-actionwebservice instead.
sudo gem install datanoise-actionwebservice --source http://gems.github.com

Now, set up a quick rails app and configure the environment.
rails ws-test

Edit the config/environment.rb file:
1) Find the load_paths section and add:
config.load_paths += %W( #{RAILS_ROOT}/app/apis )

2) Find the config.gem section and add:
config.gem 'datanoise-actionwebservice', :lib => 'actionwebservice',
:version => '2.3.2'

Ok, now lets take advantage of that config work we just did...
Create the app/apis directory that we referenced in the environment.rb file
mkdir app/apis

Create the app/apis/hello_world_api.rb file
class HelloWorldApi < ActionWebService::API::Base
api_method :hello_message, :expects => [{:name=>:string}], :returns => [:string]
end

Create a controller in app/controller/hello_world_controller.rb
class HelloWorldController < ApplicationController

web_service_api HelloWorldApi
web_service_dispatching_mode :direct
wsdl_service_name 'hello_message'
web_service_scaffold :invoke

def hello_message( name )
return "Hello #{name}"
end

end

Finally, fire it up...
script/server

And browse to http://localhost:3000/hello_world/invoke for a spiffy web page or http://localhost:3000/hello_world/wsdl for the WSDL.

UPDATE (4/7/2010): You can also use script/generate on webservices
script/generate web_service HelloWorld
create app/services/
exists app/controllers/
exists test/functional/
create app/services/hello_world_api.rb
create app/controllers/hello_world_controller.rb
create test/functional/hello_world_api_test.rb

Tuesday, May 26, 2009

Installing RoR on Ubuntu 9.04

Mainly because I always forget... here's the quickest way to get Rails installed on a fresh Ubuntu box.
First, grab everything you need to install the native gems. Then most of the ruby stuff and mysql (it will ask you to choose a root password - don't forget what you pick)
sudo apt-get install build-essential
sudo apt-get install ruby ri rdoc mysql-server libmysql-ruby ruby1.8-dev irb1.8 libdbd-mysql-perl libdbi-perl libmysql-ruby1.8 libmysqlclient15off libnet-daemon-perl libplrpc-perl libreadline-ruby1.8 libruby1.8 mysql-client-5.0 mysql-common mysql-server-5.0 rdoc1.8 ri1.8 ruby1.8 irb libopenssl-ruby libopenssl-ruby1.8 libhtml-template-perl mysql-server-core-5.0 libmysqlclient-dev
Next, grab the latest rubygem from Rubyforge (http://rubyforge.org/projects/rubygems/)
wget http://rubyforge.org/frs/download.php/56227/rubygems-1.3.3.tgz
tar -zxvf rubygems-1.3.3.tgz
cd rubygems-1.3.3
sudo ruby setup.rb
At this point, do:
gem -v
Since this is a fresh install, you'll probably see something like:
slotito@ubuntu-desktop:~/rubygems-1.3.3$ gem -v
The program 'gem' can be found in the following packages:
* rubygems1.8
* rubygems1.9
Try: sudo apt-get install
bash: gem: command not found
If you do, create some symlinks:
sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri
sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb
Ok, now for rails and some goodies =)
sudo gem install rails
sudo gem install mysql
sudo apt-get install imagemagick
sudo gem install rmagick
sudo gem install mongrel