Friday, January 9, 2009

Errors when using Struts 1.3.x that are not intuitive javax.servlet.ServletException: org/apache/commons/lang/UnhandledException

Today, I decided to upgrade a new application that I was working on to Struts 1.3.10. After getting the necessary jars and stuff from the struts-blank.war, and upgrading my webapp library with those, everything was fine until I ran into this error. Apparently, Struts 1.3.x removed some jars from the distribution, and the dependecies had to be resolved externally. The error gave me no clue that it was unable to find the commons-lang.jar. After struggling with it for sometime, I finally figured out that the commons-lang.jar was the missing jar. Usually when a jar is missing we get a NoClassDefFoundError that points in the right way, but the error trace for this gave no clue at all. Anyways if you happen to run into this error the key is to have the commons-lang.jar in your classpath from this location Apache Commons


2009-01-09 17:30:34,001 ERROR InsertTag$InsertHandler.doEndTag - ServletException in '/pages-bdb/batchListDetail.jsp': org/apache/commons/lang/UnhandledException
javax.servlet.ServletException: org/apache/commons/lang/UnhandledException
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:244)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:590)
at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:510)
at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:966)
at org.apache.jasper.runtime.PageContextImpl.doInclude(PageContextImpl.java:610)
at org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.java:604)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:129)
at org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:152)
at org.apache.struts.tiles.taglib.InsertTag.doInclude(InsertTag.java:764)
at org.apache.struts.tiles.taglib.InsertTag$InsertHandler.doEndTag(InsertTag.java:896)
at org.apache.struts.tiles.taglib.InsertTag.doEndTag(InsertTag.java:465)
at org.apache.jsp.pages.shared.template_jsp._jspx_meth_tiles_insert_2(template_jsp.java:173)
at org.apache.jsp.pages.shared.template_jsp._jspService(template_jsp.java:92)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:704)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:474)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:409)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1083)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:295)
at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:271)
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:332)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

Wednesday, December 31, 2008

The Best Things in Life are always Free

Well, probably they are always not. But these days, information is. If you truly have the passion and drive to learn something, then the opportunities today are wide ranged thanks to Internet.

MIT Open courseware gives everyone an opportunity to experience the standard of its courses from previous semesters. Some of them might be outdated with respect to changes in technology but many core courses are usually not. Here is a link to MIT Open Courseware

Other universities offering free online courses that I have come across are below:

Carnegie Melon
Stanford
Tufts
UC Berkley
Utah State University OpenCourseWare
Johns Hopkins OCW
Notre Dame
Yale

To find courses available from several countries, use Open course ware consortium

If you are interested in a specific course use OCWFinder to find all the options that you have. Good luck.

Sunday, November 9, 2008

Notes/Thoughts from an accident

1. Life is too short. A minute or even a second could decide if you will see the next moment..
2. Live every moment of the life as if it is your last moment in your life. You never know what might come up in the next moment.
3. Nothing is permanent. You might not live to think about what you could have accomplished with your life. Spend at least 2-5 mins a day thinking what the day has meant to you, if you were given a chance to re-live the same day, what would you have done differently, and then try to implement that difference in the next day
4. Working out, looking good, trying to impress people don't have much to do when your moment arrives. It doesn't matter. Nothing matters actually.
5. If in each day, you could do something that would make you feel better as a person, as a human being, do it, you can find excuses to tell others, but there is no excuse from your conscience.
6. Procrastination could really be dangerous. If there is something that needs to be done, do it now or else have a fixed plan to do it on a particular day by a particular time. If its a big project split it into pieces and have a fixed time for completing each piece.
7. Before complaining about a thousand things that happened to you today, stop for a moment and be thankful for the fact that you are alive, you lived to see another day in your life, you got one more day to prove your essence in the world, whether you utilized it in the right way is a different story.
8. Have a fixed set of things that you really want to do in your life. Give them fixed years. do a bucket list for yourself and assign importance to them. For example, By 30, I want to own a BMW etc. Work out an exact plan how you would do it, day dreaming won't work, have an exact plan within the means..
9. When a moment can decide your life, live it up, live every minute part of a moment..

Friday, November 7, 2008

Oracle SQL group by on a portion of a clob field in the database

