Sunday, January 18, 2009

Change Voicemail number in iPhone

How to change Voicemail number in iPhone?

Call : *5005*86*123456789# where 123456789 is the number you want to call when you press the Voicemail button.

For example, you can set your Voicemail number to your own iPhone telephone number. When pressing it, you will always get a busy tone. Thus, this will prevent accidentally calling Voicemail number.

Credits : http://janandjanuary.multiply.com/journal/item/68/68

Sunday, January 11, 2009

Read Request Body in Filter

Is it possible to intercept HTTP Request in order to read HTTP Request Body (HTTP Request Payload) before it is served by target servlet or JSP?

The answer is yes. You can use Servlet Filter to read, "filter" or modify ServletRequest (HTTPServletRequest) object before the request object is sent to and serve by the final servlet.

What if I read a request body within a servlet filter, is the body still going to be available to be read again by the servlet, or can it be read only once?

Yes, but it is a little bit tricky.
Because of the fact that the request body can be read only once. If you read the body in a filter, the target servlet will not be able to re-read it and this will also cause IllegalStateException. You will need ServletRequestWrapper or its child: HttpServletRequestWrapper so that you can read HTTP request body and then the servlet can still read it later.

public class MyRequestWrapper extends HttpServletRequestWrapper {
private final String body;
public MyRequestWrapper(HttpServletRequest request) throws IOException {
super(request);
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;
try {
InputStream inputStream = request.getInputStream();
if (inputStream != null) {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
} else {
stringBuilder.append("");
}
} catch (IOException ex) {
throw ex;
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ex) {
throw ex;
}
}
}
body = stringBuilder.toString();
}

@Override
public ServletInputStream getInputStream() throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
ServletInputStream servletInputStream = new ServletInputStream() {
public int read() throws IOException {
return byteArrayInputStream.read();
}
};
return servletInputStream;
}

@Override
public BufferedReader getReader() throws IOException {
return new BufferedReader(new InputStreamReader(this.getInputStream()));
}

public String getBody() {
return this.body;
}
}

The first step is to create a class that extends HttpServletRequestWrapper. Then, use the constructor to read HTTP Request body and store it in "body" variable. The final step is to override getInputStream() and getReader() so that the final servlet can read HTTP Request Body without causing IllegalStateException.

Here's how to use RequestWrapper in the filter.

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {

Throwable problem = null;

MyRequestWrapper myRequestWrapper = new MyRequestWrapper((HttpServletRequest) request);

String body = myRequestWrapper.getBody();
String clientIP = myRequestWrapper.getRemoteHost();
int clientPort = request.getRemotePort();
String uri = myRequestWrapper.getRequestURI();

System.out.println(body);
System.out.println(clientIP);
System.out.println(clientPort);
System.out.println(uri);

chain.doFilter(myRequestWrapper, response);
}

IBM ASEAN dW Game Challenge




IBM ASEAN dW Game Challenge (IBM ASEAN DeveloperWorks Game Challenge) is a maze-quiz game sponsored by IBM. During the game, you will need to navigate King Darwin out of the maze and to his castle. If you encounter a yellow box, you will need to answer an IT-related multiple-choice question in which its answer can be found on IBM developerWorks website. Once answer correctly, you will gain 300 points. If you answer it wrong, you will lose 150 points. When you start the game, you will have 3000 points. Each seconds during the play, except when you are attempting to answer each question, will cost 1 point.

This is the official rules and description from the website:

About the Game

King Darwin is trapped in a maze and needs to find his way back to the dW Castle. Your challenge is to help him out in the shortest time possible, through pushing of crates and tackling of quiz questions whereby answers can be found within the IBM developerWorks portal.

So are you up to the ASEAN dW Game Challenge? Play the game now to find out!


How to Play

Your task is to help King Darwin maneuver through the maze by pushing crates out of his way. There will be metal boxes along the way that cannot be moved.
You are required to answer a multiple-choice quiz question whenever King Darwin steps on a glowing golden tile, which could be exposed or hidden under the crates.
Answers to the quiz questions can be found within the IBM developerWorks portal. A hint will be provided for each question.


Scoring System

You will own 3000 gold coins at the start of each game, whereby 1 gold coin represents 1 second.
The timer will be activated once you start the game and one gold coin will drop for each second that passes.
The timer will be paused when King Darwin steps on a glowing golden tile and you are prompted to answer a quiz question. The timer will resume upon submission of your answer to the quiz question.
If a quiz question is answered correctly, the bonus will be an addition of 300 gold coins to your total number of gold coins at that point of time.
If a quiz question is answered incorrectly, the penalty will be a deduction of 150 gold coins from your total number of gold coins at that point of time.
The objective of the game is to collect the most number of gold coins at the end of the game.
You can play the game multiple times and submit your best scores with your personal information for a chance to be one of our top 3 winners.

The top 3 winners at the ASEAN level will be awarded with the following prizes.



The ASEAN dW Game Challenge was opened till 31 December 2008.

I played the game and as of December 31, 2008, luckily, I am the first place. Until final announcement, I hope it won't change.
:)

Sunday, January 4, 2009

Most Popular Search Terms on Google in 2008

Google has published most poppular search terms in 2008 on Google Zeitgeist 2008. According to dictionary.com, Zeitgeist means
the spirit of the time; general trend of thought or feeling characteristic of a particular period of time
It is pronounced like "sai-gai".

Google Zeitgeist 2008 published many interesting stats. Here is one of them.

During April-July, the gas around the world was the most expensive ever in the history. From the graph we can conclude that people are interested in seeking for alternative energy source: solar, energy efficient cars and lamps (cfl : Compact fluorescent lamp). As the price dropped, trends started to fade away for hybrid car and solar panel probably because hybrid car is quite expensive nowadays and building solar panels on house roof can be troublesome. And, the most easiest way to save energy cost in the house, without the need to spend too much time and money, is to change your light bulb into a more energy efficient one.