Eclipse loading problem : XPCOM error

November 3, 2008 by samindaw

If you are an eclipse user you may have come across this error atleast once in you lifetime. Sometimes this error shown as a message “Widget disposed too early” or something like that. To be more precise when starting eclipse it just hands on a small blank dialog kind of form after specifying the workspace. You cannot close or exit from this form. It just hangs.

This happens mostly in linux. I experienced this in ubuntu hardy with Ganymede mostly. If this happenes first thing you should do it to verify the problem. Just check the log for the workspace to see what the exception thrown before eclipse hanged. For example in our case it will be something like this.

Exception in thread “Thread-1″ org.eclipse.

swt.SWTError: XPCOM error -2147467262
at org.eclipse.swt.browser.Mozilla.error(Mozilla.java:1360)
at org.eclipse.swt.browser.Mozilla.setText(Mozilla.java:1564)
at org.eclipse.swt.browser.Browser.setText(Browser.java:716)
at org.eclipse.jdt.internal.ui.infoviews.JavadocView.setInput(JavadocView.java:531)
at org.eclipse.jdt.internal.ui.infoviews.JavadocView.refresh(JavadocView.java:452)
at org.eclipse.jdt.internal.ui.infoviews.JavadocView.setBackground(JavadocView.java:439)
at org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView.inititalizeColors(AbstractInfoView.java:327)
at org.eclipse.jdt.internal.ui.infoviews.AbstractInfoView.createPartControl(AbstractInfoView.java:191)
at org.eclipse.ui.internal.ViewReference.createPartHelper(ViewReference.java:372)
at org.eclipse.ui.internal.ViewReference.createPart(ViewReference.j……

…..

Now for the solution.

Well the solution is a bit murkey. I came across the worst path of solving the problem with the only solution available. Eclipse uses XUL (spelled “zool”) for its GUI rendering when in linux. This is kind of weird because the actually reason i figured out is that it uses the platform current browser to do that for him. This in the case of linux where the default browser is most of the time is Mozilla Firefox, eclipse uses the functionalities of firefox to render its GUI. If in the case of windows it uses IE as I can remember. This is why the above exception contains the words like “browser” “mozilla” etc.

Anyway the problem occures due to a simple reason, the firefox browser does the rendering using the xulrunner. There is a default xulrunner when firefox is installed and this version is not updated enough for eclipse. Thus it cannot render the UI parts and the UI widgets are disposed not being able to be created correctly. So the easy solution is to update the xulrunner.

You can do a simple

$apt-get update xulrunner or $apt-get install xulrunner

Works most of the time. But sometimes its best to do a system wide upgrade using

$apt-get upgrade

because there is a version firefox which xulrunner also supports, and if the firefox is old (or in 3.0beta for eaxmple), the xulrunner will not get updated properly.

So after that the eclipse should work fine. But mind you, you might want to start on a fresh workspace anyway.

But i have seem in some instances where eclipse can start on a already created (and previously worked) workspaces. Yeah i know, WIERD!!!

Well In my case this worked great on eclipse, but with a hitch. The firefox was giving trouble now. The address bar not working properly, icons in the title bar disabled, No history or bookmarks shown etc. It looked like the upgrade messed up the firefox.

With a little bit of searching I found that this can happen if the firefox profile gets corrupted. For those of you who does not know what a firefox profile is, its just a simple profiles created by the firefox to keep track of each and every uses preferences/history/bookmarks/etc etc.

So all you have to do is to create a new firefox profile abadoning the one you already have. Google for how to create a new profile. For those of who wants to keep the old one all they have to do is to go and rename the “localstore.rdf” file to say “localstore.rdf.tmp” and restart the browser. (This file is normally located in “~/.mozilla/firefox/<somefolder_for_the_profile>/localstore.rdf”).

localstore.rdf is the file where most of the settings of the profile are declared. When this file is missing the browser automatically resets the settings for the browser. And you will see that the buttons and icons etc will start working normally again :)

but make sure u rename the “localstore.rdf.tmp” back to “localstore.rdf” after the browser resets the settings. Because if not eclipse again will start giving problems and this time it will not be specific on what the problem is. It will not even mention that the problem is with the profile of the browser. It will just not behavie as you expect and make you think there is something wrong in you code (because most of the time it doesn’t throw an exception also). In my case this happened to me. Where i was not able to add a dynamic project to the tomcat server as the runtime environment. We can add the dynamic projects to run with the tomcat server from the left list box to right list box (if u can remember). Both the list boxes will just remain empty. And there will be no hint on whats exactly wrong. So i restored the localstore.rdf file and it started working again.