I work on an application which writes its internal errors in processing to a DB table. The input data that caused the failure due to a parsing error or missing configuration error is put in a clob column in the database. This input data is an XML message and one of the tags identifies each application that sends data to my application. We had one of the architects who requested us to give a split up on the number of errors that have occurred for each application.

This was significant from Oracle perspective because you cannot do a group by on a clob. In order to do a group by, you need to be able to sort and clob fields do not have a natural sort order. The workaround is to do a to_char function on the clob field but you can get a max of 4000 chars. For me, this suited the requirement because the substring I needed was a small string. But the issue is that I needed to sort a portion of an XML tag inside the clob field and group them based on that. Not only that I needed to find a specific type of error in the XML message and count them.

After a little food for thought, here is the final query that fetched the sweet results


SELECT k.application_name, COUNT (*)
FROM (SELECT TO_CHAR
(SUBSTR (clobfield,
( INSTR (clobfield,
'ns0:appName',
1,
1
)
+ 21
),
( INSTR (clobfield,
'lt;/ns0:appName',
1,
1
)
- INSTR (clobfield,
'ns0:appName',
1,
1
)
- 22
)
)
) AS application_name
FROM tableName
WHERE appID = 1
AND INSTR (clobfield, 'ns0:appName', 1, 1) <> 0
AND INSTR (clobfield, 'ErrorMsg', 1, 1) <> 0
AND INSTR (clobfield, 'Application Not Configured', 1, 1) <> 0) k
GROUP BY k.application_name


The INSTR function selects the index of the occurrence of a string inside another string, while substr gets the substring from a string. The numbers 21 and 22 account for the tag name lengths and the additional characters in the tag name like > etc.

If you need to count based a specific portion of a clob, just modify the above query and you are good to go..

Wednesday, September 3, 2008

Lifestyle savings etc. a nice comment from an enlightened person

