Tuesday, September 15, 2009

Initialization Error When Invoke Weblogic webservice Through Client Stub

I faced an strange error message when I tried to call webservice client stub from a POJO class.
The web service is hosted on a weblogic server instance and is generated using jwsc. The client is generated from the generated wsdl. I use weblogic clientgen ant task to generate the stubs.



The exception I got is:


Exception in thread "Main Thread" java.lang.ExceptionInInitializerError
at weblogic.wsee.ws.init.WsDeploymentChain.newClientChain(WsDeploymentChain.java:24)
at weblogic.wsee.ws.WsFactory.callClientListeners(WsFactory.java:108)
at weblogic.wsee.ws.WsFactory.createClientService(WsFactory.java:46)
at weblogic.wsee.jaxrpc.ServiceImpl.init(ServiceImpl.java:143)
at weblogic.wsee.jaxrpc.ServiceImpl.<init>(ServiceImpl.java:111)
at com.cibc.eccs.omni.bre.wsclient.GetRuleEngineConfigurationService_Impl.<init>(GetRuleEngineConfigurationService_Impl.java:21)
at com.cibc.eccs.omni.bre.wsclient.GetRuleEngineConfigurationService_Impl.<init>(GetRuleEngineConfigurationService_Impl.java:13)
at com.cibc.eccs.omni.test.RuleEngineConfigClientTest.getRuleEngineConfig(RuleEngineConfigClientTest.java:23)
at com.cibc.eccs.omni.test.RuleEngineConfigClientTest.main(RuleEngineConfigClientTest.java:39)
Caused by: java.lang.ClassCastException: com.bea.xbean.values.XmlTokenImpl
at weblogic.wsee.tools.wseegen.schemas.impl.ListenerTypeImpl.getListenerClass(ListenerTypeImpl.java:37)
at weblogic.wsee.ws.init.WsConfigFactory.getDeploymentListenerConfig(WsConfigFactory.java:139)
at weblogic.wsee.ws.init.WsConfigFactory.load(WsConfigFactory.java:110)
at weblogic.wsee.ws.init.WsConfigFactory.newInstance(WsConfigFactory.java:59)
at weblogic.wsee.ws.init.WsConfigFactory.newInstance(WsConfigFactory.java:45)
at weblogic.wsee.ws.init.WsConfigManager.<clinit>(WsConfigManager.java:8)
... 9 more


First, I thought it is caused by not properly defined shcema xsd which makes wsdl invalid and cause this. But everything is checked and I still have this error message... Then I start suspect my running mode. I'm running a pojo inside eclipse to call the weblogic server endpoint, the pojo is using the classpath set in eclipse. I checked the classpath the pojo is invoked with in eclipse and everything is included. Then I dig further and found the actual exception is thrown inside weblogic.jar when the ServiceImpl class constructor is invoked. This jar is in the classpath, but maybe there is some conflicts. After puting the weblogic.jar to the top of my classpath, things are okay.


Monday, August 24, 2009

Update mysql gem for rails

Had a problem updating mysql gem today... keep getting the following error:
ERROR:  While executing gem ... (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb update mysql
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no

Copied the error and googled around and found a solution. It appear to be that gem installationis not finding mysql directory correctly. However, that fix doesnot work for me as I still getting the same error after regenerated Makefile...

So, I used the very basic way: install the mysql gem, which will install the latest version for me.

On my snow leopard:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

On 10.5 leopard:

sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

If you getting further error such as "rake aborted! uninitialized constant MysqlCompat::MysqlRes"
when doing "rake db:migrate", check this post for solution.

Saturday, August 8, 2009

Calculate And Format Due Date In Words

In my todo application, I want to show the due date in years, months, weeks and days... I saw many sites have this feature but I couldn't find any available source code by googling. So I decide to implment my own. It is premature and only server simple purposes. If you find it helpful and save you some time, feel free to copy and use it. It's a helper method added into your application helper or any helper in your rails application.


# Helper method to calculate a string presentation of days from due
def due_from(due_date)
  return "long-term" if due_date == nil
  return "overdue" if due_date.past?
  return "today" if due_date.today?  
  today = Date.today
  return "tomorrow" if due_date == today.tomorrow

  diff_year = due_date.year - today.year  
  diff_month = due_date.month - today.month
  diff_day = due_date.day - today.day  
  diff_week = diff_day/7
  diff_month = diff_month -1 if diff_day < diff_year =" diff_year" y_str = " #{diff_year} "> 1? "years" : "year")
  m_str = " #{diff_month} " + (diff_month > 1? "months" : "month")
  w_str = " #{diff_week} " + (diff_week > 1? "weeks" : "week")
  diff_day = days_in(today.month) + diff_day if diff_day < d_str = " #{diff_day} "> 1? "days" : "day")

  if diff_year > 0
    if diff_month > 0
      return y_str + m_str
    else
      return y_str
    end    
  end

  if diff_month > 0
    if diff_week > 0
      return m_str + w_str
    else
      return m_str
    end
  end

  if diff_week > 0
    diff_wd = diff_day%7
    if diff_wd > 0      
      d_str = " #{diff_wd} " + (diff_wd > 1? "days" : "day")
      return w_str + d_str
    else
      return w_str
    end
  end

  return d_str
