Dimuthuc’s Weblog

Just using what others shared..

New Year Gift for Ruby Developers, The Brand New Web service Dev Kit

Finally WSO2 Web Service Framework for Ruby (known as WSF/Ruby) is reached the milestone 1.0.0. It took us only 3 months to hit this as it was based on well established code in WSO2 WSF/C which is proven to be embeddable and most importantly we had WSO2 WSF/PHP which make more easier to do the same thing with ruby.

In this extension the consumer is written using swig interfaces which does the talk between ruby and c languages, but the provider engine is completely written in C which provides the high performance required in an enterprise level applications.

When compared with the other soap extensions of ruby, You will find this is the only choice that support following set of features,

  1. Full Support for MTOM binary attachments.
  2. WS-Security with username-token(For Authentication), sign(For Non-Repudiation), encrypt(For Confidentiality), time-stamp(For avoid replay attacks) support.
  3. WS-SecurityPolicy based configurations
  4. WS-Reliable Messaging
  5. The simple client and service APIs.
  6. Interoperability with Java, C, .Net

And it has a really comprehensive guide and blogs which update the community with really interesting thoughts on web services on ruby. Ruby developers like to write internet programs in few lines of code. So they will find this is the product for them to write web service clients and services in their natural style.

January 5, 2008 Posted by dimuthuc | Programming, WSF/Ruby, WSO2, Web services | , , , , , | 2 Comments

WSO2 WSF/Ruby Stepping towards 1.0

Yesterday We were doing an RC on WSO2 WSF/Ruby. It will enable growing ruby and rails developers to feel the taste of WS-* stack without having any trouble.

WSF/Ruby is based on the WSO2 WSF/C which itself based on set of apache web service projects like Axis2/C, Rampart/C, Sandesha/C, Savan/C. So the WSF/Ruby will be great platform to experience the power of these project.

Consuming a web services with WSF/Ruby is really simple. It need very few line of code to do a simple web service,


require "wsf"   req_payload_string = "<greet> Hello </greet>" 

client = WSO2::WSF::WSClient.new({"to" => "http://greeting_host/myservice"}) 

res_message = client.request(req_payload_string) 

p res_message.payload_to_s << "\n"

The service provider code would be simple as this, You may put this on some function in the controller class inside Rails. (Yea I mean Ruby on Rails)


def greet(message)      if message.payload_to_s == "Hello"   

      "<greetResponse>Welcome!</greetResponse>"   

   else 

      "<greetResponse>Still Welcome!</greetResponse>" 

   end 

end

service = WSService.new({"operations" => {"greet" => "greet"}}) #the greet service operation to greet function map 

res = service.reply(request, response) 

render :text => res

Ok, That may seems ordinary. How about improving the service by authenticating the user with username tokens,Consumers may give their identity by adding some options at the constructor of WSO2::WSF::WSClient,


   policy_content = {"use_username_token" => true}   

 policy = WSPolicy.new({"security" => policy_content})   

 security_options = {"user" => "dimuthu",   

     "password" => "not my real one",   

     "password_type" => "Digest"} 

security_token = WSSecurityToken.new(security_options) 

options = {"to" => "http://greeting_host/myservice", 

      "policy" => policy, 

      "security_token" => security_token} 

client = WSClient.new(options)

And the service provider will also change their code just to authenticate the user,


  def passwordCallBack(username)    # hopefully you will be taking the password out from database   

  if(username == "dimuthu")   

    return "not my real one" 

  else 

    return "I m a guest" 

  end 

end  

policy_content = {"use_username_token" => true} 

policy = WSO2::WSF::WSPolicy.new({"security" => policy_content}) 

sec_token = WSO2::WSF::WSSecurityToken.new({"password_callback" => "passwordCallBack", 

                                            "password_type" => "Digest"}) 

wss = WSO2::WSF::WSService.new({"operations" => operations, 

                                "policy" => policy, 

                                "securityToken" => sec_token})

Similarly not only the username token, but also complete specifications of WS-Security, WS-Addressing, WS-Policy and WS-Reliable messaging can be used from a simple script with WSF/Ruby. This API is proven to be simple and popular with its predecessor WSO2 WSF/PHP. Hope we can do the same in Ruby as well.:)

December 8, 2007 Posted by dimuthuc | Programming, Ruby, WSF/C, WSF/PHP, WSF/Ruby, WSO2, Web services, axis2/c | , , , , , , | 1 Comment