Friday, January 09, 2009

Oh! Dash it...

I spent half a day cursing and spewing bile at JavaScript when after all was said and done, it was doing the right thing. The ignominy of it all...My writing here is part penance for casting aspersion at JavaScript and part hoping that you don't have to go through this agony.

I have a typical Java Server Page (JSP) with its share of HTML, scriptlets (gasp) and JavaScript. Much of the HTML is neatly organized in <div> tags. The JavaScript controlled the toggling the visibility of some of the divs.

When I tested the page and invoked the script, I didn't see the expected behavior. Firebug even told me that there was an error when the JavaScript was invoked. It went so far as to tell me that

document.getElementById(a_div_id) is null

By setting breakpoints in the script I quickly determined that, not surprisingly, the variable a_div_id referred to the id of a div on the page. It was there in the code -- clear as daylight. Here is about where the JavaScript cursing began. When that didn't help -- for the record, it never has -- I pulled out my trusty JS shell tool. Still muttering under my breath "I'll show you how it's done", I pounded the command

document.getElementById("line_items").style.display = 'block';

fully expecting to see the div with id=line_items to pop up.

Nope! Nothing but silence. The next port of call was the HTML source of the page in question. Sure enough, I was able to locate the div in question. However, the syntax highlighting showed that the entire div was commented out!!!! So, my script was correct in saying that there was no such element in the document.

Turns out that culprit was the use of textual em-dashes1 in my comments. Typically em-dashes are represented in text as two consecutive hyphens thusly

--

WYSIWYG editors (such as MS Word) are wont to convert that into a single em-dash



However, there is no such implicit conversion in a JSP or HTML page. So there it was smack in the middle of the comment.

<!-- This is bad news –– if you ask me. -->

It colluded with other such comments on the page to make a mess of what divs were actually there. I know HTML wonks out there are going to chime-in in unison with a "Well, D'uuuuh! Don't you know that that's improper HTML syntax". OK, for the rest of us, the Web Design group provides a pithy maxim to code by

An HTML comment begins with "<!--", ends with "-->" and does not contain "--" or ">" anywhere in the comment.

The formal definition of an HTML comment can be found at W3C.

My peeve now is that you would think that a self-respecting IDE like Eclipse2 would point that out for you. Now that I think back, even a puny little editor like VIM would flag this error. Heck, Eclipse doesn't even acknowledge <!> as a valid comment. If Eclipse had shown the code correctly as being in a comment, I would not have wasted time down the JavaScript rabbit hole in the first place.

All this is coming at the end of what has been a long week of futzing with Eclipse's sloppy handling of JSPs in general. Yes, this is with an Eclipse that is souped up to use the Eclipse Web Tools Project (WTP) "goodness".



1 em-dashes (—) Denotes a pause in thought, a parenthetical statement, or — more casually — an afterthought. For more on this subject, see What’s the Difference Between an Em Dash, En Dash & Hyphen?. BTW, did you know that an em-dash is called that because it is the width of a an 'm' in the current font? Useless trivia.
2 For the record, I am using the latest version 3.4.x (Ganymede).

Monday, November 24, 2008

Getting Hudson going on a Windows server

After getting all giddy about the ease of running Hudson (java -jar Hudson.war), I ran into rough weather pretty quickly. The main problems:
  1. Running under Tomcat
  2. Accessing our CVS server
As the saga unfolded the two issues got inexorably intertwined. After the Winstone experiment worked swimmingly, I cranked up Tomcat and dropped the Hudson WAR into the Tomcat webapps directory and it dutifully deployed up the application. I then configured Tomcat to run as a service.

Here was the first sign of trouble. When I ran a project build from Hudson, it reported a problem accessing CVS. It gave the vanilla CVS response to login first. Login as whom? The trouble was that the Tomcat service was running as the Windows system account. However, the system account is not authorized on the CVS server. Hmm...

