Friday, October 31, 2008

XML-RPC vs. SOAP vs. REST thoughts and Spring Beans

Recently I am working on the remote API side of my project, and the protocol that we chose is XML-RPC. Somewhere in two blogs returned by Google search suggested that REST > XML-RPC > SOAP. SOAP can only be considered for its wide enterprise adoption and protocol stack (with security management, transaction control, etc.) and therefore it is complicated. Yes, the person created XML-RPC wasn't an expert in XML but it's neat.

Why not REST then? I used to work on design and technical issues of Mule ESB and I was exposed to REST of its sweetness (the simplicity, the CRUD stuff) before more people started to talk about it (now they talk about Cloud). I learned that SOAP is for SOA (Service Oriented Architecture) and REST is for ROA (Resource Oriented Architecture). They are two different paradigms, and the purpose and design of these layers are therefore different, e.g. you don't carry a service/RPC mindset when you create a REST API.

So, no REST for now as IMO it requires more effort to design a proper API. Never I'll create SOAP due to its complexity.

What about JSON-RPC? I had a short discussion regarding this with @ditesh at #myoss@irc.freenode.net. I love JSON for its interoperability and speed (vs. XML parsing). But the available implementations turned me off pretty quickly, most of them stuck in year 2005~2007. For a publicly available remote API, a well-adopted and "mature" protocol is a much better choice.

What about the Spring beans stuff mentioned in the topic? I found the Apache XML-RPC server can't be integrated with Spring naturally (it has but not enough of bean property methods) and the API is quite ugly, e.g. XmlRpcSystemImpl.addSystemHandler() takes a PropertyHandlerMapping, why not XmlRpcListableHandlerMapping?

I took a similar approach suggested by Tomas Salfischberger in his blog and here they are:
  • An implementation of Spring's AbstractController.
  • An extension of PropertyHandlerMapping, this bean is used by the previous.

public class MyXmlRpcController extends AbstractController {
private XmlRpcServletServer server = new XmlRpcServletServer();
private boolean introspectionEnabled = false;

@Override
protected void initServletContext(ServletContext servletContext) {
super.initServletContext(servletContext);
if (this.introspectionEnabled) {
try {
XmlRpcSystemImpl.addSystemHandler((PropertyHandlerMapping) this.server.getHandlerMapping());
} catch (Exception e) {
}
}
}
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
this.server.execute(request, response);
return null;
}
@Required
public void setHandlerMapping(XmlRpcHandlerMapping serverHandlerMapping) {
this.server.setHandlerMapping(serverHandlerMapping);
}
public void setIntrospectionEnabled(boolean introspectionEnabled) {
this.introspectionEnabled = introspectionEnabled;
}
}

public class MyXmlRpcHandlerMapping extends PropertyHandlerMapping {
private Map serviceMap;

public void init() throws XmlRpcException {
this.load(Thread.currentThread().getContextClassLoader(), serviceMap);
}
@Required
public void setServicesMapping(Map serviceMap) {
this.serviceMap = serviceMap;
}
}


<bean id="xmlRpcHandlerMapping" class="my.MyXmlRpcHandlerMapping" init-method="init">
<property name="servicesMapping">
<map>
<entry key="membershipService" value="my.service.XmlRpcMembershipService"></entry>
</map>
</property>
</bean>
<bean id="urlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>/xmlrpc=xmlRpcController</value>
</property>
</bean>
<bean id="xmlRpcController" class="my.MyXmlRpcController">
<property name="handlerMapping" ref="xmlRpcHandlerMapping"></property>
<property name="introspectionEnabled" value="true"></property>
</bean>


- yc

Friday, October 17, 2008

The guys behind the new Maybank2U, please read

Epic fail! For the past few days, I had been hearing people ranting about the new site in Twitter, Facebook and my IM.

I haven't been using my Maybank account (basically abandoning it unless there's a need to M2U to some friends for convenience sake, oh.. and, it has more ATM machines than HSBC that is true) for the past 2 months ever since I changed my job.

As I am NOW doing some book keeping, as well as to experience the pain others are suffering, I convinced myself to log into the site. Clicking on "Transaction History", the cool Ajaxy waiting icon appeared and.. woohoo, a few 10 seconds later:

Ah, ArrayIndexOutOfBoundsException, caused by a JSP tag. I don't want to know what else they're doing with Struts and in the JSP, but surely, these guys wrote some shit to make almost every customer suffers.

- yc

Monday, October 13, 2008

I love Java

Love? Love comes with struggles, frustrations, hate; it's unconditional. There's this "I Love *" meme initiated by the folks at foss.my and in supporting of it and to show my love to the programming language and its community:



I love Java for how advanced it is, for the standards (see JCP and JSRs) that have been defined, for the other languages that you can run on top of it, for its rich frameworks and libraries, ...

I hate Java, for the same reasons too. :)

Note: The Sun's Java Virtual Machine (runtime) is called HotSpot. It is released under GPL, it wasn't.. before November 2006. Here is a list of JVM implementations.

- yc

Saturday, October 4, 2008

Let's complain about the local taxi service!

In a yumcha session last week, my friends told me that the taxi service in our country has recently been rated as the worst in the region. This morning, one of my friends shared this article in Facebook, which is on the same topic.

The past 2 months, I have been driving frequently than I ever had before. I hate (hated, hate still) driving because it adds one more car to the already-busy traffic, it pollutes the environment, it causes fuel depletion too. For these reasons, I always took taxi last time (for years), because I didn't travel much.. I didn't feel the pain although I ranted about it sometimes.

What're the problems? Two problems:
  1. The taxi drivers never use the meter if you're traveling from one town to another. Say, Setapak to Mid Valley, Chow Kit to One Utama, KLCC to anywhere, etc.
  2. Most Malaysians do not queue (esp. couples), I usually shout to stop them from taking my taxi.
I drive because I travel far these days and I got enough of being ripped off by the taxi drivers. But that doesn't solve the problem I faced and other people are facing. So, inspired by OpenMalaysia's Yoon Kit, I decided to lodge a complain to the ministry of domestic trade and consumer affairs.

Please join me:

The local taxi service has gotten out of control to the extent that we are now rated as the worst country in taxi service provision in the region. We're also featured in the MSN Singapore News<http://news.sg.msn.com/lifestyle/article.aspx?cp-documentid=1682889> too.

I am a residence of Kuala Lumpur and the situation has become worse to me these days as I have to travel frequently than I ever had to, to/from Mid Valley, 1 Utama, KLCC, etc.

The taxi drivers never follow the meter, every time I travel to/from these places, I have to bargain for a good price in order to get into the cab. At the first place, it is so wrong for them to break the rules, secondly, it has made me to look like a an idiot for so many times by walking from one taxi to another. There was once in Mid Valley that I had to try seven taxis.

Another issue is that, most general passengers do not use the queue and taxi drivers just stop their car before the station when someone waves their hand at another end.

Can someone do something about it? It's not just hurting the local consumers, it's also tarnishing the image of our country because tourists don't really love it too.

Act now!

From @yoonkit: @yclian you may need to name specific taxi companies and events, otherwise they won't know how to react.

- yc