Saturday, February 10, 2007

Rails 1.2 impact on Ajuby release 0.4

We are running into quite a few issues with latest Rails version 1.2 starting with Theme generator complaining about "named_route" , following is the exception that we get

=> Booting WEBrick...
./script/../config/../vendor/plugins/theme_support/lib/patches/routeset_ex.rb:26:in `create_theme_routes': undefined method `named_route' for #<actioncontroller::routing::routeset:0xb7d34690> (NoMethodError)
from script/../config/../vendor/plugins/theme_support/lib/patches/routeset_ex.rb:13:in `draw'


Reason is Theme generator is using its own routes extension for its custom routes and as per Rails 1.2 release , Routes section).


So meanwhile we figure out how to fix this or Theme generator comes with fix for Rails 1.2, Following is the fix that you can do

# Lets freeze the Rails for Ajuby release by running following command

> rake rails:freeze:edge TAG=rel_1-1-6

This will take rails 1.1.6 and make rails available within Ajuby framework, (We will eventually go this route. Every release will be bundled with Rails , so one less thing to worry with)

# After above step successfully complete, start the WEBrick and see if you run into any error , if yes possibly you would not have Activerecord core frozen properly. Not sure whether its a bug in the rake process. If you see this error like undefined method "deprecate" or #<Class:......

Copy activerecord/lib directory from your installed Rails (wherever you have installed rails version 1.1.6 before above freeze process) to <ajubyhome>/vendor/rails/activerecord/lib directory

Thursday, February 08, 2007

Ajuby Release 0.4 is out

We are happy to announce latest release of Ajuby (0.4) out for general access/download on source forge/Google code.

We are gearing up for next release, with interesting features like Module builder. Updates will be on the Ajuby wiki for coming release

Thursday, February 01, 2007

Apache Axis namspace quirk in a SOAP response

When you use Apache Axis for your web services implementation , its a wise move but you got to remember its few one off situations, like this one that I'm going to explain.
Apache axis generates namespaces in every single element of the response , which can be very painful for the client if client is going parse and moreover its additional overhead in your SOAP response back to client, you are pushing more data over the wire where it can be avoided. sample looks something like this

<SOAP ENV..>
<SOAP Header..>
</SOAP Header..>
<SOAP body>
<ns1:elemenntname xsi:type="xsd:string"
xmlns:ns1="http://a.b.c/...." >
<ns2:elemenntname xsi:type="xsd:string"
xmlns:ns2="http://a.b.c/...." >

<ns3:elemenntname xsi:type="xsd:string"
xmlns:ns3="http://x.y.z/...." >

</SOAP body>
</SOAP Env...>


So above if you see , its unnecessary data getting duplicated in each element, where as ideally axis should be doing this internally by aggregating namespaces. So what you have to do is add following code in the your services code

org.apache.axis.utils.NSStack namespaceList = new org.apache.axis.utils.NSStack();
namespaceList .add("http://a.b.c./...", "ns1");
namespaceList .add("http://x.y.z./...", "ns2");
soapRespEnv.setNSMappings(namespaceList .cloneFrame());

Where as soapRespEnv is SOAP response envelope fetched from MessageContext. So what will above code do is, it will notify Axis engine to aggregate SOAP response namespaces in the SOAP envelope root. your response would look like below after above change



<SOAP ENV. xmlns:ns1="http://a.b.c/...." xmlns:ns2="http://x.y.z/....">
<SOAP Header..>
</SOAP Header..>
<SOAP body>
<ns1:elemenntname xsi:type="xsd:string">
<ns1:elemenntname xsi:type="xsd:string">

<ns2:elemenntname xsi:type="xsd:string">

</SOAP body>
</SOAP Env...>



benefitof above approach is

* Sheer data size reduction, that goes over the wire
* SOAP response looks like very clean.

Thursday, December 28, 2006

How to use Dynamic Object invocation in Rails for Models (String to Model conversion)

Requirement
-------------
You have String value of the model (model name) and you want to dynamically invoke methods on this model. This comes handy when you want to parse controller/action and do some neat nifty tricks.


Solution
-----------
model_name = "invoice"

model_name_capital = model_name.capitalize # => this creates "Invoice"

@object = Object.const_get(model_name).find(:all) # => This is equivalent to Invoice.find_all

Wednesday, December 27, 2006

Ruby 4 Lines of Web service/SOAP Code Magic

This is amazing to see how easy and simple it is to write a SOAP code in ruby, have a look at the following code. This does call Google search engine by passing some random search query.

require 'soap/wsdlDriver'
factory = SOAP::WSDLDriverFactory.new("http://api.google.com/GoogleSearch.wsdl")
service = factory.create_rpc_driver
@service_output = service.doGoogleSearch("xxxxxxxxxxxxxx", "Ajuby", 0, 10, "false", "", "false", "", "latin1", "latin1")

That's it.. @service_output returns what I call it as "Ruby's intelligent data structure" which you can use to get respective data output

e.g.
- Results: <%=@service_output.estimatedTotalResultsCount%>
- searchTime: <%=@service_output.searchTime%>


Note: Above "xxxxxxxxxxxxx" is the api key that you need to obtain from Google to use their web services, its less than a minute job to get that from google.

Now there is a better and more modular way of writing above code using ActionWebService
where you can manage API's to access outgoing SOAP calls more effectively.

Monday, November 27, 2006

XSD to WSDL Conversion

# Good site to refer contract-first web service and XSL that translates XSD to WSDL
# Also Christian Weyer's jWSCF for Eclipse
# ObjectWeb's Celtix ESB's xsd2wsdl tool

Surprisingly first 2 generates different type of WSDL for same XSD.

Tuesday, October 10, 2006

Legends/Great Programmers answer simple but important questions..

This one is a classic page, should go in a history of software/hardware. Author of this page has done good job in asking simple but interesting (in terms of these great guys and their outlook towards simple things in their day to day life).
I liked the question "If you had three months to learn one relatively new technology, which one would You choose?". Answers to this question can project one vital thing "What is the interesting technology/concept or thing which you would see helping technology future"


Monday, October 09, 2006

Java String replace: java.lang.IndexOutOfBoundsException: No group 2

Issue

If you see java.lang.IndexOutOfBoundsException: No group 2 , when you are doing <String>.replaceFirst(<source string>, <target string>) or <String>.replaceAll(<source string>, <target string>).

Reason

You possibly have "$" character in your target string.

Solution

Add java.util.regex.Matcher.quoteReplacement(<target string>), before you apply replace function.

Bug reported on Sun site by someone.

Thursday, October 05, 2006

OpenAppDotOrg Toolkit hits 100 downloads!!.


Our Ruby/Rails based open source project OpenAppDotOrg finally hits 100 downloads on sourceforge . Groovy!!... See the captured snapshot of that moment on the left. This is just a beginning, we have a long way to go and I will come back to toast 1,000.....of downloads.

Current release 0.2515 includes, things like
  • Common user services (sign up/email support/forgot password etc)
  • User access control
  • Company/User relationship
  • First open source Feed management module

  1. More about the project can be found on our wiki
  2. Download the latest version from sourceforge
  3. Our community on Google groups and openapp forum

Tuesday, October 03, 2006

Rails Association example: has_many relationship

After a long time, I finally get to write this up. Step by step instructions to build Rails:ActiveRecord: has_many relationship.

Once you start with this , you can sense the power of this meta modeling techique which turns your business application/model building into a snap.

I will write up more going deeper into complex techniques of Rails association, meanwhile few interesting sites explain this as follows

Friday, August 18, 2006

Ruby/Rails tricks and tips with ActiveRecord

I had a simple problem definition:
  • Write a installer application in rails which will take database username, password and database name
  • Creates brand new database
  • Populate the database with schema and reference data.
  • Updates database.yml file
  • Reinitialize the rails activerecord connection context, so that user does not have to restart the application
This is how I solved it. few steps , hopefully this will be usefull for other ppl who wants to do something similar.


# Create new database

ActiveRecord::Base.connection.create_database("rex_boy") #rex_boy new database name.

# Load new database with schema and data.
.........This you can do either by using writing Rake migrate tasks or manually write SQL's to load the schema and data, 1000's of ways to do this. I did using creating using migrations and invoking rake command from rails.


# Read and update the database.yml file with newly created database

## Read the Yml and update with new database name
@config = YAML::load(File.open("#{RAILS_ROOT}/config/database.yml")) @config['development']['database']= "rex_boy"

## Now update the yml file back. basically write the database.yml back from @config object
File.open( "#{RAILS_ROOT}/config/database.yml", 'w' ) do |f| f << @config.to_yaml

# Now the interesting part to reintialize ActiveRecord connection context without restarting the server (Apache or WEBrick or Lighttpd..)

ActiveRecord::Base.configurations = @config ActiveRecord::Base.establish_connection ActiveRecord::Base.connection



This should get you very fancy in terms of building rails based installer application.

Thursday, August 10, 2006

Framework comparison

Check this video (almost 340MB) out, Its fun and gives users a quick glance at all the frameworks that author of this video is trying to use. He is comparing J2EE vs Ruby on Rails vs Zope vs TurboGears vs Django.

Friday, August 04, 2006

Rails based framework for Java. Co-existence or contender?

I was sailing thru the net to see if there is anyone doing Rails framework on Java?. so some of the following guys who are doing few things similar to rails, not all.

# Trails: domain driven development framework in the spirit of Ruby on Rails or Naked Objects. Uses Spring, Tapestry, and Hibernate. Probably this one has a long way to go. Not too much happening in this area.
# Sails: Purely framework designed by keeping Rails in mind. Have a download section.It would be interesting to download and play with it.
# Grails: Sounds the closest one to rails, including controller/model generation, scaffolding etc, its written in Groovy
# JBoss Seam: Probably most active and adopted project as compared to above. Seam uses EJB3 and Hibernate (both, I wonder why?. Probably things around Transaction support and things like heavy weight vs light weight components usage).

I will keep watching this space and add if i run into any other puppy who wants to be or do things like rails in Java.

Friday, June 09, 2006

Quick view on Computer Software/Programming Languages History

I found this great collection of pictures of Programming language creators/authors, surely a Wall of Fame for all those people who wants to be inspired by probably the best men to walk over this planet earth. Men who made today's world of computer/software/programming/ possible

Apache would not start if Skype is running

I wasted 30 mins figuring this out without knowing what could be the real reason. If you are trying to start your apache (with or without mod_ssl/:443 port enabled) and if you have Skype already running on your machine, Apache won't start, it will not create any error log, so you go look at your event viewer you will see something like

  • System Log: "The Apache2 service terminated with service-specific error 1." ; Arghh!! so helpful ;)
  • Application Log: "The Apache service named reported the following error:
    >>> Unable to open logs" , "The Apache service named reported the following error:
    >>> no listening sockets available, shutting down . "

Now the last message is little useful and it says that there is something already listening/running on port 80/443 , But hunting down was tough!. Because I don't have any other web server running. Root cause is "Skype"

Go to Skype->Tools->Options->Connection-> Uncheck "use 80 and 443 for incoming connection"

Who would ever thing my IM will waste my time, where as IM's are supposed to be productivity improvement tools :) , Anyways a good find and I hope it will be useful for others too. BTW No complains for skype, its a great tool.

Tuesday, June 06, 2006

Funky Browser based ruby shell

Tryruby is Neat!!...but couple of things are hack, Like I type

require 'abracadabra'
=>true

Now I don't think anyone has written gem called abracadabra yet. but this shell is cool, very handy. I tried quick String manipulation test, it works!

Monday, June 05, 2006

Is MySpace becoming IPOD for social community business platform

As usual I landed on Techcrunch website and what I see first 2 posts (companies), doing their business around MySpace. Like ,
  • SingleStat.us: Its a funny concept, but works for lot of singles or people with old crush. Techcrunch says "Want to know when that cute friend of yours breaks up with her boyfriend....a service that let’s you type in anyone’s Myspace profile and be notified by email if their relationship status changes".
  • Nooz: Interactive news service aimed for MySpace users, to start with.
  • and lot many...

So the question of the day: Is MySpace becoming IPOD for social community business platform. Like IPOD did, people made lots of dough by spinning their business around IPOD, concepts around IPOD. Now MySapce universe is emerging in a way, it's helping lots of Web2.0 startups to grow.

Monday, May 29, 2006

Buttonator....

Pretty nifty tool/site create buttons. It's very handy. check it out, world of web 2.0 design is getting easier every step of the way.

Friday, May 19, 2006

Ruby Java Bridge is here

Ruby bridge to Java is here, Not sure how smooth it is but surely worth a try.

Thursday, May 11, 2006

How Ruby can be next generation business building block

  • As Martin fowler said "As a result it certainly seems to me that certain languages are more suited to in-language DSL than others. Seeing lisp and smalltalk I concluded that the more suitable languages were minimalist ones with a single basic idea that's deeper and simpler than traditional languages (function application for lisp, objects and messages for smalltalk). But Ruby is more conventional and a much bigger language than these two, yet is still suitable for in-language DSLs."
So Ruby certainly sounds like a language which can rapidize (Not sure that's legal word or not, but I felt like using it here) business application building.