Methinks I'll run Tomcat under the credentials of the account that does have access to CVS. I restart the service after this change and try to start another build.....however....I can't access Hudson. The Tomcat admin console reported that Hudson was running. Yet, when I accessed its URL, I didn't get a response. Uh oh!

To recap,
  1. If I ran Tomcat under the Windows system account, I cannot access CVS
  2. If I ran Tomcat with an account that could access CVS, Hudson's pages weren't being delivered....and let me throw in to the mix
  3. To make matters a little more intractable, CVS passwords when using CVSNT (the common CVS client on Windows servers) is stored in the registry and not in a .cvspass file.
Given all these facts, we decide to hack the registry by copying the CVS-authorized user's password into the profile of the system account. We had to go to some Microsoft web site to find out the arcane SID for the System account. Once we located the account, we created a cvspass entry for it and copied the password from the authorized user's account. Then, we reverted the Tomcat service to use the system account account and triggered a project build. No dice :-(

It became clear that the solution had to be found while running Tomcat as the CVS-authorized user. However, why wouldn't Tomcat serve the Hudson pages?

It turned out the reason was that Tomcat had been installed by the administrator to a location that the CVS-authorized user did not have write-access. However Hudson required write-access to the logs directory! Once we gave this account the necessary permission, everything was hunky dory.

Phew! That was quite a workout. I am not sure how typical/atypical is our user and environment set up. For sure it highlighted several of the moving parts and many of the things that can go wrong.

Here's hoping you aren't here because you ran into similar problems!

Tuesday, April 24, 2007

DBUnit + Sequence numbers + Foreign keys = Nightmare!

Setting up my unit tests with reliable fixtures is turning out to be quite a headache.

Sparing you arcane application-speak let me use the classic simple EMPLOYEE-DEPARTMENT example to illustrate my problem.

Facts:
  • We have the typical EMPLOYEE table and the DEPARTMENT table
  • Both use database-generated ids (sequence numbers) as primary keys.
  • An EMPLOYEE belongs to a DEPARMENT.
  • The DEPT_ID field in the EMPLOYEE table is a foreign key into the ID field of the DEPARTMENT table.
So far, so good.

Now, consider a method in the EmploymentDao class that returns all known employments. In SQL speak, it executes

Select e.emp_name, d.dept_name
From employee e, department d
Where e.dept_id=d.id

In order to test this method I need to set up the database with necessary data. I would like to be able to use something like DBUnit to set up my fixtures. However, I have to populate the DEPARTMENT table with at least one department record. Then, I need to get the ID field of that record to insert a record into the EMPLOYEE table. How does one do that ? This is crucial for a test such as

public void testGettingAllEmployments() {
List employments = employmentDao.getAllEmployments();
assertNotNull("Empty list of employments", employments);
}

Even with a simplification of suppressing foreign key constraints, I will have to do something like:
  • Insert a record into the DEPARTMENT table with a DBUnit fixture.
  • Insert a record in the EMPLOYEE table (with a bogus dept_id)
  • Then read the record, from the DEPARTMENT table to get at its id
  • Update the record in theEMPLOYEE table to set the dept_id
Wow! That's a lot of preamble -- not to mention using of the very DAO methods I want to test!!

Wednesday, February 21, 2007

Hello Google Reader. Goodbye Bloglines

I have been a longtime user of Bloglines. Sometime last year when Google introduced the Google Reader (GR) I took a looksee and was severely underwhelmed and so I stayed with Bloglines. One of my primary reasons was that GR did not work with my reading style. You see I like the blog posts grouped by feed -- all Slashdot posts together, all Javablogs together -- separated from the Slashdot posts.

Of course, the choice of Bloglines over over a locally installed reader was a no-brainer; I did not want to have to maintain a copy of my blogroll on each machine that I used during a typical day.

I recently peeked over to Google-land and lo and behold, this one feature that had been the deal-breaker for me had been added. In addition, were some very useful features that won me over. Here are the things that clinched the deal for me:

  • List view -- This allows me to glance at about 50-60 posts in a group at a time. If I am interested, I click on it to expand it and read a synopsis.
  • Ability to "star an item"
  • Keyboard shortcuts -- Boy! Do they ever have shortcuts. I haven't mastered them all yet
  • Ease of renaming feeds
  • Ability to selectively mark items as having been read -- Bloglines has a severe problem in that when you select a blog, every unread article in the blog is displayed and (this is the problem) they are all immediately marked as "read". Very often I start looking at feeds from a blog and before I can finish scanning all the unread posts, I am called away. With GR, I know where I left off
  • Progressive loading -- The reader doesn't attempt to load every article in the selected grouping in one fell swoop
  • Configurable start page -- I like my starred items to be displayed when I bring up the reader since well, I starred the item for a reason -- so that I can read them later!
Of course there is always a wishlist. Here's mine:

  • Ability to choose the order of display in the list view
    • [UPDATE] Anonymous commenter has shown me how! However I wish this wouldn't be a per-feed setting. OK, have a per-feed setting if you must but the one must be able to customize the default at a blogroll level.
  • Ability to mark an item as unread (I wouldn't at all be surprised if this feature is already there and that I just haven't figured out the keyboard shortcut)
    • [UPDATE] Thank you, Anonymous commenter for showing me the way!
  • Speed it up, please! Were it not for the features, GR's sluggishness would've be a deal-breaker!





powered by performancing firefox

Monday, May 15, 2006

JBoss Rules...Well, not quite!

I have been attempting to work with JBoss Rules (nee Drools) and have mostly met with frustration.

With the acquisition by JBoss, the Drools site (www.drools.org) pointed me to JBoss for v3 of the API. In fact, today, I can't even get to drools.org any more. Now cleverly annointed "JBoss Rules", I downloaded the version 3.0 RC2 of both the binary and the IDE.

No joy, however (several errors reading the DRL files). Tried various alternatives including recommendations on their mailing list by some of the project's leading lights that one use Eclipse 3.2 M6 and not 3.2 M5 as indicated by their docs. Still no joy.

Finally, I decided to download the source and built v3.0. Pay dirt! Actually, you don't need Eclipse 3.2 M6 -- the docs were right it works just fine on M5.

On the subject of docs, they are mere shells. The original Drools site used to have a plethora of documented examples, and usage documentation. Not any more. What is the syntax for the new DRL files? I see "duration" is a long, but what is it? About the DSLs? Why get rid of perfectly good documentation of the concepts?

OK, since the docs aren't there yet, I decided to join the mailing list. Again, I followed the instructions and tried to subscribe by sending email to user-subscribe@drools.codehaus.org. Again, no joy. I got an automated response that read

Hi. This is the qmail-send program at codehaus.org.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

:
Sorry, no mailbox here by that name.

So, what next?

JBoss Rules...I don't think so.

Friday, February 03, 2006

RailsConf: If you announce it, they will come...

The RailsConf has been getting a lot of press. So methinks let's see what the hullabaloo is all about.

Q: What are the sessions going to be?
Silly me, that's not been decided yet. Don't worry they have over 80 proposals.

Q:Where is it going to be held?
The web site says: Chicago, Venue TBA. TBA!!? What kind of amateurish prank is this? Oh, well, drill down a few pages further and you figure it's at a Wyndham hotel. Phew! At least I know where I'll be staying!

Important details aren't fleshed but they want you to register.... Do they ever! Better get there soon if you want to catch the "super early bird" blue light special. What gall!

That's not all, Mike Clark, Dave Thomas and cohorts (from the NFJS circuit) are drumming up the support on their blogs.

I am sure -- given the track record of the names named -- it will be a great conference. However I did not expect such premature promotion from so far east of Redmond. The Ajax Conf (or Experience or whatever they call it) is another example of a conference that was announced, much hyped before any details were available.

Is this to be the trend? Announce a conference, announce keynote speakers, build up clientele on the shoulders of the blogosphere an then work out the details?

Sunday, January 01, 2006

Wisdom of Amazon crowds?

I often find myself relying on the wisdom of crowds to guide my purchasing decision. How so? I go check out the customer reviews at Amazon. This has been a very a very good barometer for my purchase.

Analyzing my habit a little further, I realized that I don't just pick out the majority opinion. BTW, is there a way to get a summary of the customer reviews for an item? Such as,

Acme's New Super duper toaster ratings:
95% -- 4+ stars
2% -- 3 stars
2% -- other

probably could using Amazon web services. Anyway, what I seek out is the not-so-silent minority. I want to see why, while the page is filled with 5-star or 4-star reviews, there are a discordant few. I do read (some of) the majority opinions. However, you tend to get the drift after the first few. Have you noticed that the majority opinion cites similar reasons? However, the minority seem to have more variety -- or maybe its just a matter of numbers.

It is the gripes I pay close attention to: is the review just a sore rant or do the complaints seem to have merit. Are these reasons something that I feel is important to me -- or do I not care that the toaster doesn't have a mirror-like sheen?

Such an analysis has held me in good stead over the past few years of major and minor purchases. In retrospect, this seems to weight the few heavier than the many -- contrary to Surowiecki's contention.

Monday, December 26, 2005

AJAX Experience...Yet another boondoggle

A colleague of mine upon hearing of the Spring experience, said "what a boondoggle". That captured exactly how I felt about it.

Now, I don't object to one man's opinion of enterprise. I know Jay Zimmerman and I applaud him for putting up a fabulous show time and time again with his No Fluff Just Stuff series. However a symposium just on Spring? C'mon. If you are new to Spring, a symposium isn't a way to learn to use it. If you already using Spring, you may get something out of 10-20% of the sessions. How do I figure? Due to many level 101 sessions, and others that you can't attend due to conflicts.

Hard on its heels comes the AJAX experience. A symposium essentially on one Javascript API call! Do we really need a conference on AJAX? Aren't there enough online articles, blogs, and books (don't get me started) on the subject?

