Friday, December 15, 2006

Version Confusion

I was working on a project that I took over from another developer who left the company I work for when one day I need to work on a bug located in different but related project.

I crank my Eclipse, package the project, deploy it to JBoss 4.0.4 and start debugging. Lo and behold I kept bumping into a strange and initially mysterious problem. This was what I kept bumping into:


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from
fulfilling this request.

exception

javax.servlet.ServletException: Servlet execution threw an exception
...
root cause

java.lang.NoSuchMethodError: org.apache.struts.util.RequestUtils.forwardURL(
Ljavax/servlet/http/HttpServletRequest;Lorg/apache/struts/config/ForwardConfig;
Lorg/apache/struts/config/ModuleConfig;)Ljava/lang/String;
...


The thing that surprised me was the fact that the application is in production and should pass this point of failure. I have yet to make any changes to it and I know I have the struts library with all the dependencies in there. I went into the war file and make sure I have them in there. I make sure the manifests define the proper classpaths. So what gives?

To cut the story short, after some checking and experimenting, it dawned on me the possibility that there may be a few conflicting struts.jar (something I initially ruled out). So I went to my current project(package into a different ear file, but deployed into the same server instance), check the libraries, peek to the version info... voila... lo and behold... sure enough that was the problem.

This project that I'm working on, the one I just inherited, uses an ancient version of struts (version 1.1 to be exact) This project, package and deployed along with the other package project (I have multiple ear files deployed, mind you) create such a confusion. The order the packages deployed, my current package with Struts 1.1 was deployed first and apparently got first inline in the classpath and created all these other problems. This is proven, because if I deployed them in different order, it will work. Apparantly because the newer struts.jar is first inline.

Moral of the story: If you have crazy exceptions in which you think you have everything right, go and check to see if you have jar files with different versions in your classpath.

Friday, October 20, 2006

Ant Uppercase Lowercase mystery

If you used Ant to build your project on Windows and ever had your supposedly uppercased directory name in your war file turned to lowercased directory name, here's the thing: it's not ant. It's winzip.

http://ant.apache.org/manual/CoreTasks/war.html

Here's the note from ant:
"We regulary receive bug reports that this task is creating the WEB-INF directory, and thus it is our fault your webapp doesn't work. The cause of these complaints lies in WinZip, which turns an all upper-case directory into an all lower case one in a fit of helpfulness. Please check that jar xvf yourwebapp.war shows the same behaviour before filing another report."

Monday, October 16, 2006

Google Code Search

If you want to search for code example that uses a specific code, google now has a tool to help searching for what you need. It's quite neat! http://www.google.com/codesearch
Mind you it will only search for public source code.

Try, for example a search on HelloWorld and see what you'll find.

Thursday, September 21, 2006

Java SE starting a features diet

Apparently Java SE will take on a slimming program. With new guidelines from JSR 270, Java SE 6 will start shedding some weight. First on it's way to the dumpster: javax.sound.midi, according to SD Times. Here's the link: http://www.sdtimes.com/article/story-20060915-04.html

I hope they move that into add-ons library. Sure the feature appetite need some control, but why not keep things which are already available as add-ons for those who may need it to maintain backwards compatibility?

Short intro to Ajax

What is AJAX?

Ajax in mythology was a Greek hero of the Trojan War. He was the son of Telamon, the king of Salamis as descibed in Homer's Iliad. He was one of two Trojan War heroes named Ajax. The other was Ajax the Lesser, Oilean Ajax, a Greek hero and legendary king of Locris.

But AJAX in relation to web technology is: Asynchronous JavaScript Technology and XML (AJAX)

AJAX is neither a new technology nor a new programming language, but rather a new way of using a composite of supportive technologies, mainly javascript and XML (hence AJAX) to create a more interactive and faster web applications.

The technology uses JavaScript to send and receive data between a web browser and a web server by using an XMLHttpRequest object to facilitate the exchange. Then, the next part of the process is having a callback method processes the data returned from the web server. This callback method is specified when the XMLHttpRequest object was setup prior to sending the request (xmlHttpReqObjectName.onreadystatechange = javascriptCallbackMethodName;.)

The data request can be made via a GET or POST. The rule of thumb is:
  1. If you're not changing the state of the server use get.
  2. Otherwise use POST.
And off-course things are not always that simple, there are always other consideration to be observed.

The slick thing about AJAX is that it makes the life of a web developer a little easier when all the developer needs is to update a small portion of the webpage in question. Instead of reposting everything, change a tiny bit of data and re-render everything - now, the developer can do that behind the scene: exchange data with the web server transparently and then use JavaScript to process the retrieved information and refresh the small block of information that need refreshing.

AJAX can be a tool for an elegant web solution, but like any other technology can be abused and overused to create a monstrous size of a mess.

Friday, May 12, 2006

WebLogic and Axis

Ever tried using Axis for webservices in WebLogic environment and have all sort of weird axis fault?

Well, I was using Axis 1.2.1 on WebLogic 8.1 sp5 and having this Axis fault. After trying to debug for a while, I finally went back to the Axis installation instruction and sure enough, there on the last part of step 2 I found my solution.

The information is there, on the Axis docs. It's knowing which one will bring you solution is another. You may think everything is alright and just wondering why Axis throwing faults when it should've been fine. The first thing to do in most cases is nail the basic first. Run HappyAxis and makesure everything is what it should. If everything is okay then you can move on to the next without having to worry about these basics without making mere assumptions.

My problem was as they said: "WebLogic 8.1 ships with webservices.jar that conflicts with Axis' saaj.jar and prevents Axis 1.2 from working right out of the box. This conflict exists because WebLogic uses an older definition of javax.xml.soap.* package from Java Web Services Developer Pack Version 1.0, whereas Axis uses a newer revision from J2EE 1.4."

The solution suggested was two options of configuration changes (http://ws.apache.org/axis/java/install.html):
  1. In a webapp containing Axis, set element in WEB-INF/weblogic.xml to true.
  2. In a script used to start WebLogic server, modify CLASSPATH property by placing Axis's saaj.jar library in front of WebLogic's webservices.jar.
In my case, option 1 for some reason wasn't too helpful. It was already set and the needed jar files are in the classpath. So I went for option 2, and making sure that the jar files needed are first in line.