Hope this helped anyone. Dont want someone else to waste a day to solve this problem.

Accept or Ignore Self Signed Certificates While reading ssl web page using Java

January 18, 2010 by samindaw

Turns out this is quite easy to do but hard to find the code for it. So here it is.

TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
	public java.security.cert.X509Certificate[] getAcceptedIssuers() {
		return null;
	}

	public void checkClientTrusted(X509Certificate[] certs,
			String authType) {
	}

	public void checkServerTrusted(X509Certificate[] certs,
			String authType) {
	}
} };

// Install the all-trusting trust manager
SSLContext sc;
try {
	sc = SSLContext.getInstance("SSL");
	sc.init(null, trustAllCerts, new java.security.SecureRandom());
	HttpsURLConnection
			.setDefaultSSLSocketFactory(sc.getSocketFactory());

	// Create all-trusting host name verifier
	HostnameVerifier allHostsValid = new HostnameVerifier() {
		public boolean verify(String hostname, SSLSession session) {
			return true;
		}
	};
	HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (Exception e) {
	// TODO Auto-generated catch block
	e.printStackTrace();
}

So basically what the above manager does is that it creates a socketFactory with a trust manager which allows all certificates and sets that as the default socket factory. The 2nd part is to validate a hostname which is not really important unless you are working on a server side IMO.

Open or trigger eclipse wizard without using an extension point in eclipse

January 18, 2010 by samindaw
Display display = Display.getDefault();
display.asyncExec(new Runnable(){
   public void run() {
      RegistryBrowserWizard wizard = new RegistryBrowserWizard();
      WizardDialog dialog = new WizardDialog(new Shell(), wizard);
      dialog.create();
      dialog.open();
   }
});

Helpful links to understand: FAQ How do I get a Display instance?

Boycott Sri Lanka – Top 10 Reasons to Boycott

January 5, 2010 by samindaw

There is a site on the net called http://www.boycottsrilanka.com which requests everyone to refrain from buying Sri Lankan products. I’m not sure what they are trying to achieve by doing so, but if they succeed in their objective the end result

People loosing market => Financial Issues for People => People loosing jobs => Family financial and economical issues => Anger towards the people who caused them these problems => Formation of retaliation or revenge on their minds => Short-sighted will take the revenge on innocent ppl (these innocent ppl most probably might be tamils since the boycott effort is encouraged by a set of short-sighted tamils abroad) => the innocent will become no longer innocent => accusations, bloodshed will happen => some political ppl will take advantage of the situation and say mistreatement for tamil/sinhala ppl => ppl who follow these stupid politicians will get enraged and cause more harm => minority will suffer the most because of this => for political gain political nut heads will CREATE more and more arguments and clashes. => people start getting gravely injured or killed by mistake => Friends/relatives and political gainers will take advantage of the deaths to take direct revenge by murdering => in the end alot of sri lankans will die => Disregarding that all were sri lankans and that there were sinhala and muslim ppl among who died, the propagandist will announce that tamils in sri lanka is subjected to genocide => and here we go again…

Believe me, this is the start of the eelam war of prabakaran also even though the first seed was not a boycott. But a very small thing can create so much destruction to people of a country who are trying to unite.

If you’ve decided to boycott by any chance, just take a moment and think. Would the Sri Lankan government or people give an 1/3 of the country for a race of people who are less than 1/5 of the populations just because our products are boycott? We invite to share the whole 100% of the country rather than 33.3%. Thats a better bargain I say. If someone says tamil can have better rights and better life style if they had a different country, then why not just go to south india where you have more space all are tamil. if they insist on a part of sri lanka, then look at pakistan and india. pakistan got what they wanted more than 50 years ago, but still both pakistan and indian ppl are dieing not only on borders but within their countries too. Solution is never division. its combination.

Anyway my whole reason for writing this blog is to comment on the Top 10 reasons the “boycott srilanka” are advertising.

1. Sri Lanka is one of the top “red alert” countries at risk for genocide (Genocide Prevention Project)

Are you boycotting Pakistan, Afghanistan, Iraq, Somalia…. also? They are in that list also you know. I cant find http://www.boycottpakistan.com/ on the net. If you are truly against genocide then you should carry your mission to all countries mentioned in your link. Just out of curiosity, did you start your effort only after seen the above link? or is it just a link which you found helpful to put in your site?
2. Sri Lanka was voted off United Nations Humans Rights Council in 2008 (Asian Human Rights Council)

I have nothing to say about this because I haven’t much knowledge on how UN HRC operates.
3. Sri Lanka has a history of expelling UN and human rights monitors from the country (BBC)

As far as I know no UN and human rights monitors were expelled. But UN and human rights monitors violators were expelled. They should have done what they came to do. But I’m sorry if some of them were falsely accused which I’m sure may have happened for some and I agree that it is unacceptable. But that doesn’t mean you can human rights violations are happening in every corner of the country or only to a specific race of people. In every country there is human rights violations. You just dont see them because you don’t bother to look them up. Just like you dont bother to look up the sinhalese and muslims who suffered on the hands of LTTE.
4. Sri Lanka is ranked as having the 2nd highest rate of disappearances in the world (United Nations)

An old report about 8 years ago. Even it it were true, this is no longer credible for today. So the 4th point is useless and barely applicable.
5. Sri Lanka is one of the most dangerous places for journalists (BBC)

I think all the facts in the article states that it is dangerous for journalists who are collaborating with the LTTE. So the 5th point is INCOMPLETE?
6. Tamils treated as second-class citizens in own country: they must carry identification cards (United Nations)

This sentence tells me that the person who created it has never set foot on sri lanka atleast during my lifetime. We singalese also cant go anywhere without an ID card. so its a common thing for every one. And as for second class accusation, in political arena only the prime minister and president positions have never been held by a tamil. Once even the Chief of Police was a tamil, not for forget our famouse beloved forign minister late Luxman Kadiragamar. My former training place CEO was a tamil. I have pretty good friends who are tamil when I was at school (and they still are). I dont know the claims are for a specific location of the country, so far I’m unable to see anything which proves the above accusation.
7. Culture of impunity: despite pervasive human rights violations, very few are ever held accountable (International Press Freedom Mission)

This is due to dirty politics in Sri Lanka. Cant argue with this. All Sinhala, Tamil, Muslims suffer equally because of this. But I’ve seen dirtier political actions in US/UK.
8. 130,000 + civilians denied access to freedom of movement in internment camps (Human Rights Watch)

no longer applicable.
9. 20,000+ civilian casualties just at the end of the war alone (Guardian UK)

the total for 30 year war is close to 80,000. this includes sinhalese, tamils and muslims. So what was your point again?
10. Continued restrictions on humanitarian aid in IDP camps (Washington Post)

no longer applicable.

I think these 10 reasons are applicable for US.

Trying to start learning Eclipse GEF? Here’s the best documentations I’ve found so far.

January 4, 2010 by samindaw

If you are looking for good GEF documentation then the chances are you already know how good GEF might be as a plugin. So straightway to the point. These steps are for java developers cause using java models you can get the full potential of GEF.

My advice,

1. Try to understand the basic architecture behind the Eclipse GEF

2. Start following a tutorial for creating an graphical editor using GEF step by step

3. Mess around with the tutorial example editor you just created.

4. Reverse engineer the example to create a simple editor of your choice

5. Start creating your editor using GEF

6. Use google and use the GEF news forum for problems which you will definitely have.

7. Take a break every 30-40 classes.

Some references

1. http://wiki.eclipse.org/GEF_Description

2. http://www.eclipsecon.org/2008/?page=sub/&id=102

3. common sense

4. best way to dig in to something

5. good luck

6. http://www.eclipse.org/forums/index.php?t=thread&frm_id=81&

7. you’ll understand what I mean when you get to this step ;)