My prediction: Coming soon shall be a Ruby Experience -- which actually is a topic worthy of an "experience". I guess what I really envy is Jay's entrepreneurial spirit. You go Jay!

Thursday, July 21, 2005

Maven catch-22 with multiproject builds

Maven's multiproject plug-in is a very useful tool on a large project that's been organized into several sub-projects. Using the dependencies the reactor figures out the correct order in which to build the entire project. However Maven gets in its own way when doing such builds. Here's how:

Consider a multiproject with sibling sub-projects that are interdependent. Having been bitten one too many times for not doing so, I have become fastidious about maven cleaning before every build. Just as with any other plugin, when you invoke clean, Maven checks the dependencies. However, when this happens the first time the multiproject is being built, the dependencies cannot satisfied and so the build quits with a failed dependency.

If you are wondering why get so anal about cleaning and that it isn't needed before the first-ever build, consider setting up your builds to be managed by CruiseControl. That's an automated process and needs to be given the goal(s) that must be executed at every build cycle.

So, the only solution I know is to perform a one-off build manually without a clean and then let CruiseControl loose. Can you suggest a better alternative?

Speaking of cleaning and multiprojects, why doesn't multiproject:clean clean the root directory? Why do I have to maven clean multiproject:clean?

Monday, June 13, 2005