Lately, thoughts have been springing into my mind as to what I should save for, what my real goals in life are, etc. I was navigating through some links and landed on this post about Lifestyle inflation. More than the post, this comment from Ron made a lot of sense. He sure must be an enlightened person. With his kind permission (haven't received it yet, since I have no way of communicating except leaving a comment on the same blog), I publish it here for my future reference and for any readers. I hope to emulate him some day..

----------------------------------------------------------------------------------

Some very interesting comments and I see everyone is very committed to saving…but I wonder for what? What are you saving for, why do you want to earn more money? I am not being facetious; I really want to know the reason behind your efforts.

One of the seven habits: Begin with the end in mind. I see the blogger has a goal of a million dollar net worth…same question…why? What will having that net worth accomplish? And what are you measuring? And what is the nature of the net worth you are after, specifically?

I mean, do you want a million in equity (say, in real estate) or a million in the bank earning 5%? Two totally different scenarios.

Many people fixate on some number but it is often like leaning the ladder of success against the wrong wall. My clients come to me with that same idea sometimes; that is, to grow their net worth to some magic number as if it will resolve their financial issues somehow.

Look, as a goal I guess a million is as good as any but, really, if you are saving just to reach a number…what is the life you want? What would an ideal day look like, feel like?

Money is a tool…but for what? To build the life you want, IMO. So isn’t that the real goal? What is the life you want and, now, break that up into pieces and cost those pieces out:

The house I want: $x
The car I want: $x
Number of kids: $x

So on and so forth. Then you add that all up and you will have a bottom line and that is your real goal.

I wanted a small but comfortable home in a safe neighborhood and a five year old car that I would keep for five years and then sell and start over. Cost for that: $1,000 a month where I live. Plus expenses: Another $1000 a month.

My savings earn me $15,000 a year ($300K at 5%) and the rest I earn working three days a week doing what I really enjoy doing and what I would do for free if I could afford to do so. And I also manage to save some of what I earn so my savings are growing, as well.

I am married and we have a daughter and we look for all the world like a typical middle-class family. But we pay for it all with 24 hours of work a week; meanwhile both spouses work in all the other houses on the block.

We are not better or smarter, we were just able to decide what we wanted, price it out, and fund it with just enough work to get the REAL job accomplished (the life we wanted). Four day weekends are great!

Good luck!

-----------------------------------------------------------------------------------

Thursday, August 7, 2008

Log4j writing to a dynamic log file for every run

In my recent project, I was using Log4J and I had a requirement where I had to write to a new dynamic log file every time and the name of the log file was determined at runtime. In specific terms each run would produce a Project and the log file had to reflect the project name. Since this project name could be repeated across runs, the timestamp needed to be added to the log file. I searched across Google and didn't find much help in this regard. So I decided to post the code I wrote.

I didn't want to lose setting the log levels from the log4j.xml file and wanted all the options I could configure for the FileAppender except the file name. The file name was configured too, but the code had to overwrite and create a new file at runtime. Here is the code..



Date projDate = new Date(Long.parseLong(project.getTimeStamp()));
StringBuffer dateStr = new StringBuffer();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
dateStr = sdf.format(projDate, dateStr, new FieldPosition(0));
String logFileName = logsDir + File.separator + project.getName() + "_" + dateStr.toString() + ".log";
log.info("\n**************Log file for this run: " + logFileName + "\n**************\n");

Logger rootLogger = Logger.getRootLogger();
Enumeration appenders = rootLogger.getAllAppenders();
FileAppender fa = null;
while(appenders.hasMoreElements())
{
Appender currAppender = (Appender) appenders.nextElement();
if(currAppender instanceof FileAppender)
{
fa = (FileAppender) currAppender;
}
}
if(fa != null)
{
fa.setFile(logFileName);
fa.activateOptions();
}
else
{
log.info("No File Appender found");
}



That's it. The logs were created for each and parallel runs would write to different files...

Friday, July 18, 2008

Totally Annoyed with Toyota of Plano service guys

I went to Toyota of Plano and was pretty annoyed with their service department and this Chris guy who was upset that I didnt get the Dealer recommended maintenance for $300 and got just the factory recommended one. Here is the story..

I needed a 15000 mile maintenance for my car and I called up the Toyota of Plano guys and asked how much it would cost. The guy on the phone said it costs me $335 or so. I was indeed surprised at such high amount and checked the Toyota website. All the Toyota recommends for my car is the following. (Source)

Replace engine oil and oil filter 1
Rotate tires
Clean cabin air filter
Visually inspect brake linings/drums and brake pads/discs
Inspect the following:
Ball joints and dust covers
Brake lines and hoses
Drive shaft boots
Engine coolant 3
Exhaust pipes and mountings
Steering gear box

I then asked this service dept. guy if it was the factory recommended one or the Dealer recommended one. He said it was dealer recommended one and he went on to list a bunch of things they would do. He said they were very important for the car. The only question I had in my mind was if all those were so important for the car then why wouldn't Toyota recommend that. But I didnt ask him that and asked him how much would the factory recommended one cost me. He says $93.20. He said I could come in and talk to some Chris guy who would take care of it. I say okay and start out to get one.

I go there and wait for my turn and then some guy comes in and fills my request form. I mentioned clearly I needed 15k facory recommended maintenance and asked him how much it would cost. He said, oh it costs 80 bucks and notes 80 on the sheet. I say okay and ask are you Chris. He is like, no, that guy right there is Chris, I will fill it and keep it on Chris' desk so he can take care of it. I say okay and then leave my car and wait. After an hour or so, Chris guy comes and tells me its ready. I say okay and go to pay the bill. The lady at the counter says $85 and some change. I asked her if I could get a sheet that describes what all has been done and she shows me a billing list which doesnt contain most of those listed above. I asked if they have been done at all and like to see the detailed list and she tells me, Oh ask Chris and he will have the checklist that they check the boxes when they perform the inspections and all. I say okay, pay my bill and walk out to Chris.

I ask this Chris guy if I could get a detailed list, he is like, wait and he says, If you got a dealer recommended one, I would have the list, and then he answers his cell phone, and then says it would be in the maintenance guide you have in the car, and then brings me a list that has the above checked. And then he goes on, "See you just have tire rotation and oil change, there is no wheel balancing and all done because you took a factory recommended one and not a dealer recommended one", and I say, "Okay, so what difference does it make". He says "Oh you will not know that now, after a few miles when you hit 70 miles per hour and your wheels start vibrating then you will notice." I never knew thats a way to talk to a customer and in such derogatory tone. I got really pissed off and asked him, "So if its gonna affect my car and all, why doesnt Toyota recommend whatever your dealership is recommending. And he says "Look man, I am just trying to help you.." Great way to escape without an answer.

The checklist that he gave me says the service is $93.20 and I show it to him and ask if it costs $93.20 then how come, I was charged only $85 and change and he says, ya its lesser than that right. I say, of course, but I am just curious why the difference. And he says, the guy who talked to you put 85 on the paper (he had actually put 80 but may be taxes is 5), so I had to give it to you for 85. This was totally ridiculous. I dont know if they have a pricing system at all, some guy says its 80 to me and so he says he gave it to me 85 instead of 93. The difference might be a few dollars, but what I dont like is the fact that the same thing costs different amount to different people. So, you go to walmart and ask a rep what the price of a hdtv on a tv stand is. He mistakes the price of the tv stand to be that of TV and says 200, so now will Walmart give the TV to you for 50 bucks. Doesnt make sense to me at all..

And then I ask him, did you put the seal on my Toyota Passport guide, and he was like you didnt give it to me. The last two times, the service rep guys took care of it without me even asking them. I say, okay, let me get it for you, and then he walks with me to the car. I give him the booklet, and I say, I just need the signature and your seal and he goes "I know what I need to put in there, I have been doing this for some time". I wouldn't mind if he said that in a friendly way but he was outright rude. He goes, fills it up and comes back and I ask him, one last qn, is the blinking message on Dashboard that says "Maint Reqd" reset, and he says, it should have been, and guess what I start and the blinking is still present. And then he resets it and says, now it is reset. If I hadn't asked I needed to go back again for that.

I am totally surprised by the total inefficiency and the carelessness that they show towards the customers and the worst part is they are getting away with it. And I am also appalled at their discretionary variable pricing system. May be today was a bad day or I got the wrong guys, but in my opinion today, Thumbs down to Toyota of Plano...

Wednesday, July 16, 2008

Java: Loading an XML file from the CLASSPATH

Today, I faced this issue in Java coding. I needed to load an XML file which was in my classpath but not in the same directory as the classes. The deliverable was a jar and the properties and the configuration XML files were in a different folder and were appended to the classpath at the runtime. The issue was that the file could not be located through the the statement


String fileName = getClass.getSystemResource("config.xml").getFile;


Then I thought that it checks relative to the current class and so used the statement


String fileName = ClassLoader.getSystemResource("config.xml").getFile;


But then, it wouldn't still recognize the file. The reason is the same, it checks relative to the classes folder. I did not want to get the classpath from the system and browse through it for the config file since the class path could get larger. A couple of google searches and a little research later, I found the solution. The workaround is by using the following statement


String fileName = Thread.currentThread().getContextClassLoader().getResource("config.xml").getFile;


It only makes sense since in the above statement, you get hold of the context class loader and find the path in the entire classpath...

Wednesday, June 25, 2008

Dont ever say that you don't have enough time

Nice quote from Pravsworld



If you want to get inspired daily, subscribe to their email list. Its pretty cool :)