Saving/Retrieving the java object as/from xml string

November 19, 2009 by samindaw

Apparently this is extremely easy :) . I wanted to save an object in xml format in order to later recover the object. The coading involves only a couple of lines of code. Following is an example class I wrote on how to do that. As you can see I’ve included the xml encoding & decoding methods (toString() and the getMyObject()) inside the same class which of course can be done outside the class also.

package a.b.c;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

public class MyClass {
	private String name;
	private int age;
	private Map friends=new HashMap();

	public void setAge(int age) {this.age = age;}
	public int getAge() {return age;}
	public void setName(String name) {this.name = name;}
	public String getName() {return name;}
	public void setFriends(Map friends) {this.friends = friends;}
	public Map getFriends() {return friends;}

        // from here starts the xml encoding/decoding
	public String toString(){
	   StringOutputStream fos = new StringOutputStream();
           XMLEncoder xenc = new XMLEncoder(fos);
	   xenc.writeObject(this);
	   xenc.close();
           return fos.getString();
	}
	public static MyClass getMyClass(String xmlObjStr){
	   XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(xmlObjStr.getBytes()));
	   MyClass p = (MyClass)decoder.readObject();
	   decoder.close();
	   return p;
	}
	private class StringOutputStream extends OutputStream {
	  StringBuilder mBuf = new StringBuilder();
	  public void write(int bytes) throws IOException {mBuf.append((char) bytes);}
	  public String getString() {return mBuf.toString();}
	}
        // xml encoding/decoding ends
}