Reasons to attend a NoFluffJustStuff conference

I just spent the last three days at my third NoFluffJustStuff conference -- the Research Triangle Software Symposium. My brain is full and I am wiped and extremely invigorated!! It is my annual shot-in-the-arm booster that makes me look forward to going to work! Here are some of my reasons why you shouldn't miss the next opportunity. (Of course you can also see their top-10 reasons):

The speakers: The speakers are uniformly exceptional. They not only know what they are talking about, they want to be on the stage and are good at it. Further, they don't mind answering questions -- and not just during the session. Speakers are routinely found mingling with the attendees at lunch and breaks.

Constant innovations: In the three years that I've been attending these conferences, it has constantly been evolving, never leaving well enough alone. First it was end-of-day keynotes, then it was the introduction of .Net topics, then it was BOFs, web-site with speaker blogs, etc etc.

Timely topics:At any given time there are invariably 5 active sessions. The topics being discussed at these session are not only of high quality, they are timely. Let's take the latest conference. There were sessions on AJAX, Tapestry, Spring, Hibernate, Ruby, Rails, the list goes on.

Doesn't cut corners: The high quality doesn't stop with the speakers and the sessions, it includes the other amenities. You get all the session materials on CD, with binders, in a nice laptop carrying case (another innovation for this year). Meals (read: breakfasts, lunches, snacks and opening night dinner) during the conference are provided. Jay Zimmerman (the organizer) could very easily have just thrown in the "continental breakfast" fare. But meals here would put most restaurants to shame. There is of course the obligatory raffle during the conference. Even there this one outshines. There are two raffles. At the recent conference, up for grabs were books, an iPod and the new Sony PSP.

