We’ve been grappling with a number of different problems with our app over the last week. We’ve made many improvements, including several changes to our Spring configs (which I may touch on another day), but we still had a problem where occasionally we ran out of database connections momentarily — no matter how many we had in the pool to start with.
So the other morning I got an itch to start coding while I was waiting for my carpool ride to show up. By the time I got to work, I had a rough draft of something I wanted to try out. It’s a simple logging DataSource. We converted our datasource to one driven by Spring a couple months ago, but we still have a combination of straight JDBC, an old custom in-house ORM tool, and Hibernate. Somewhere among them, we’ve got something occasionally misbehaving.
It’s a pretty simple concept. I decided to extend Spring’s DelegatingDatasourceProxy to make my LoggingDataSource. Configuration is just as simple as changing this:
<jee:jndi-lookup id="dataSourceTarget" jndi-name="java:/MyJbossDS"/>
to this:
<bean id="dataSource" class="com.timshadel.util.LoggingDataSource">
<property name="targetDataSource" ref="dataSourceTarget"/>
<property name="filterPattern" value="^(com.timshadel|com.example).*"/>
</bean>
<jee:jndi-lookup id="dataSourceTarget" jndi-name="java:/MyJbossDS"/>
When you turn it on, you might see something like this:
[main] INFO com.timshadel.util.LoggingDataSource - Connection request stack trace, filtered by '^(com.timshadel|com.example).*'
com.example.myapp.model.MyClass.determineSomethingImportant(MyClass.java:770)
com.example.myapp.model.MyClass.updateStatusString(MyClass.java:674)
com.example.myapp.model.MyClass.loadStatusInfo(MyClass.java:643)
com.example.myapp.model.MyClass.reloadStatusInfo(MyClass.java:332)
com.example.myapp.util.helper.LegacyHelper.run(LegacyHelper.java:440)
[main] ERROR com.timshadel.util.LoggingDataSource - Connection request stack trace, filtered by '^(com.timshadel|com.example).*'
CAUGHT EXCEPTION (java.sql.SQLException): Pretend there's no more connections.
com.example.myapp.model.MyClass.determineSomethingImportant(MyClass.java:770)
com.example.myapp.model.MyClass.updateStatusString(MyClass.java:674)
com.example.myapp.model.MyClass.loadStatusInfo(MyClass.java:643)
com.example.myapp.model.MyClass.reloadStatusInfo(MyClass.java:332)
com.example.myapp.util.helper.LegacyHelper.run(LegacyHelper.java:440)
All of the stacktrace lines have been removed except those that match your pattern. This is helpful to make sure you cut through a typical enterprise Java call stack to only show the calls your code is making. For us that was helpful as a poor man’s way to determine which pieces of our code were using connections frequently. One simple run turned up a few hotspots. If we need to dig in a bit more, perhaps we’ll throw together a simple Ruby script to count how often a given call stack shows up in the log.
Also note, that since this puts the info out to Log4j, you can obviously pull this logging out to a completely separate file, set a different threshold, or use any of the other standard Log4j features to capture this information in a way that’s useful to you.
Finally, please remember that I pulled lots of this together while riding to work. It’s not really meant to be used for anything serious. Please expect warts and problems, but hopefully it’s enough to help get you goin’.
These days there’s lots of sleaze around, and one place where it annoys me is at the domain registrar GoDaddy.com. I’ve used them forever it seems — back when I saw their ad on AltaVista’s search engine. These days, though, I find their marketing to be sleazier than I appreciate. On top of that I’m not interested in paying the rates they require to keep your domain private, and for my new domains I’m interested in simple email setups and such. So Google Apps for Your Domain fits the bill quite nicely. It’s $10 per year, you get a GMail-ish setup plus more, and I don’t have to use GoDaddy.com.