then by simply just calling toString() method of an object of above class you can get the xml representation of the object (save it to a file/database if u want) and recreate an object of the type by passing this xml to getMyClass() method.

Live Editing a Web Service or Making use of Axis2 Hotupdate feature in a cool way.

October 17, 2009 by samindaw

This is to inform that we now support the feature of making use of the hotupdate feature in axis2 web service feature.  Try this tutorial http://wso2.org/library/tutorials/live-edit-your-axis2-web-service-using-eclipse for more details. Basically it allows you to test your web service while you edit it. Really cool.

How to write a axis2 web service within seconds

October 9, 2009 by samindaw

It is literally within seconds, given that you already have the java class which you intend to make it a web service.  Here’s the link http://wso2.org/library/tutorials/create-axis2-web-service-3-steps-using-eclipse. Will write a web service  which would be more close to a real world scenario next time. Any thoughts of improvement is welcome.

How to write a web service client with just 3 steps

October 9, 2009 by samindaw

I recently wrote an I article to WSO2 OT regarding creating a client to consume or should I say access a web service. Didn’t explain a complex scenario though. Only showed the simple case of accessing a Web Service. This is the link to access the tutorial http://wso2.org/library/tutorials/creating-web-service-client-3-steps-using-eclipse. Thinking of writing a tutorial with a more complex scenario of handling security or binary uploads/downloads.

තල මල පිපිලා – Thala Mala Pipila

September 15, 2009 by samindaw

I think it was about more than 10 years ago when I last watched a stage drama. And that was මනමේ (maname), back when I was in school. Before that it was a stage drama called කැඩපත (kadapatha) – I barely remember that one. Even though I wasn’t dyeing to see another one, I always wanted to go watch a stage drama just for a change to all the big screen (wide-screen, lcd screen, television screen) movies. After missing several opportunity I finally got a chance to watch the famous stage artist Jayalath Manoratnes (ජයලත් මනෝරත්නයන්) thala mala pipila (තල මල පිපිලා) stage drama today.

When the drama started I was captured by the strange lighting that was made in the stage focussing the attention on a person wearing on a robot costume. Eventhough the constume wasn’t good enough to pass for a real robot, it made me feel that we are about to enter to a strange world. I sat up straighter on my chair. The year it said was 4000 AD. It explains that they no longer pocess anything called tradition (සම්ප්‍රදාය) or emotions (හැඟීම්) but there were a species called humans millenniums ago who did have it. The robot wanted to share one such historical scene with us. It was one of the wierdest way of stepping in to a story, but nonetheless the surrounding the lighting and the synthesized voice made it very interesting.

The story starts up from that point onwards, and I wont explain what the story is, because I would probably ruine the greateness of such an artistic creation just by trying to make you imagine what it was like. But I must say the attention to the details, the lighting, the music, the hilarity and the magnificent performance of the stage actors did not stir me even anything close to bordem. It kept us interested right until to the end.

Now I’m officially a sri lankan stage drama fan :)

Why did the war in SL went on for more than 20 years?

September 15, 2009 by samindaw

This is not entirely accurate, but close enough analogue. Found on the internet.

The 8 Monkeys

(This is reportedly based on an actual experiment conducted in the U.K.)

Put eight monkeys in a room. In the middle of the room is a ladder, leading to a bunch of bananas hanging from a hook on the ceiling.
Each time a monkey tries to climb the ladder, all the monkeys are sprayed with ice water, which makes them miserable. Soon enough, whenever a monkey attempts to climb the ladder, all of the other monkeys, not wanting to be sprayed, set upon him and beat him up. Soon, none of the eight monkeys ever attempts to climb the ladder.
One of the original monkeys is then removed, and a new monkey is put in the room. Seeing the bananas and the ladder, he wonders why none of the other monkeys are doing the obvious.  But undaunted, he immediately begins to climb the ladder.
All the other monkeys fall upon him and beat him silly. He has no idea why.

However, he no longer attempts to climb the ladder.
A second original monkey is removed and replaced. The newcomer again attempts to climb the ladder, but all the other monkeys hammer the crap out of him.

This includes the previous new monkey, who, grateful that he’s not on the receiving end this time, participates in the beating because all the other monkeys are doing it.  However, he has no idea why he’s attacking the new monkey.
One by one, all the original monkeys are replaced. Eight new monkeys are now in the room. None of them have ever been sprayed by ice water. None of them attempt to climb the ladder. All of them will enthusiastically beat up any new monkey who tries, without having any idea why.