I think there are about 28 events over the course of the year at different locations across the US. So, if you are in the country, chances are, there is one in your neighborhood. Don't miss it.

Thursday, May 12, 2005

Freeware installer recommendation?

I have been using Null Soft's product and frankly, I just don't get the NSI scripting language. It just seems too arcane and doesn't seem to flow right -- if you know what I mean. I spend more time digging through the help docs and Googling to figure out how to get something going.

I would welcome any alternative tool recommendation -- freeware of, course :) My target environment is Windows and so the tool doesn't have to be cross-platform capable.

Tuesday, May 10, 2005

Visualizing Web Logic's domain configuration

Web Logic's config.xml is the center of WL universe. This is what WL uses to keep track of all servers, deployments, services etc and is one gnarly XML file. Yes it isn't for human consumption but it helps to be able to read it when diagnosing problems. Now you have a handy-dandy XSL stylesheet that'll present this file in HTML. Element names are hyperlinks. Following these links takes you to the appropriate reference documentation page. Now, why didn't I think of that? This works with IE and Firefox although with the latter it doesn't work for a file:// URL. Any ideas why?

Attributes: I can't place the actual blog where I came across this tip. So thank you, anonymous.

Wednesday, April 20, 2005

StrutsTestCase and Tokens

How does one get around the usage of Struts tokens when unit testing using StrutsTestCase? If the action class under tests for duplicate submissions using tokens,

if(isTokenValid(request) == false) {
// don't perform the action and route the user
// to an appropriate location
}

it'll always fail. This is because, the token is set in the request by the tag and of course when running a StrutsTestCase, the JSP isn't involved.