end

 def days_in(month)
   (Date.new(Time.now.year,12,31).to_date<<(12-month)).day    end 



Below is the actual effect: the due date is displayed as word description

Show due date in meaningful words

Saturday, July 25, 2009

Fix Ubuntu update manager download speed

You may experience the same thing I did today. Ubuntu update manager download speed is very slow (<10Kb/s) however network speed is normal for other applications like email or browsing.


It turns out that a slow repository is selected for update manager. After I let the system pick the best server, my update manager is downloading at normal speed (>500Kb/s).


Thursday, July 23, 2009

CSS Progress Bar for Ruby on Rails App

Today, I spent sometime working on my TODO application and found that I need a progress bar to show the status of completion.

However, I don't find any helpful source so I decided to invent my own wheels. It turns out that pure CSS progress bar is easy to implement. So I wrote a application helper method for my view.


# Progress Bar Helper
 # Paramemters
 # progress - integer value between 0 - 100 indicating progress percentage
 # options available:
 # :width - bar width, default to 500px
 # :height - bar height, default to 20px
 # :text - Show text in progress bar, which will also increase the bar height if less than 20px
 # :text_color - Set the text color shown in progress bar
 # :bg_color - background color of the progress bar
 # :bar_color - progress bar color

 def progress_bar(progress,options={})
   width = options[:width] || 500
   height = options[:height] || 20
   bg_color=options[:bg_color] || "#DDD"
   bar_color=options[:bar_color] || "#6A5ACD"
   text = options[:text]
   if text
     height = 20 unless height>=20
     text_color = options[:text_color] || "white"     
     text_content = content_tag(:span,text,:style=>"margin-right: 3px; color: #{text_color};")
   end     
   style1 = "width: #{width}px; background: #{bg_color}; border: 1px solid black; height: #{height}px;"
   style2 = "text-align: right; float: left; background: #{bar_color}; width: #{progress*width/100}px; height: #{height}px"
   content_tag(:div, content_tag(:div,text_content,:style=>style2),:style=>style1)
 end


Monday, June 22, 2009

iPhoto 8.0.3 bug fixed

Apple issued a new bug fix update today to fix the bug created by incompatibility between Safari 4 and iPhoto 8.


The main bugs included map undragable, location search long wait time, and etc..


Again, thanks to the Apple engineers for this quick fix. Just check your system update, there should be a Safari update on this bug.

Friday, June 19, 2009

iPhone OS 3.0 upgrade

Tonight I finally have my iPhone upgraded to OS 3.0. The first thing I try As soon as I finished the upgrade is the my most wanted function copy and paste! The new function design by apple is very creative and easy to use. Just touch the text you want to copy and hold for a sec, the text will be selected and you will be given a option to copy, cut or paste. Just as it shown on the apple's announcement video. I also love the spotlight feature, especially being a mac user.


Updated! Now, tethering is available!! One way to enable thethering from your provider, is to use your iPhone safari to go to this post and clik on the proper provider. I have tried it and it works great on my Mac. For some reason I can't get it to work for my WinXP at the moment. For mac user, I tried and comfirm it's working!


Enjoy surfing with your iPhone!

Tuesday, June 16, 2009

iPhoto 8.0.3 update has bugs

I have updated iPhoto and safari couple days ago but didn't notice until today that the iPhone got a serious bug after update. The one that annoyed me the most is the map is no longer draggable. Instead of dragging the map, I'm dragging a single map tile...


As usual, I open my brawser and start looking for answers. I come across the post iPhoto 8.0.3 updater bug bites many and quickly found the solution (rather a workaround) for the map issues inside the post comments.


What I need is to remove the 'my com.apple.iPhoto.plist' file from ~/Library/Preference folder. This file contains all your iPhoto personal settings, such as the size of thumb nails and alert messages. But don't worry, all your tags on Faces and Places are not in this file so removing the file will not removing your faces and places settings (what a relief!).