Wednesday, June 18, 2008

Mee Sreyobilashi - Suicide is not an option, so is giving up for an entrepreneur

Just watched the Telugu movie Mee Sreyobhilashi. Gist of the story. Around 10 people who are vexed with life and want to end it travel together in a bus to take the bus down to a valley and die together. Their journey to the realization of the value of life is the movie...

The movie spurred a bunch of thoughts. First of all, why should anyone commit a suicide. God has given us the life to live. Life is a challenge, we need to face it. If everyone starts ending their life due to some problems or the other, then what is the essence of life in itself. Death is just the absence of life, not an end to it. No problem on earth is big enough to force any one to death. People who are handicapped or have many other disabilities are living a happy life with tons of self-confidence. Why cant normal people do the same...

And then there is one more way of looking at the whole thing. If living the life symbolizes your dream of making it big, your dream of being a success, giving up symbolizes the death of a life, the death of an aspiration, the death of a hope.. A person never really is a failure until he gives up. One thing is for sure. Every one of us is going to die sooner or later. And that is one thing that we can never avoid. That is one thing we cannot run away from. Then whats the point of living life in an insipid manner. What is the point of giving up... Live life to the fullest and never give up... The day you give up is the day you fail, whether you give up your hopes or dreams or even your life... Dont quit your hopes, your aspirations, your life...