The application functions correctly, however, I cannot run my unit tests :(

Thursday, April 07, 2005

Clustering mutable objects

One of things a clusterable application server (for example, Web Logic) does for an application is to broadcast objects placed in the user's session. This happens (at least with Web Logic) whenever the application invokes the setAttribute method of the HttpSession interface. This has a subtle impact when the thing being placed in the session is a mutable object. To explain, first consider a simple (non-mutable) example

1: String name = "John";
2: session.setAttribute("username", name);

The application server will serialize the value associated with the key username to all the nodes in the cluster. Now suppose that the node executing the above steps turns around and changes the value of name. IOW

1: String name = "John";
2: session.setAttribute("username", name);
..
15: name = "Mary";
16: String sessionValue = (String)session.getAttribute("username");

Since Java passes a copy of a reference to a method call, sessionValue is guaranteed to be John -- on all the nodes. No harm. No foul.

Now consider placing a mutable object such as a java.util.List in the session.

1: List cart = new ArrayList();
2: session.setAttribute("shoppingcart", cart);

Just as with the String before, this will get propagated to all the nodes in the cluster. Now suppose the cart is updated in one of the nodes:

1: List cart = new ArrayList();
2: session.setAttribute("shoppingcart", cart);
..
19: cart.add(aLineItem);
..
// More business logic
25: List sessionValue = (List)session.getAttribute("shoppingcart");
26: System.out.println("Cart size = " + sessionValue.size());

Now, line 26 above will display different values depending on the node on which it was executed. The node which added the item to the cart will display Cart size = 1 while the others will display Cart size = 0.

This is bad! This can be avoided if we place an item in the session as the last step of responding to a user request. Application development and application deployment are -- in large part -- independent activities. This is an instance where the developer needs to be aware that (s)he is developing an application that's going to be deployed to a clustered environment.

Monday, March 07, 2005

Jira's service -- Legendary or just a legend

[Updated: See end of posting]
Recently, we came across some critical problems with our Jira installation. When we couldn't figure out/fix the problem ourselves, I posted a support request to Jira's support site. In response, I received a request for additional information. Since the request involved a fairly sizeable attachment I wrote back to clarify the request. Didn't get a response. I decided to send the attachment anyway and updated the support request with the required information and waited for a response. That was 4 days ago...The silence is deafening.

When you stick your neck out so far and claim "Legendary services"....well, you have to deliver. Atlassian's web-site quotes Jeff Bezos

"If you have an unhappy customer on the Internet, he doesn't tell his six friends, he tells his 6,000 friends"

The trouble is, there is no apparent way to escalate an issue. I couldn't find a phone number to call or any other email addresses -- other than for sales. I finally located a contact page. I filled out the form stressing the urgency of our problem and asking about an escalation process. Still not a peep.

We were considering purchasing Confluence. The one reservation that I had thus far was the lack of coherent documentation. I am now wondering if going for Confluence would be wise given the trouble I'm having with Jira; which, btw has excellent documentation.

I realize the irony of using javablogs to publish my gripe...

[Update: Mar 9 2005 2300]
Since originally posting the above, I have heard back from Atlassian. I hope the timing was just a coincidence.

The problems are being handled.

Tuesday, January 25, 2005

Struts and checkboxes

The following is a reminder to those working on implementing checkboxes on their pages.


It is essential that you implement the ActionForm's reset() method. In this method, you must set the fields that populate the checkboxes to false. The reason is that an HTTP request only includes values for selected checkboxes. Any de-selected box will not be a part of the request and so the server-side will be none the wiser that a user un-checked a box.

An important side note (one that cost me quite a while): The reset() method is overloaded with the following variants

 

void reset(ActionMapping mapping, ServletRequest request)

and

void reset(ActionMapping mapping, HttpServletRequest request)


For a web UI, you need to implement the latter. If you use your IDE's intellisense, it is easy to accidentally pick the former since it shows up first in the list of choices.

Friday, October 29, 2004

President Edwards? A mathematical possibility

Stephen Marmon's article paints the scenario in which we could have John Edwards in the Oval office come Jan 2005. Interesting, if not anything.

Thursday, October 14, 2004

Google your desktop -- Sweet!

The new Google Desktop Search is really a nice extrapolation (or is it really an intrapolation) of what Google does for the Internet.

You can now just as easily search the contents of your desktop -- including Outlook-based emails. Even nicer, when you search the web using Google, it prefaces the search results with hits on your local machine!

Tuesday, September 28, 2004

JSF & Struts to co-exist?

Craig McClanahan, the creator of Struts and one of the leaders in the JSF 1.0 spec sees a world where JSF is a souped up presentation layer for a Struts-controlled application. He writes at length about this in his blog.

Friday, September 17, 2004

Continuous Integration Tools' Feature Matrix

Found an interesting feature matrix comparing various CI tools.

Aside: I got to this point from some article referring to Damage Control. I looked high and low at the site to see what is Damage Control. I could only infer that it is a tool in the same genre as CruiseControl. Sure could use better introductory docco. There is a lot of information if you already know what it is and what you need.

Tweety thoughts

    follow me on Twitter