I haven’t yet signed up with eNom for anything. I plan to purchase my first domain from them (via Google Apps) tomorrow. I may not be able to move all of my domains right away, but I think that by pushing my money to someone else that’s less offensive I’ll feel better about what it gets used for in the end. It’s small, but it’s one simple way to start standing up against the sleaze of the day.
It’s hard to believe that it’s been a year since my “burrito” podcasts on JSF. So what have I done in this last year with JSF? What is my opinion now and how has it changed?
Have you ever skipped out on a movie that was popular? Decided not to see it because it either didn’t fit your taste or didn’t mesh with your life in some other way? I have. I usually look back later on without regret. That’s the way I feel looking back at JSF a year later, but let give you some details.
Read more…
Mike Clark is wondering:
Which RubyGems are you sporting?
So my current list is down below. I imagine it will change soon — maybe tomorrow.
gem list | grep "^[a-zA-Z]"
actionmailer (1.3.2, 1.3.1, 1.2.5)
actionpack (1.13.2, 1.13.1, 1.12.5)
actionwebservice (1.2.2, 1.2.1, 1.1.6)
activerecord (1.15.2, 1.15.1, 1.14.4)
activesupport (1.4.1, 1.4.0, 1.3.1)
aws-s3 (0.3.0, 0.2.0)
BlueCloth (1.0.0)
builder (2.0.0)
capistrano (1.4.0, 1.3.0, 1.2.0)
cgi_multipart_eof_fix (2.1)
daemons (1.0.4, 1.0.3)
ezcrypto (0.7)
fastthread (0.6.3)
gem_plugin (0.2.2, 0.2.1)
hoe (1.2.0)
hpricot (0.5, 0.4)
libxml-ruby (0.3.8.4, 0.3.8)
mechanize (0.6.4)
mime-types (1.15)
mongrel (1.0.1, 0.3.13.4)
mongrel_cluster (0.2.1)
needle (1.3.0)
net-sftp (1.1.0)
net-ssh (1.0.10)
rails (1.2.2, 1.2.1, 1.1.6)
rake (0.7.1)
RAliasFile (0.1.0)
rubyforge (0.4.0)
rubyosa (0.2.0, 0.1.0)
sources (0.0.1)
wirble (0.1.2)
xml-simple (1.0.10)
ZenTest (3.4.3)
- Download winstone from it’s Sourceforge Files page
- Download the Hudson war file from its Java.net Release page
- Then run
java -jar winstone-0.9.6.jar --warfile=hudson.war --httpPort=8081
- You should see something like the screenshot below.
- Play.

One of my favorite features of Hudson is the ability to watch the console output of a build in progress, like this one:

Other cool things include:
- No more messing around with XML
- I can setup a Hudson job and use it to run
mvn release:clean release:prepare on my branch code. (Haven’t tried this beyond tinkering yet, though. Could possibly be manual or nightly job it seems.)
- It’s easy to have several builds for different branches and see them all at once.
- There’s a really cool build history graph that shows both the time it took to build each release, and whether it passed or failed — makes it easy to see your build trends on the team.
I’m looking forward to investigating it’s publishing of Javadoc and JUnit test results. I also want to see if it’ll do anything with Maven’s site generation. If so, that’d be a big win. I’ve fiddled with Continuum, but this just feels like a better setup to me, and the author seems eager to add Maven2 integration to it.
After having it around for a couple weeks, I’ve tentatively switch our build to use it. It’s just so easy to turn on, that it seems like a no brainer. If it doesn’t pan out then we can always turn CruiseControl back on, but I don’t anticipate that outcome. Something else I might try is to drop Hudson into Tomcat if winstone seems to strain, but I don’t think we’ll need that either. It’s built our stuff plenty fast in that little servlet container for a few weeks now, so I’m not anticipating any load increase to it — simply more publicity for it among our team.
Try it out. Let me know if you think it’s worth the switch.
This morning I experimented a bit with overriding the default HTML generated by validation errors in Rails. Instead of wrapping the <input> tag inside a <div class="fieldWithErrors"> indiscriminately (which was breaking the layout I wanted), I wanted to simply inject a new CSS class onto the HTML element.
I found one email showing how to use regular expressions to get the job done. It may work, but I wanted something that seemed a little less blunt. I’ve also been playing around with Hpricot lately as well. So I decided to try to combine the two. Here’s the first draft of what I came up with:
require 'hpricot'
Rails::Initializer.run do |config|
. . .
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
doc = Hpricot(html_tag)
elem = (doc/"/").first
css_class = elem.attributes['class']
css_class ||= ""
css_array = css_class.split(" ")
css_array << "fieldWithErrors"
elem.attributes['class'] = css_array.uniq.join(" ")
doc.to_s
end
end
I then changed the CSS ever so slightly from the default scaffold.css:
.fieldWithErrors {
border-color: red;
background-color: #ffcccc;
}
The result looks like this:

The layout I had before is completely preserved, and I have the chance to color the input the way I want. I haven’t tried it with a <textarea>. Also, I tried to adjust for the possibility of other CSS classes already existing on the element, but I’ve only checked it in irb. Let me know if you’ve got improvements to this approach; I’d love to hear ‘em.