Sunday, March 7, 2010

Using Google Code as a SVN repository

Although Google is branded as a searching company, now it has come into every corner of IT world. I just realized that without Google, I will be kind of in a situation that cannot live comfortable any more.  Using Gmail to send and receive mails, using Google Docs to create, edit and share documents, using Google Calendar to arrange weekly and daily schedule, using Google Reader to read the latest information and news around, using Google Map to discover and explore neighborhood and destinations, using Google Buzz and Wave to socialize, and more importantly for me, using Google App Engine to earn money.

Recently, I have a thought to take participant in the open-source world, as a result the first thing came into my mind is to create some small project on the Google Code, which is previously dominated by SourceForge. After some attempting, I have constructed a very small project with the name of "restfulhttpclient". It is written in Java, with the IDE of Netbeans 6.8. Consequently, the checking out code will in the structure in Netbeans.

It is not difficult to adopt Google Code as SVN repository, since it provides the most basic functions to host code, and once you have an account and create a project there, you just need simply using your familiar SVN client to commit and check out your code.

However, I do have some questions here, the one that confused me most is that why should I name my project in all lowercase characters. Some one may argue it will be easier for lowercase letters to display in the address URI and for people to type in, but I believe a simple mapping and checking mechanism will not be that hard.

Another thing is actually for each of the project, there are two different URIs mapping to this project. One in the format of ***.googlecode.com, and the other is code.google.com/p/***. Whenever you try to upload your file, it is better to choose the first one, since the latter one will give you a 400 bad request response.

All right, if you have some interest, try to download my project in a while ( not finished yet).

http://code.google.com/p/restfulhttpclient



The reason why it is called restful http client is simply because of I have to use those basic functions as work. As developing a project full of Restful web services, invoking a http request will be the most common task. A handy GUI tool will be really nice if it can covers those most usual functions. Even a lot of similar products are out there, I cannot find one that most suits me. Either some of them have too many capabilities that made them extremely difficult to master, or some just ignores certain part of the function that I have to use. In this project, users can send GET, POST, PUT and DELETE request to server, you can add specific headers, and basic authentication informations. The response code and message will also be displayed on the panel once received by the client.

Sunday, December 20, 2009

Reading List

I'm going to read these two books in the coming weeks until the next vacation, and going to write any ideas and thoughts during the reading. Hopefully this way can force me to have reading tasks more regularly and more frequently.

Book 1. Learning Python, Mark Lutz and David Ascher, O'Reilly

Book 2. Beginning Unix, Paul Love, Joe Merlino, Jeremy C. Reed, Craig Zimmerman, Paul Weinstein, Wrox

Sunday, December 13, 2009

Get Request Header in Restlet

When using Restlet library to invoke RESTful method, sometimes you need to parse the request header for further use. And luckily, though there is explicit ways to solve this problem, we can still get what we need.

Calling getRequestAttributes().get("org.restlet.http.headers"); will return all the headers in the request. However, the type of returned result is "org.restlet.data.Form". Consequently, we need to convert it into the Form format, and then using the getFirstValue("") method to retrieve the value. One catch there is the key is always start with capital letter, for instant even is "location" in the header, you have to use "Location" instead.

Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
location = headers.getFirstValue("Location");

Wednesday, December 9, 2009

Solve the annoyance with Eclipse Access Restriction

Sometimes, you may encounter a problem like this:
is not accessible due to restriction on required library /usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/rt.jar.

After several times checking, there is no reason to properly explain and your program gets to stuck since no compilation is allowed when error existed.

One way to work around this issue is by resetting the configuration in the Eclipse project properties. Right click the project name, get into its properties and the Java compiler tab. There is an Errors/Warnings line listing there, select it, and update the Forbidden Reference (access rules) into Warning in the Deprecated and restricted API. Then rebuild the project, and problem solved.

Similar errors can be handled in the same way.

Monday, December 7, 2009

How to invoke a remote web service in GAE

Well, with GAE it is easy to develop applications on the cloud. But various limitations sometimes make people feel really uncomfortable when their usual behavior being considered as illegal according to the Google Laws.

You are not allowed to use any library related to .net package which may possibly generate more threads. But in order to make any invocation of other RESTful web services, we need to do something to both satisfy the requirement of Google and us.

In the official document, GAE recommends to use the HttpURLConnection class, which is a little bit too simpler to use, which means it brings various problems when dealing with complicated data types.

Here I will invoke a remote RESTful web service which will accept the format of JSON. Here is the code:

try {
URL url = new URL("http://localhost:8183/users/" +user+"/content");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
String json = content.toJSON().toString();
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(json);
writer.close();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
System.out.println("sssssss");
} else {
System.out.println(connection.getResponseMessage());
System.out.println("ffffffff");
}
} catch (Exception e) {
e.printStackTrace();
}

Looks easy, ha, yep, quite straightforward. Remember to add those content-type in the connection for the receiver to recognize the format you are sending. While you are only allowed to send String or Char[], so hurry up and write your own parsing functions.

Sunday, November 1, 2009

Kick off my new career path

It's the first day that I work in Australia, and also in the uni. Currently I have two titles, one is a master student who is going to graduate later this year, and another is a casual research assistant in the department of cs. At this moment, I am really happy to have a perfect environment to start with my career, and also thanks to my "boss" James giving me infinite help on my first day.

Anyway, I have never try to use Linux before, and after one day living with Ubuntu, I guess in the future I might be a big fan of the Linux family although Win7 has just come out of the water. I prefer this feeling with professional study and work, and I'm more happy to get payed by this.

I'm going to write more in this blog to record my working life in Melbourne, and also some technique skills or tips or summaries as I walk through this project.

Wednesday, July 8, 2009

Download All Mails to Client Mail Box

After re-install my computer, I lost all the mail information. While I was a little unsatisfied with the character encoding with Foxmail, I decided to take a try with Thunderbird, which originally I found from Lars.

It is a great application with email receiving and sending. However, two problems blocks me a little while for configuration. One is each time you close the box, it will really exit but not minimize to the system tray. Actually this is pretty annoying that at first I just feel strange how can I not receiving any mails for half a day. OK, so what you need to do is download a plug-in to enable the minimize ability. Just Google it and you will definitely find it.

Another serious problem is I can only download those unread emails from GMail which always affects my working when I try to fetch those old mails. At first I thought it is a problem with the configuration of Thunderbird, and finally I figured out I owe an apology to Thunderbird. Yep, it is just one single click on the setting with GMail.

Log into your GMail account, in the setting panel and Forwarding and POP/IMAP tab,  you will see a POP Download option, select it to enable POP for all mails, then start your client to receive. Done.

I guess this solution will be suitable for all kinds of client applications.