Unfortunately, the bug will come back after iPhoto got restarted. So go ahead remove the file again and restart your iPhoto, your maps in places will behave correctly.... I know it sucks, that's why it's just a workaround.


The post also issues some other bugs caused by this update, so if you experience big impact by those bugs, I encourage you to send feedback to apple through either iPhone (iPhoto->Provide iPhoto Feedback) or safari (safari -> report bugs to apple).


I do believe in Apple will come up with fixes for the bugs shortly. Meanwhile, just use the workaround.

Monday, June 15, 2009

iPhone 3G(S)

The new iPhone is going to hit the market in Canada within next week.

I'm really looking forward to the new 3.0 platform as well as the SDK. Although I'm not a iPhone developer (not yet), but the new APIs introduced in SDK do make me feel the urge to learn and write something exciting on the phone.

Here are some of the new APIs I feel most interested:

1. Push Notification - reworked and scalable
2. Accessory API - that can turn iPhone into virtually everything...
3. Ability to embed Google Map and Email inside application - really user friendly feature
4. Other native support to make application development easier and faster

Use Permalink in Rails

It is easy to setup permalinks in Rails, so that your application url will show the meaningful path other than the default controller/action/id format.


To enable permalink in Rails, you need to add a column to store the permalink string (give it any name e.g. permalink). Then in your model, override the to_param metod to use the permalink as shown below:


 class Post < ActiveRecord::Base
has_many :comments, :dependent => :destroy

def to_param
"#{id}-#{permalink}"
end
end

You might encounter a strange error that says


modelname_url failed to generate......


I had this problem on my server and it turns out that I had a '.' in my permalink. '.' is used to set sub-domain in your url. Having '.' unintentionally will make url invalid.

Friday, June 12, 2009

Textmate Twilight Theme For Eclipse

Are you tired of coding with Eclipse default theme and want to get the colorful eye comforting Twilight theme availabe only in Mac Textmate? I do.


But I can't find any good ones on Google so I start making one myself. It all comes down to a bunch of preference setting in Eclipse. So if you want to use the setting, you just need to download and import the eclipse preference setting to your own eclipse. Before doing so, don't forget to export your current setting as a backup!!


You also need to install the Monaco font into your system. The font installation depends on your OS.


So, get the font and preference, install the font and import the preference. You are all set.


Enjoy coding in Twilight!

Wednesday, June 10, 2009

AirPort Express - Music all around

Apple got this great idea that all speakers at home can play music in sync with the help with its AirPort Express.

Today, I bought one and gave it a try. It's surprisingly easy to setup. Just plug in the AirPort Express on the wall outlet close to my HiFi stereo then connect the audio into stereo. Then install the AirPort Utility in the CD shipped with the Express and follow a simple setup (it automatically finds the wireless network, if your computer is using that network, it even filled the password for ya!). All done in 5 mins!!

Now, in my iTune, there is a pull up menu available at the bottom right corner. From the menu I can select which speaker I want to play my music, e.g. from computer, from my stereo or both (now both my computer and stereo are playing music in sync!!).

What's even more amazing is the iPhone Remote application that is available on my iPhone. I can now remotely control my iTune on my phone which means full controll of my computer and stereo output!

I love this experience and will definitely install more Express when I have a bigger house. Imagine walking in my house with all the speakers playing same music in sync.... This feeling is like walking in a shopping mall... Cool

Saturday, June 6, 2009

Setup rails on ubuntu

Today I have setup RoR environment on my laptop installed with ubuntu 8.03

Here are the things I have done:

1. sudo apt-get install ruby

2. sudo apt-get install rubygems

#The gem installed is not working because of some deprecated lib, so I have to do a few more steps:
gedit ~/usr/bin/gem
#Make the first three lines looks like below:
require 'rubygems'
require 'rubygems/gem_runner'
#Gem.manage_gems

3. sudo gem update --system

4. sudo gem install rails

5. sudo apt-get install mysql-server

6. sudo apt-get install libmysqlclient15-dev

7. sudo gem install mysql

8. Copy my .profile content to .bash_aliases (new file)
gedit ~/.bashrc
uncomment the following lines in .bashrc file:
if[ -f ~/.bash_aliases]; then
.~/.bash_aliases
fi

9. Install Java (in order to install NetBean)
sudo gedit /etc/apt/sources.list
Add the following if now there
deb http://us.archive.ubuntu.com/ubuntu feisty main restricted
deb http://us.archive.ubuntu.com/ubuntu feisty universe multiverse

sudo apt-get update

sudo apt-get install sun-java6-jre sun-java6-jdk sun-java6-plugin


That's it!!