<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>I’m Tejus Parikh and this is my blog about programming, startups, and other technology related topics.

The vast majority of the posts are about Java or Ruby code, with a few about startups or gadgets thrown in for color.

You can learn more about me on Github and my personal homepage.</description><title>Tejus's Programming and startup blog</title><generator>Tumblr (3.0; @tejustechblog)</generator><link>http://tech.tejusparikh.com/</link><item><title>Access Denied Error when using XHR PUT and DELETE</title><description>&lt;p&gt;Late one night, I was attempting to wire up a delete button on a Rails app using XHR.  However, every time I attempted to make the XHR call, I saw &lt;code&gt;AccessDenied&lt;/code&gt; in the server log and my session was un authenticated. Since it was late, I remapped it to a different URL and moved on.&lt;/p&gt;

&lt;p&gt;However, the fact that this did not work still bothered me and when I revisited it after a good night’s sleep, the answer was quite obvious. My Ajax setup (copied from many Rails projects ago) looked like:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1769263" target="_blank"&gt;&lt;a href="http://gist.github.com/1769263" target="_blank"&gt;http://gist.github.com/1769263&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I was only setting the &lt;code&gt;X-CSRF-Token&lt;/code&gt; on a &lt;code&gt;POST&lt;/code&gt;. Therefore, when the server received the &lt;code&gt;DELETE&lt;/code&gt; verb, it killed the session, thinking that something was afoul.&lt;/p&gt;

&lt;p&gt;Changing that line to:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1769443" target="_blank"&gt;&lt;a href="http://gist.github.com/1769443" target="_blank"&gt;http://gist.github.com/1769443&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;fixed the issue in the correct way.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/17262580378</link><guid>http://tech.tejusparikh.com/post/17262580378</guid><pubDate>Wed, 08 Feb 2012 08:22:41 -0500</pubDate><category>ruby</category><category>ruby on rails</category><category>security</category></item><item><title>Access Denied Error when using XHR PUT and DELETE</title><description>&lt;p&gt;Late one night, I was attempting to wire up a delete button on a Rails app using XHR.  However, every time I attempted to make the XHR call, I saw &lt;code&gt;AccessDenied&lt;/code&gt; in the server log and my session was un authenticated. Since it was late, I remapped it to a different URL and moved on.&lt;/p&gt;

&lt;p&gt;However, the fact that this did not work still bothered me and when I revisited it after a good night’s sleep, the answer was quite obvious. My Ajax setup (copied from many Rails projects ago) looked like:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1769263" target="_blank"&gt;&lt;a href="http://gist.github.com/1769263" target="_blank"&gt;http://gist.github.com/1769263&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I was only setting the &lt;code&gt;X-CSRF-Token&lt;/code&gt; on a &lt;code&gt;POST&lt;/code&gt;. Therefore, when the server received the &lt;code&gt;DELETE&lt;/code&gt; verb, it killed the session, thinking that something was afoul.&lt;/p&gt;

&lt;p&gt;Changing that line to:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1769443" target="_blank"&gt;&lt;a href="http://gist.github.com/1769443" target="_blank"&gt;http://gist.github.com/1769443&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;fixed the issue in the correct way.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/17262576835</link><guid>http://tech.tejusparikh.com/post/17262576835</guid><pubDate>Wed, 08 Feb 2012 08:22:30 -0500</pubDate><category>ruby</category><category>ruby on rails</category><category>security</category></item><item><title>@Autowire with AOP Proxy Classes in Spring</title><description>&lt;p&gt;This is an issue that gets me once every blue moon. Lets say that I have two classes &lt;code&gt;DependencyClass&lt;/code&gt; and &lt;code&gt;MainClass&lt;/code&gt;:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1568484" target="_blank"&gt;&lt;a href="http://gist.github.com/1568484" target="_blank"&gt;http://gist.github.com/1568484&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;DependencyClass&lt;/code&gt; makes use of Spring’s &lt;code&gt;@Transactional&lt;/code&gt; support, which is provided through AOP Proxies. This code works when I fire it up. However, if I add another implementation, and want to change the code to the following:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1568539" target="_blank"&gt;&lt;a href="http://gist.github.com/1568539" target="_blank"&gt;http://gist.github.com/1568539&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I get this nasty on the application startup:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;NoSuchBeanDefinitionException: No matching bean of type [DependencyClass] found for dependency
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The reason for this is simple. Within the Spring container, the concrete class &lt;code&gt;DependencyClass&lt;/code&gt; has been replaced by a proxy. Therefore, as far as the system is concerned, there is no matching bean of type &lt;code&gt;DependencyClass&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Inevitably, when this occurs, I spend too much time looking to other issues with my application context setup. However, the solution is easy and straightforward, once you realize what the problem is:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1568553" target="_blank"&gt;&lt;a href="http://gist.github.com/1568553" target="_blank"&gt;http://gist.github.com/1568553&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically, one needs to change the type back to an interface, then use named services and the &lt;code&gt;@Qualifer&lt;/code&gt; annotation to inject the desired dependency.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/15376275315</link><guid>http://tech.tejusparikh.com/post/15376275315</guid><pubDate>Thu, 05 Jan 2012 21:09:52 -0500</pubDate></item><item><title>Can Vertical Acuity Stop Your Site Losing Visitors?</title><description>&lt;a href="http://mashable.com/2011/11/22/vertical-acuity/"&gt;Can Vertical Acuity Stop Your Site Losing Visitors?&lt;/a&gt;: &lt;p&gt;It’s always fun to wake up in the morning and see Mashable do a write up on your company.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://mashable.com/wp-content/uploads/2011/11/125,Ungoogle_1.jpg" alt="Can Vertical Acuity Stop Your Site Losing Visitors?" width="125"/&gt;Vertical Acuity Quick Pitch: Vertical Acuity is a self-serve content syndication…&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/13158353083</link><guid>http://tech.tejusparikh.com/post/13158353083</guid><pubDate>Tue, 22 Nov 2011 09:58:39 -0500</pubDate></item><item><title>(Trying to) Sanely Deal with Maven Dependency Versions</title><description>&lt;p&gt;One challenge of the maven way is how to sensibly version dependencies in a large, but constantly changing, project.&lt;/p&gt;

&lt;p&gt;In the ideal maven world, each module is a highly defined project, with a highly structured team and releases only occur once the contract has been fully defined, tested, and whatever else enterprise teams do. In many realities, projects are simply logical constructs that don’t have strict contracts between the other module. The production environment is a mix of highly stable and rigorously tested products and experimental, pushed-constantly projects.&lt;/p&gt;

&lt;p&gt;In this environment, automatic versioning of dependencies is both unnecessary and costly, and the dependencies need to be frozen at branch time of the stable, top-level projects. The other requirement is that the changes to the poms need to be minimal, so that any merge conflicts can be easily resolved.&lt;/p&gt;

&lt;p&gt;The approach I’ve used, combining a few different ideas from the internet, is to remove any version numbers referencing internal projects from child modules. The versions are then included as properties in the parent project.&lt;/p&gt;

&lt;p&gt;Freezing the set of dependencies for the module tree is then a three part process of:
- Change the version number in the parent pom
- Change the version properties of the parent pom
- Change the parent version number in the child poms&lt;/p&gt;

&lt;p&gt;To illustrate how this works, consider a project that has &lt;code&gt;com.tejusparikh.web&lt;/code&gt; with a parent pom &lt;code&gt;com.tejusparikh&lt;/code&gt;.&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1341577" target="_blank"&gt;&lt;a href="http://gist.github.com/1341577" target="_blank"&gt;http://gist.github.com/1341577&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1341587" target="_blank"&gt;&lt;a href="http://gist.github.com/1341587" target="_blank"&gt;http://gist.github.com/1341587&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you wanted to freeze the poms at &lt;code&gt;1.0.RELEASE&lt;/code&gt; then the poms would look like the following:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1341596" target="_blank"&gt;&lt;a href="http://gist.github.com/1341596" target="_blank"&gt;http://gist.github.com/1341596&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1341597" target="_blank"&gt;&lt;a href="http://gist.github.com/1341597" target="_blank"&gt;http://gist.github.com/1341597&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The point is that every child pom would have a property as it’s version number, making it easy to manage an arbitrary number of children.&lt;/p&gt;

&lt;p&gt;Of course, you don’t want to have to update everything manually. The only method I’ve found to effectively use maven is to wrap it all in &lt;code&gt;rake&lt;/code&gt;. Therefore, I’ve created a rake task to recurse the directories and change the version numbers.&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1341631" target="_blank"&gt;&lt;a href="http://gist.github.com/1341631" target="_blank"&gt;http://gist.github.com/1341631&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Freezing all of your poms is as simple as calling &lt;code&gt;rake mvn:version[/path/to/parent/dir,VERSION]&lt;/code&gt;.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/12370814587</link><guid>http://tech.tejusparikh.com/post/12370814587</guid><pubDate>Sat, 05 Nov 2011 11:10:12 -0400</pubDate></item><item><title>Getting Rid of My Personal Server</title><description>&lt;p&gt;&lt;img src="http://media.tumblr.com/tumblr_ltbj7lc9iI1qagzx4.png" alt=""/&gt;&lt;/p&gt;

&lt;p&gt;A few years ago, I stopped hosting my site on physical hardware and got a VPS from &lt;a href="http://www.linode.com" target="_blank"&gt;Linode&lt;/a&gt;. This worked really well for a few years, but I’ve gotten busy with other things and linux server administration really doesn’t interest me anymore.&lt;/p&gt;

&lt;p&gt;Since I blog so infrequently, every time I was tempted to write a blog, &lt;a href="http://www.wordpress.org" target="_blank"&gt;Wordpress&lt;/a&gt; begged me to update it. By the time I installed the patches, updated the plugins, I blew the window and desire to write a blog post.&lt;/p&gt;

&lt;p&gt;Therefore, through no real fault of Linode, I’m shutting down my VPS and moving to strictly to SaaS solutions.&lt;/p&gt;

&lt;p&gt;The most important and challenging was moving the blogs to &lt;a href="http://www.tumblr.com" target="_blank"&gt;Tumblr&lt;/a&gt;. I wrote a &lt;a href="http://tech.tejusparikh.com/post/10934666890/wordpress-to-tumblr-importer" target="_blank"&gt;small post&lt;/a&gt; for the tool I wrote.&lt;/p&gt;

&lt;p&gt;The other challenge old SVN repositories off the machine. Since these are really just projects that I created years ago for very specific people and purposes, the cost of &lt;a href="http://www.github.com" target="_blank"&gt;Github&lt;/a&gt; didn’t make sense. Instead I opted for the free plan on &lt;a href="https://bitbucket.org/" target="_blank"&gt;Bitbucket&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Finally, I am using Linode to handle some of my DNS. Since I moved my domains to &lt;a href="http://namecheap.com" target="_blank"&gt;namecheap&lt;/a&gt;, I just use their free domain service for most things. For anything that requires more, there’s always Amazon’s &lt;a href="http://aws.amazon.com/route53/" target="_blank"&gt;Route 53&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Just for kicks, I created my own “about-me” style &lt;a href="http://tejusparikh.com" target="_blank"&gt;page&lt;/a&gt; and tossed it out there with Amazon’s &lt;a href="http://aws.typepad.com/aws/2011/02/host-your-static-website-on-amazon-s3.html" target="_blank"&gt;S3 for static websites&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Unless you are hosting a real application, there’s almost no reason to manage one’s own server. There are simply too many free or cheap alternatives that handle the administration overhead.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/11654486316</link><guid>http://tech.tejusparikh.com/post/11654486316</guid><pubDate>Wed, 19 Oct 2011 11:23:15 -0400</pubDate></item><item><title>Using Noah to Configure Properties in your Spring Container</title><description>&lt;p&gt;On a recent trip through our code base, I realized that there were multiple projects that used identical properties defined in files that sat on the file system. I find DRY is a superior pattern to copy and paste I wanted to consolidate these into a single location.&lt;/p&gt;

&lt;p&gt;One approach would be to move them up a level in the source stack, and either rely on the properties being included in a jar or included via the build process. Both of these approaches suffer from some drawbacks and require rebuilds on a config change. Also the properties are still located all over the place, making it difficult to recover from mistakes or handle changes to the environment.&lt;/p&gt;

&lt;p&gt;One of my co-workers, &lt;a href="http://about.me/lusis" target="_blank"&gt;John Vincent&lt;/a&gt;, is currently developing &lt;a href="https://github.com/lusis/Noah" target="_blank"&gt;Noah&lt;/a&gt; which is a lightweight node/service registry. However, there’s nothing that says you couldn’t use it as a centralized location for properties files.&lt;/p&gt;

&lt;p&gt;I uploaded my properties file using Noah’s &lt;a href="https://github.com/lusis/Noah/wiki/Ephemeral-API" target="_blank"&gt;Ephemeral API&lt;/a&gt;. From there, it was a very trivial to make the properties available to Spring:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1271788" target="_blank"&gt;&lt;a href="http://gist.github.com/1271788" target="_blank"&gt;http://gist.github.com/1271788&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, I didn’t like the url hardcoded in the configuration file. I’d prefer to have them configured through some properties that do live on the filesystem. In effect, each server would just need to know where to go to configure themselves. This required more advanced Spring trickery. Since all &lt;code&gt;PropertyPlaceholderConfigurer&lt;/code&gt; instances implement &lt;code&gt;PriorityOrder&lt;/code&gt;, they will be implemented before any property expansion has become. Therefore, you have to create your own &lt;code&gt;Ordered&lt;/code&gt; bean that wraps a &lt;code&gt;PropertyPlaceholderConfigurer&lt;/code&gt;. The following code is adapted from &lt;a href="http://forum.springsource.org/showthread.php?89623-PropertyPlaceholderConfigurer-problems" target="_blank"&gt;this discussion forum&lt;/a&gt;.&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="http://gist.github.com/1271808" target="_blank"&gt;&lt;a href="http://gist.github.com/1271808" target="_blank"&gt;http://gist.github.com/1271808&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then you configure it in your &lt;code&gt;applicationContext.xml&lt;/code&gt; file like the following:&lt;/p&gt;

&lt;p class="embed_gist"&gt;&lt;a href="https://gist.github.com/1271812" target="_blank"&gt;&lt;a href="https://gist.github.com/1271812" target="_blank"&gt;https://gist.github.com/1271812&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, you just have to manage one file on the filesystem that points to where the rest of the application’s configs can be found.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/11167965365</link><guid>http://tech.tejusparikh.com/post/11167965365</guid><pubDate>Fri, 07 Oct 2011 23:36:23 -0400</pubDate><category>noah</category><category>java</category><category>spring</category></item><item><title>Import your wordpress blog into Tumblr</title><description>&lt;p&gt;Last week, I searched rather fruitlessly for a way to import my wordpress blog into Tumblr. There were a few snippets and examples out on the web, but they all used the older API or required email addresses and passwords for authentication.&lt;/p&gt;

&lt;p&gt;Since I couldn’t find what I was looking for, I opened up my IDE, fought with OAuth, and created a &lt;a href="https://github.com/vijedi/tumblr_import" target="_blank"&gt;Wordpress to Tumblr&lt;/a&gt; importer.&lt;/p&gt;

&lt;p&gt;Using the importer is pretty easy, you just need ruby and &lt;a href="http://gobundlr.com/" target="_blank"&gt;bundlr&lt;/a&gt;. The script is a &lt;a href="http://www.sinatrarb.com/" target="_blank"&gt;sinatra&lt;/a&gt; application so you should will only need normal Tumblr OAuth access and not require XAuth approval.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10934666890</link><guid>http://tech.tejusparikh.com/post/10934666890</guid><pubDate>Sun, 02 Oct 2011 10:50:35 -0400</pubDate><category>wordpress</category><category>tumblr</category><category>ruby</category></item><item><title>Re-evaluating Vaadin : A Difficult Framework for Building Web Applications</title><description>&lt;p&gt;&lt;a href="http://vaadin.com" target="_blank"&gt;&lt;img height="50" width="211" class="alignright" title="Vaadin Logo" src="http://vaadin.com/vaadin-theme/images/vaadin/vaadin-logo-white.png"/&gt;&lt;/a&gt;I just had to make the rather painful (well painful for my free time) decision to re-write the project that I and a team member had written in &lt;a href="http://vaadin.com/home" target="_blank"&gt;Vaadin&lt;/a&gt; with the old standby’s of JQuery, JSP’s, and Spring MVC. There was a lot of frustration that went into maintaining the project over the last year and it simply became very difficult to deliver what the product team wanted in a timely manner. The point of the post is not to bash the framework, but present the difficulties I encountered that made it unusable for us.  I described the reasons we picked Vaadin in a previous post &lt;a href="http://www.vijedi.net/2010/evaluating-vaadin-a-java-web-application-framework/" target="_blank"&gt;Vaadin&lt;/a&gt;. Many of the benefits still exist, but some of our core assumptions lead to major headaches down the line.&lt;/p&gt;
&lt;h3&gt;Integration with Spring&lt;/h3&gt;
&lt;p&gt;The vast majority of what we do and where we spend our time is on the server. We’ve built large libraries of internal functions that are exposed to other aspects of our application stack through Spring. We use Spring for security, talking to the database, configuring our remoting endpoints, and almost everything else.  Unfortunately, you can’t dependency inject the Vaadin &lt;code&gt;Application&lt;/code&gt; object.&lt;/p&gt;
&lt;p&gt;The most sensible pattern is to create a static singleton that has the beans your application needs to access. However, this is very kludgy and somewhat defeats the purpose of dependency injection.   Also, since the Application is one monolithic thing, it is impossible to make use of Spring Security filters unless you write the unauthenticated portions of your application outside of Vaadin or in another Vaadin container.&lt;/p&gt;
&lt;p&gt;Another problem is most of the advanced DataContainers in Vaadin want to interact directly with the datasource. However, we have services in the middle that abstract access to those systems. Configuring Vaadin to accomplish this was more difficult than it needed to be, leaving the developer with two real choices, hack around Vaadin’s plugins or use basic containers that you initialize yourself.&lt;/p&gt;
&lt;h3&gt;Very Inconsistent Plugins&lt;/h3&gt;
&lt;p&gt;To give a specific example, one of the bigger challenges was integrating with the &lt;a href="http://vaadin.com/directory#addon/lazy-query-container" target="_blank"&gt;Lazy Query Container&lt;/a&gt;. Vaadin defines interfaces to adhere to, but many of them throw &lt;code&gt;UnsupportedApplicationException&lt;/code&gt;, which makes it very difficult for the programmer to figure out what actually needs to be implemented for the desired behavior.&lt;/p&gt;
&lt;h3&gt;Odd Layout Behavior&lt;/h3&gt;
&lt;p&gt;When we started the project, we found layout to be very easy. Then we tried to make the look more like some of our existing products, which meant changing some of the default padding, margin, and sizes. All of this has to be done inside Vaadin or by overloading a Vaadin theme. Using normal stylesheets will often get you into trouble since it throws off Vaadin’s resize calculations.&lt;/p&gt;
&lt;p&gt;In one concrete example, I added a &lt;code&gt;Label&lt;/code&gt; with &lt;code&gt;HTML&lt;/code&gt; content inside of a table. After making that change, there were nearly 30 empty rows at the bottom of that table. Getting rid of the &lt;code&gt;Label&lt;/code&gt; made it work again. It took about 60 lines of Vaadin to accomplish what I had put together in 6 lines of HTML.    Also Vaadin sets every DOM element to &lt;code&gt;overflow: hidden&lt;/code&gt; so if one is not careful, all the elements will clip. Setting all the elements to have a different &lt;code&gt;overflow&lt;/code&gt; value is not trivial due to…&lt;/p&gt;
&lt;h3&gt;Thousands of HTML elements&lt;/h3&gt;
&lt;p&gt;Open Firebug on even a simple-looking page in Vaadin and you will discover elements that are nested dozens of levels deep. Therefore, even changing something simple about the box model of a specific element involves changing the elements on the tree above it. Things that are taken for granted in today’s web world, such as adjusting the size of an element in Firebug, are impossible.&lt;/p&gt;
&lt;p&gt;The raw number of elements has implications for the user experience as well. Vaadin depends heavily on javascript and javascript interpreters slow down with DOM size. Browsers also have issues rendering very large DOMs. One of our pages is a list of thumbnails with some meta information associated with them. We discovered that even on our Dual Core Macs with Google Chrome, the browser became unusable after 50 elements. Something like &lt;a href="http://www.google.com/search?q=vaadin&amp;hl=en&amp;safe=off&amp;prmd=ivnsl&amp;source=lnms&amp;tbm=isch&amp;ei=AU_xTdrXC6bh0QH0h5iQBA&amp;sa=X&amp;oi=mode_link&amp;ct=mode&amp;cd=2&amp;ved=0CBwQ_AUoAQ&amp;biw=1376&amp;bih=783" target="_blank"&gt;Google’s image search&lt;/a&gt; would not even be possible.&lt;/p&gt;
&lt;p&gt;The other problem is that animations don’t work. The browser can’t re-render the page and move objects out of the way smoothly so any animation looks jerky and odd. I didn’t go through the effort of installing Google Chrome to get a IE6 experience.&lt;/p&gt;
&lt;h3&gt;Long Cycle Times&lt;/h3&gt;
&lt;p&gt;In a normal java webapp, you can deploy an exploded war and fix interface issues (JS, CSS, and JSPS) with a reload of a page and firebug. Since it’s impossible to adjust on the fly with firebug and everything in a Vaadin app is written in Java, even a 1px width change requires a rebuild/container restart. What was 3 minutes of firebug fiddling has just turned into 30 minutes of cycling. This would have been less of a problem had we stuck with only Vaadin supplied look and feel, but that is not always an option.&lt;/p&gt;
&lt;h3&gt;Widgets are Opaque&lt;/h3&gt;
&lt;p&gt;I had what I thought was a trivial requirement. I need to have a start date and an end date. The dates can only cover a 90-day window and the end date can only be 30 days after the start date. I wanted the date widget to disable any dates outside of this range. This turned out to be &lt;a href="http://vaadin.com/forum/-/message_boards/view_message/205007" target="_blank"&gt;unsupported&lt;/a&gt;.  I almost said “impossible,” but that’s not true. I spent about a day digging through Vaadin’s source to where it interacted with GWT, back to Vaadin’s source and so on until I discovered the small change I had to make to support this feature and wrote a custom widget. However, none of this was documented wasn’t part of the official API.&lt;/p&gt;
&lt;p&gt;Whatever success I felt at finding the solution dissipated the when we attempted to upgrade the Vaadin version and discovered the the code that my new fancy date widget depended on had been removed and no substitue was readily available. Of course product didn’t want to drop the requirement, so we stuck with the old version with the working date widget.&lt;/p&gt;
&lt;h3&gt;Weird Problems with Statefulness&lt;/h3&gt;
&lt;p&gt;A Vaadin application is stateful, which has all sorts of implications. First, unless you explicitly write a “multi-windowed” application, you cannot have different sections open in different tabs. The state of one tab will update the other tab on a refresh.   Also, it is incredibly easy to screw up your error handling so that the app never recovers and the user is forced to clear their cookies before they can use the application again. We’ve even encountered this with Vaadin generated restart dialogs.&lt;/p&gt;
&lt;h3&gt;The Straw that Broke the Camel’s Back&lt;/h3&gt;
&lt;p&gt;The point where I hit the “I can’t make this work anymore” button happened when we switched to using Vaadin through SSL. The problem with using Vaadin for authentication is everything is generated through Javascript, which renders the browser’s login manager useless.&lt;/p&gt;
&lt;p&gt;Vaadin provides a solution to this problem with the &lt;code&gt;LoginForm&lt;/code&gt; widget. Vaadin generates the action for this form not through a relative path, but by reading properties from the container. However, in our case, SSL is handled by NGINX and Jetty is blissfully unaware. This works 99.9% of the time, except for Vaadin’s LoginForm, which happily attempts to send the credentials over HTTP, while the rest of the application was HTTPS giving a very unfriendly dialog in Firefox.&lt;/p&gt;
&lt;h3&gt;Analysis&lt;/h3&gt;
&lt;p&gt;I think the primary problem with Vaadin and the challenges I experience was in picking something beyond what I was comfortable with for a relatively time-boxed project. I’m far more experienced with HTML, CSS, and Javascript than I am with Swing or any other thick frameworks.&lt;/p&gt;
&lt;p&gt;Much of my early time with Vaadin was spent thinking back to how I used to do it and trying to reconcile it with how I’m used to doing it now.  Vaadin is clearly not meant for developers that have even moderate web experience. Going with more native web technologies will be far easier and deliver better results. Vaadin may still be an option if you need a team of Swing (or maybe Android?) developers to build web applications, but I don’t have enough experience with those frameworks to pass judgement.&lt;/p&gt;
&lt;p&gt;If you’ve had some experience with Vaadin, I’d love to hear your thoughts as well. It’s a framework that gets mentioned frequently among teams looking to deliver web solutions. Know where it has succeeded would be just as enlightening as me sharing my issues with it.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920310399</link><guid>http://tech.tejusparikh.com/post/10920310399</guid><pubDate>Thu, 09 Jun 2011 20:37:00 -0400</pubDate></item><item><title>Logging Standard Exceptions with Spring AOP</title><description>&lt;p&gt;One of the challenges of working on a large system with multiple developers is the management and handling of application errors and exceptions. Often, developers get frustrated with managing typed exceptions and all interfaces either throw or catch Exception. Another common approach is to change all exceptions to RuntimeException to avoid cluttering interfaces. 

An alternative approached is described in &lt;a href="http://accu.org/index.php/journals/1575" target="_blank"&gt;this paper&lt;/a&gt; by Andy Longshaw. His approach breaks exceptions into two distinct hierarchies, domain and system. Domain errors caused by logical faults in the application, such as a zero being passed as a divisor to a function. System errors are errors caused through the interaction with other components, like a network timeout when attempting to communicate with the database. Both exception types are checked exceptions, which means they must be caught and handled by each layer of the application. He presents guidelines on when and at which layer each type of exception should be logged. 

If you are using Java the obvious drawback of using checked exceptions everywhere is that each layer will be filled with code that looks like the following: 

&lt;pre lang="java"&gt;
    try {
        service.doApiCall();
    } catch(DomainException e) {
        log.error("Domain exception occurred", e);
    } catch(SystemException e) {
        log.error("System exception occurred", e);
    }
&lt;/pre&gt;

The duplication of handling of api exceptions can easily be handled with a custom annotation and Spring AOP. 

The first step is to create the Boundary logging annotation. This annotation describes where exceptions should be logged. 

&lt;pre lang="java"&gt;
    @Retention(value = RetentionPolicy.RUNTIME)
    @Target(value = {ElementType.METHOD})
    public @interface BoundaryLogger {
    }
&lt;/pre&gt;

Next, we need to create the interceptor. Along with just logging exceptions, I also choose to log the api calls. There are a few steps to creating an Aspect that can be used by Spring-AOP.

First added the &lt;code&gt;@Aspect&lt;/code&gt; annotation to the class declaration.
&lt;pre lang="java"&gt;
    @Service    // make this available as a spring bean
    @Aspect     // tell spring this class is an aspect
    public class BoundaryLoggingInterceptor {
&lt;/pre&gt;

Next, create a method that tells the Aspect to do something before the underlying method, annotated with &lt;code&gt;@BoundaryLogger&lt;/code&gt;, is called. In this example, it’s to log the method invocation. 

&lt;pre lang="java"&gt;
    @Before("@annotation(net.vijedi.springlogging.interceptor.BoundaryLogger)")
    public void logInvocation(JoinPoint jp) {
&lt;/pre&gt;

Similarly, triggering the aspect at method end can be handled with: 

&lt;pre lang="java"&gt;
    @AfterReturning(
            pointcut = "@annotation(net.vijedi.springlogging.interceptor.BoundaryLogger)",
            returning = "retVal")
    public void logComplete(JoinPoint jp, Object retVal) {
&lt;/pre&gt;

The one we are especially interested in for this purposes of this blog post is exception logging. This is the entire method for logging exceptions:

&lt;pre lang="java"&gt;
    @AfterThrowing(
            pointcut = "@annotation(net.vijedi.springlogging.interceptor.BoundaryLogger)",
            throwing = "ex"
    )
    public void processException(JoinPoint jp, Throwable ex) throws SystemException, DomainException {
        if(ex instanceof SystemException) {
            // System exceptions were logged at source
            // do not log the exception, just the return
            logReturn(jp, getLog(jp));
            throw (SystemException) ex;
        } else if(ex instanceof DomainException) {
            logException(jp, ex);
            throw (DomainException) ex;
        } else {
            logException(jp, ex);
            throw new DomainException(ex);
        }

    }
&lt;/pre&gt;

The &lt;code&gt;logException&lt;/code&gt; method is very simple:

&lt;pre lang="java"&gt;
    private void logException(JoinPoint jp, Throwable ex) {
        Log log = getLog(jp);
        log.error(ex.getMessage(), ex);
        logReturn(jp, log);
    }    
&lt;/pre&gt;

How the &lt;code&gt;logger&lt;/code&gt; is obtained is very important for accurate logging. Otherwise, it will appear that all logging messages are coming from the interceptor and not from the underlying method. Along with the confusion this could cause, it will also make it harder to use automatic log analyzers. However, it is very easy to get a logger in the context of the underlying class.

&lt;pre lang="java"&gt;
    protected Log getLog(JoinPoint jp) {
        return LogFactory.getLog(jp.getTarget().getClass());
    }
&lt;/pre&gt;

Once the Aspect has been created, the final step is to tell spring what to do when it encounters the annotation &lt;code&gt;@BoundaryLogger&lt;/code&gt;.

There are four steps, tell spring to use annotations to configure the environment, to scan the packages the annotations are in, and to create the aop environment.

&lt;pre lang="true"&gt;
    &lt;annotation&gt;&lt;/annotation&gt;&lt;component base-package="net.vijedi"&gt;&lt;/component&gt;&lt;aspectj&gt;&lt;/aspectj&gt;&lt;/pre&gt;

This is all that’s need to use annotations for logging at the tier boundaries. The complete code for the example is available at my &lt;a href="https://github.com/vijedi/Boundry-Logging-with-Spring-AOP" target="_blank"&gt;Spring Boundary Logging repo&lt;/a&gt; on Github.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920309943</link><guid>http://tech.tejusparikh.com/post/10920309943</guid><pubDate>Wed, 18 May 2011 20:55:07 -0400</pubDate></item><item><title>Stripping HTML Tags from your ActiveModel Model</title><description>&lt;p&gt;Finally a Rails post! This one is short, basic, and probably has a bunch of other examples on the net. 
Rails3 escapes HTML by default, so this isn’t strictly necessary, but I still believe that what goes into the datastore should be clean. After all, the data will probably last longer than the front-end.

I found &lt;a href="http://blog.hulihanapplications.com/browse/view/10-strip-html-in-ruby-on-rails" target="_blank"&gt;this post&lt;/a&gt; that explains how to do it for your &lt;code&gt;ActiveRecord&lt;/code&gt; models. However, I don’t have columns. Instead I used the following &lt;code&gt;before_filter&lt;/code&gt; in my model class.

&lt;pre lang="ruby"&gt;
    before_save :sanitze_html

    def sanitze_html
        @attributes.each_key do |attr|
            value = @attributes[attr]
            if(value.class == String)
                @attributes[attr] = strip_tags(value)
            end
        end
    end
&lt;/pre&gt;

It’s the same idea, but instead use the attribute map to pull the objects out. If it’s a &lt;code&gt;String&lt;/code&gt; type, call &lt;code&gt;strip_tags&lt;/code&gt;.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920309053</link><guid>http://tech.tejusparikh.com/post/10920309053</guid><pubDate>Tue, 29 Mar 2011 21:29:22 -0400</pubDate></item><item><title>Data Serialization notes with Flex4 (Actionscript 3) and BlazeDS</title><description>&lt;p&gt;Unfortunately, I’m back to developing &lt;a href="http://www.adobe.com/devnet/flex.html" target="_blank"&gt;Flex&lt;/a&gt; applications and mostly been focused on the communication layer between our Flex application and the Java backend.

Adobe’s &lt;a href="http://opensource.adobe.com/wiki/display/blazeds/BlazeDS" target="_blank"&gt;BlazeDS&lt;/a&gt; product is the easiest way to communicate between a Flex client and a Java backend. BlazeDS integrates cleanly with Spring, has annotations to expose methods as services and integrates directly with Spring security. However, like most Flex features, it has it’s quirks. 

Our model objects follow the &lt;a href="http://en.wikipedia.org/wiki/Fluent_interface" target="_blank"&gt;Fluent Interface&lt;/a&gt; pattern and we make use of method chaining to remove some of the code clutter when setting multiple properties. Furthermore, our object models are interfaces since the representations may be pulled from a large variety of backend stores. Of course, this doesn’t work with the Blaze DS serialization. This post is about all the wrong ways to do this and the explanation for why it doesn’t work. I cover my solution at the end.

&lt;!--more--&gt;

&lt;h3&gt;The (Simplified) Java Model&lt;/h3&gt;

&lt;pre lang="java"&gt;
// net.vijedi.java.User 
interface User {
    String username();
}
&lt;/pre&gt;

&lt;pre lang="java"&gt;
// net.vijedi.java.HibernateUser
@Entity
class HibernateUser implements User {
    @Column
    private String username;
    
    public String getUsername() {
        return username;
    }
    
    public User setUsername(String name) {
        username = name;
        return this;
    }
}
&lt;/pre&gt;

&lt;h3&gt;Mapping to ActionScript in all the Wrong Ways&lt;/h3&gt;

My first attempt was to map the AS object to the interface &lt;code&gt;User&lt;/code&gt;
&lt;pre lang="javascript"&gt;
// net.vijedi.as.User

[RemoteObject(alias="net.vijedi.java.User")]
class User {
    public var username:String;
}
&lt;/pre&gt;

Inspecting the &lt;code&gt;event.result&lt;/code&gt; returned in the Blaze DS callback showed that the framework had converted it to a AS &lt;code&gt;User&lt;/code&gt; object. However, the username property was &lt;code&gt;null&lt;/code&gt;. Changing the metadata to &lt;code&gt;[RemoteObject(alias="net.vijedi.java.HibernateUser")]&lt;/code&gt; yielded the same result. Likewise, changing &lt;code&gt;[RemoteObject]&lt;/code&gt; simply returned an empty &lt;code&gt;ObjectProxy&lt;/code&gt;.

The problem is in using the fluent interface pattern. Blaze DS requires the object to follow &lt;a href="http://en.wikipedia.org/wiki/JavaBean" target="_blank"&gt;Java Bean&lt;/a&gt; schematics. This means that setters must not have a return type. 

Changing the &lt;code&gt;net.vijedi.java.User&lt;/code&gt; interface to follow bean schematics didn’t have the desired effect. The ActionScript side showed an &lt;code&gt;ObjectProxy&lt;/code&gt; with the correct values set. Blaze DS sends the concrete type information as part of the return. It will still create the object, but it will not be what you want. Since AS is not a duck-typed language &lt;code&gt;event.result AS User&lt;/code&gt; will throw a runtime exception.

&lt;h3&gt;The Only Way to Do It&lt;/h3&gt;

Changing the Java class to:
&lt;pre lang="java"&gt;
class HibernateUser implements User {
    private String username;
    
    public String getUsername() {
        return username;
    }
    
    public void setUsername(String name) {
        username = name;
    }
}
&lt;/pre&gt;

and the ActionScript class to:
&lt;pre lang="javascript"&gt;
[RemoteObject(alias="net.vijedi.java.HibernateUser")]
class User {
    public var username:String;
}
&lt;/pre&gt;

This actually worked. The end result is that if you would like to use Blaze DS’s mechanisms for object serialization, the best bet is to create a set of custom value objects that are used for communication. This prevents serialization failures resulting from changes to the underlying models and frees the rest of the interfaces from being tightly coupled with the front end.

&lt;h4&gt;One Last Note about Booleans&lt;/h4&gt;

If you have a field named &lt;code&gt;boolean isEnabled&lt;/code&gt;, most IDE’s will create the getter &lt;code&gt;boolean isEnabled(){...}&lt;/code&gt;. However, Blaze DS doesn’t remap it back the same way and the Actionscript side needs to be &lt;code&gt;var enabled:Boolean&lt;/code&gt;, without the “is.”&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920308712</link><guid>http://tech.tejusparikh.com/post/10920308712</guid><pubDate>Sat, 12 Feb 2011 14:10:47 -0500</pubDate></item><item><title>Reading about How Facebook Pushes Code</title><description>&lt;p&gt;I was just reading this article found on &lt;a href="http://news.ycombinator.com" target="_blank"&gt;Hacker News&lt;/a&gt; about &lt;a href="http://framethink.wordpress.com/2011/01/17/how-facebook-ships-code/" target="_blank"&gt;the development process at facebook&lt;/a&gt;.

The line I liked the most was: 

&lt;/p&gt;&lt;blockquote&gt;
most engineers are capable of writing bug-free code.  it’s just that they don’t have an incentive to do so at most companies.  when there’s a QA department, it’s easy to just throw it over to them to find the errors.
&lt;/blockquote&gt;

I think this ties back to another point, that engineers are responsible everything (front-end, back-end, database, design) on what they create. They own that slice of the product.

Ownership is the key to getting people to act like responsible adults. When someone dumps a PSD, DB Schema, and a best practices doc on a developer, it’s too easy for the developer to pass the buck to someone else.</description><link>http://tech.tejusparikh.com/post/10920308372</link><guid>http://tech.tejusparikh.com/post/10920308372</guid><pubDate>Mon, 17 Jan 2011 14:39:26 -0500</pubDate></item><item><title>Messaging in Java</title><description>&lt;p&gt;At my current employeer, we’re starting to reach the point where we need a messaging infrastructure to scale our product. The traditional Java approach is to use a JMS broker, such as ActiveMQ. However, there’s a new alternative API in the form of AMQP. Our first use-case is a fan-out queue and I took the opportunity to see how the solution would look using both API’s within Spring. You can find the code for my proof of concept on &lt;a href="http://github.com/vijedi/messaging_poc" target="_blank"&gt;Github&lt;/a&gt;.  I’ve only included the most relevant snippets in the post, so for a real understanding on how to configure everything, look through the source.

&lt;!--more--&gt;

&lt;h4&gt;ActiveMQ&lt;/h4&gt;

The heavyweight in open source Java Messaging is ActiveMQ. ActiveMQ is a traditional JMS solution. Spring provides a template class that abstracts the communication with the JMS provider. The template requires a JMS connection factory along with a destination name. The same connection factory can be used for both sending and receiving messages by classes in the same JVM. The relevant configuration bits are as follows:

&lt;pre lang="xml"&gt;
    &lt;!--  ActiveMQ Destination  --&gt;
    &lt;queue id="destination" physicalname="${amq.destination}"&gt;&lt;/queue&gt;&lt;!-- JMS ConnectionFactory to use, configuring the embedded broker using XML --&gt;&lt;connectionfactory id="jmsFactory" brokerurl="${amq.host}"&gt;&lt;/connectionfactory&gt;&lt;bean id="jmsProducerTemplate" class="org.springframework.jms.core.JmsTemplate" connectionfactory-ref="jmsConnectionFactory" defaultdestination-ref="destination" messageconverter-ref="statMessageConverter"&gt;&lt;/bean&gt;&lt;/pre&gt;

This creates a destination queue, a connection factory with the host and the template for the producer. In this example, the consumer is configured as a &lt;code&gt;MessageListener&lt;/code&gt; and therefore, does not need a template.

The &lt;code&gt;StatMessageConverter&lt;/code&gt; is a bean that converts the payload to and from JSON. I choose to send the messages as JSON since we have a multi-language infrastructure and JSON makes it easier for those diverse systems to communicate.

With this configuration, sending a message with a JSON payload is as simple as:

&lt;pre lang="java"&gt;
    template.convertAndSend(message);
&lt;/pre&gt;


The consumer configuration is simpler. Since my consumer class implements &lt;code&gt;MessageListener&lt;/code&gt;, I just need to create a &lt;code&gt;listener-container&lt;/code&gt; and inject the bean:

&lt;pre lang="xml"&gt;
    &lt;listener container-type="default" connection-factory="jmsConnectionFactory" acknowledge="auto"&gt;&lt;listener destination="${amq.destination}" ref="jmsMessageListener"&gt;&lt;/listener&gt;&lt;/listener&gt;&lt;/pre&gt; 

Whenever the producer sends the message, the &lt;code&gt;onMessage&lt;/code&gt; method of the consumer will be called by Spring.

&lt;h4&gt;AMQP&lt;/h4&gt;

AMQP with Spring works much the same way. There is a template and a connection factory. However, AMQP is different than JMS. First AMQP is a wire-level protocol, whereas JMS is an API. Therefore, different AMQP implementations should be able to communicate with each other. Secondly, the paradigm is slightly different. In JMS, there is a queue and consumers and producers bind to that queue. In the AMQP world, producers talk to exchanges and consumers bind queues to those exchanges. Therefore the communication topology is fully within the configuration and is unknown to the code, making it trivial to go from a one-to-one exchange to a fan-out.

The AMQP provider that made the most sense was &lt;a href="http://www.rabbitmq.com" target="_blank"&gt;RabbitMQ&lt;/a&gt;. RabbitMQ is a logical choice because it has first-party java libraries and is owned by VMWare, who also own Spring, which bodes well for the project’s future.

Spring’s AMQP support requires a little more configuration compared to the JMS solution, but the basics are the same. You need connection factory, template, and a listener.  

The first difference is that there must be an administration bean:

&lt;pre lang="XML"&gt;
  &lt;bean id="amqpConnectionFactory" class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory"&gt;&lt;constructor value="${rabbit.host}"&gt;&lt;/constructor&gt;&lt;property name="username" value="${rabbit.username}"&gt;&lt;/property&gt;&lt;property name="password" value="${rabbit.pass}"&gt;&lt;/property&gt;&lt;/bean&gt;&lt;!-- Administration bean used for creating exchanges and queues --&gt;&lt;bean id="amqpAdmin" class="org.springframework.amqp.rabbit.core.RabbitAdmin"&gt;&lt;constructor ref="amqpConnectionFactory"&gt;&lt;/constructor&gt;&lt;/bean&gt;&lt;/pre&gt;

Next the send template needs both the routing key and the exchange:

&lt;pre lang="XML"&gt;
    &lt;bean id="statsExchange" class="org.springframework.amqp.core.FanoutExchange"&gt;&lt;constructor value="statsExchange"&gt;&lt;/constructor&gt;&lt;constructor value="true"&gt;&lt;/constructor&gt;&lt;constructor value="false"&gt;&lt;/constructor&gt;&lt;/bean&gt;&lt;bean id="amqpSendTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate" scope="prototype"&gt;&lt;constructor ref="amqpConnectionFactory"&gt;&lt;/constructor&gt;&lt;property name="routingKey" value="${rabbit.stat.update.queue}"&gt;&lt;/property&gt;&lt;property name="exchange" value="statsExchange"&gt;&lt;/property&gt;&lt;property name="messageConverter" ref="jsonMessageConverter"&gt;&lt;/property&gt;&lt;/bean&gt;&lt;/pre&gt;

The &lt;code&gt;statsExchange&lt;/code&gt; will create the exchange as part of it’s initialization. If the exchange already exists, it will bind to it.

Next comes the creation of the Queue:

&lt;pre lang="xml"&gt;
    &lt;bean id="statUpdateQueue" class="org.springframework.amqp.core.Queue"&gt;&lt;constructor ref="instanceId"&gt;&lt;/constructor&gt;&lt;/bean&gt;&lt;/pre&gt;

Since I want fan-out behavior, each consumer must have a unique queue name. Therefore, I use an &lt;code&gt;instanceID&lt;/code&gt; instead of a configured property. Otherwise, the same rule for exchanges applies here, the consumers will just listen on the existing queue.

The consumer is similar, but in this case we can use a regular Pojo. Since Spring’s AMQP support includes marshalling support for JSON, no special conversion needs to occur on the client side:

&lt;pre lang="XML"&gt;
    &lt;bean id="statsMessageConsumer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer"&gt;&lt;property name="connectionFactory" ref="amqpConnectionFactory"&gt;&lt;/property&gt;&lt;property name="queueName" ref="instanceId"&gt;&lt;/property&gt;&lt;property name="messageListener"&gt;&lt;!-- Use the MessageListenerAdapter to call our pre-defined handler --&gt;&lt;bean class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter"&gt;&lt;property name="delegate" ref="statsMessageHandler"&gt;&lt;/property&gt;&lt;property name="defaultListenerMethod" value="handleMessage"&gt;&lt;/property&gt;&lt;property name="messageConverter" ref="jsonMessageConverter"&gt;&lt;/property&gt;&lt;/bean&gt;&lt;/property&gt;&lt;/bean&gt;&lt;/pre&gt;

All that remains is binding the exchange to the queues:

&lt;pre lang="xml"&gt;
    &lt;bean id="statsBinding" class="org.springframework.amqp.core.Binding"&gt;&lt;constructor ref="statUpdateQueue"&gt;&lt;/constructor&gt;&lt;constructor ref="statsExchange"&gt;&lt;/constructor&gt;&lt;/bean&gt;&lt;/pre&gt;

Sending a message is identical to JMS:

&lt;pre lang="java"&gt;
template.convertAndSend(message);
&lt;/pre&gt;

&lt;h4&gt;Conclusions&lt;/h4&gt;

This little exercise was interesting because it shows that from the programmer’s perspective, there is little difference between using AMQP or JMS. With a little care in interface design, the two solutions can be swapped with minimal development effort.

For our needs, we decided to go with RabbitMQ. The solution just feels simpler for the different types of communication we need. Plus the use of an Erlang message broker feels like the right technology for the right problem.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920307876</link><guid>http://tech.tejusparikh.com/post/10920307876</guid><pubDate>Sun, 16 Jan 2011 13:11:25 -0500</pubDate></item><item><title>Going Cable TV Free</title><description>&lt;p&gt;The title of the post is just a little mis-leading. We’re not going cable free, we’ve been so for more than 3 years. I just felt compelled to write this post now because I finally have a setup that I like and is easy to use.&lt;/p&gt;

&lt;p&gt;The first thing to know about going cable free is that it’s probably going to take a while to break even on cost. If you get a bundle, the cable bill is probably a relatively small portion, especially if you pass on premium packages. So if you want to save money, get rid of the sports packages and HBO. &lt;/p&gt;

&lt;p&gt;Going solely to the web for entertainment is a tradeoff between cost and usefulness. There are plenty of devices in the $100-$150 range that provide some functionality. However, almost all of them have severe limitations. We watch movies from our hard-drives, dvds, sports from &lt;a href="http://www.espn3.com" target="_blank"&gt;ESPN3&lt;/a&gt;, &lt;a href="http://www.netflix.com" target="_blank"&gt;Netflix&lt;/a&gt;,  &lt;a href="http://www.hulu.com" target="_blank"&gt;Hulu&lt;/a&gt; and listen to music streamed through iTunes or &lt;a href="http://www.pandora.com" target="_blank"&gt;Pandora&lt;/a&gt;. There’s no set-top box, short of a PC, that can do each of those services.&lt;/p&gt;

&lt;p&gt;For simplicity of management, we stuck with Apple hardware, specifically older Mac Mini’s. Dual core Mac Mini’s are perfect for these applications because they have enough horsepower for most local HD content (up-to 720p) and have DVI and optical audio outputs, making connecting them to the home theater a snap. They are quiet as well. You can pick one up for around $300 on craigslist, which is more expensive than the dedicated set-top boxes, but it’s a real computer. We tried using linux machines, and while they were cheaper, it felt like I spent more time getting things to play rather than actually watching something. Since we made the switch to an Apple mono-culture, the setup has been rock solid. &lt;/p&gt;

&lt;p&gt;The major downside of using computers is that the interfaces aren’t designed to be accessed effectively from a remote. You need a keyboard and mouse.  We tried out a bunch of wireless input devices, both RF and Bluetooth. None of them have really worked well from the distance of our couch to our TV. The best solution we found for controlling the TV is to use our iPhones. We bought &lt;a href="http://mobilemouse.com/" target="_blank"&gt;Mobile Mouse Pro&lt;/a&gt; which is available in the App Store for $1.99. Compared to outfitting each TV with a keyboard and mouse, it’s a bargain. Since it works over WiFi, we also don’t have any range issues beyond being close enough to see the screen. &lt;/p&gt;

&lt;p&gt;There are a few free mouse applications available, but many of them didn’t provide full keyboard support. Mobile Mouse gives you access to function and control keys like escape. This makes it easy to fully do away with an attached keyboard. Mobile Mouse also reliably finds the servers on the network and wakes them from LAN, allowing me to set the boxes to go sleep when not used and save power.&lt;/p&gt;

&lt;p&gt;Since almost all the video and audio devices are hooked up to some WiFi source, I can stream the same music through the entire house. Our Airport Express supports AirPlay, but I don’t always want to listen to what I have in iTunes. I would also like to stream to the other Macs. To accomplish this, I use &lt;a href="http://www.rogueamoeba.com/airfoil/" target="_blank"&gt;Airfoil&lt;/a&gt; and have installed the &lt;a href="http://www.rogueamoeba.com/airfoil/speakers.php" target="_blank"&gt;Airfoil Speakers&lt;/a&gt; on all the machines. Then with a few clicks, I can send any audio from my desktop to anywhere in the house. Airfoil is a paid app and costs $25.&lt;/p&gt;

&lt;p&gt;Finally, for controlling the desktop while I’m in another room, I use &lt;a href="http://www.remotehd.com/Mac/" target="_blank"&gt;Remote HD &lt;/a&gt; on my iPad. Remote HD is $3.99 but is better than the free VNC clients. However, if I’m in the room with the machine, Mobile Mouse works better. It’s a bit pricey for the quality, but I’ll pay it since I don’t want to get out of bed in order to shut the music off.&lt;/p&gt;

&lt;p&gt;That describes what we do to keep ourselves entertained without cable TV. I think we’re finally at the point where we saved money compared to going with cable, but it’s still really nice to have the power of your computer on your TV.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920307354</link><guid>http://tech.tejusparikh.com/post/10920307354</guid><pubDate>Wed, 05 Jan 2011 22:19:25 -0500</pubDate></item><item><title>Macbook Air (13") Review</title><description>&lt;p&gt;The question I had to ask myself was is it really worth upgrading from a 1st gen MBA with a 1.8Ghz Core 2 Duo to a brand new one with a 1.86Ghz Core 2 Duo and could I do something better with the money.  Since I was already buying lots of gear for the upcoming trip, I put my old one up on CL and wandered over to MacMall. A few days later, I got rid of the old one, had the new one, and had a more manageable number in my bank account. &lt;/p&gt;

&lt;p&gt;This machine has been nothing but fantastic and solves every one of the problems that I had with the original. The new machine runs much cooler. Even in a warm room, its comfortable to place on your lap. For someone that uses their laptop a lot on the couch, that alone is worth a price premium. &lt;/p&gt;

&lt;p&gt;Because it’s cooler, it’s much faster. While the processor on the original was 1.8Ghz, the heat dissipation problems inevitably meant that one core would be shut down or you’d have to use a program like Coolerbook to keep it from overheating. A fully running processor coupled with 4 gigs of ram and a modern SSD makes for a very quick machine.&lt;/p&gt;

&lt;p&gt;The last two points are more about how this version is not DOA. What makes the 13” the perfect traveling laptop is that along with the sleek looks and low weight, it’s really capable of doing everything you need. The extra resolution of the screen, up to 1440x900 from 1280x800 transforms picture management, programming, and video creation from an ordeal to possible. On this trip I’ve written some PHP, poked around a little with new search engines that are written in JAVA, edited videos of our house to show to our family that haven’t been to the states recently. And I did all that without pulling my hair out or getting frustrated at the computer. Sure, it’s clearly slower than my quad core desktop and has less storage that my wife’s 13” Macbook Pro, but it’s more than adequate for everything I need to do when I’m not near my desk or home.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920306947</link><guid>http://tech.tejusparikh.com/post/10920306947</guid><pubDate>Mon, 06 Dec 2010 07:32:23 -0500</pubDate></item><item><title>Ruby Full Text Search Performance: Thinking Sphinx vs Sunspot Solr</title><description>&lt;p&gt;Full text search support has come a long way since the early days of &lt;a href="http://www.davebalmain.com/trac" target="_blank"&gt;Ferret&lt;/a&gt;. I’ve been using &lt;a href="http://blog.evanweaver.com/files/doc/fauna/ultrasphinx/files/README.html" target="_blank"&gt;Ultrasphinx&lt;/a&gt; for a few years, and while it runs great, it doesn’t work out of the box with Rails 3.

Two search projects that seem to be garnering a lot of support from the community are &lt;a href="http://freelancing-god.github.com/ts/en/" target="_blank"&gt;Thinking Sphinx&lt;/a&gt; and &lt;a href="http://outoftime.github.com/sunspot/" target="_blank"&gt;Sunspot&lt;/a&gt;. 

Thinking Sphinx is the most logical successor to Ultrasphinx, since both utilize &lt;a href="http://sphinxsearch.com/" target="_blank"&gt;Sphinx&lt;/a&gt; as the search server. Sphinx works by reading information out of the database to build the search index. Communication with the Sphinx server occurs by sharing C “objects” over sockets.

Sunspot uses &lt;a href="http://lucene.apache.org/solr/" target="_blank"&gt;Solr&lt;/a&gt;, a Java search server built on the Lucene search library. Sunspot communicates with Solr through its REST API, using XML. Although the search engine is written in Java, Sunspot bundles a version of Solr that runs as a standalone server to make deployment just as easy as Thinking Sphinx.

Solr is a compelling alternative to Sphinx, since the most scalable Web apps (Facebook, Twitter) use Java behind the UI layer. Solr servers can be clustered and since they manage the index, Sunspot can automatically update the indexes when the model objects change. There’s no need to run a cron job to reindex the data or setup delta indexing like with Thinking Sphinx.

However, the impact of XML serialization/deserialization required for communicating with Solr on performance worries me. Processing XML documents is not as fast as unpacking C objects.

In order to test this difference, I created a &lt;a href="https://github.com/vijedi/Ruby-Search-Comparison" target="_blank"&gt;little benchmark&lt;/a&gt; to measure the relative impact. The Readme describes the test in more detail along with providing the source and instructions so you can configure it to your needs. 

To give the test a slightly more realistic scenario, the benchmark was run within my Ubuntu VM while communicating with the search process running on my OSX host. The host box has four cores clocked at 2.66 GHz each. The Ubuntu VM had one core dedicated to it. There was plenty of ram available for both the search engine and the benchmark task processing the search results. Mostly I did this to ensure that Thinking Sphinx wasn’t cheating by using unix sockets for communication.

I did 50,000 searches and printed out a timing after every 5000 searches. These are the results:

&lt;pre&gt;
Runs    Thinking Sphinx       Sunspot
5000              38.49       1611.60
10000             38.54       1648.51
15000             39.06       1614.52
20000             38.86       1583.53
25000             39.78       1613.79
30000             38.83       1595.60
35000             38.34       1571.96
40000             38.06       1631.87
45000             37.57       1603.31
50000             38.23       1634.53
Total            385.80      16109.26
&lt;/pre&gt;

I had expected Thinking Sphinx to be faster, but not 45 times faster. Extrapolating the numbers out, one can run 200,000 searches in the time it takes Solr to run 5,000. 

This was just a rough test to see the relative difference and is purely based on read performance of a few hundred records. It’s possible that proper tuning could improve performance or frequent re-indexing could degrade Thinking Sphinx’s performance, but it’s hard to see that chasm closing enough for there to be comparable performance when the search index can fit on one machine.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920305822</link><guid>http://tech.tejusparikh.com/post/10920305822</guid><pubDate>Fri, 05 Nov 2010 09:25:03 -0400</pubDate></item><item><title>Evaluating Vaadin: A Java Web Application Framework</title><description>&lt;p&gt;&lt;a href="http://vaadin.com" target="_blank"&gt;Vaadin&lt;/a&gt; is an interesting RIA platform built by Vaadin, LTD. Vaadin differs from your standard RIA by existing almost exclusively on the server. All application state remains on the server and all events are handled through communication with the server. The display layer is written as a layer above GWT and the whole project is open source and free. This evaluation post is the first in a series of my lessons learned while evaluating this framework.

Vaadin is a good fit for all the web-applications that fit in the general bucket of “enterprise support tools.” The reasons why are covered after the jump.

&lt;!--more--&gt;
&lt;/p&gt;&lt;h3&gt;What’s special about it?&lt;/h3&gt;
I think the biggest departure from the frameworks that I’ve been using for web programming is that Vaadin is stateful. The client state is tied in the session with a state on the server. This has some major implications for deployment, such as requiring sticky-sessions in load-balancing and shared caches for failover. 

The developers of Vaadin made the framework stateful to facilitate building all the interaction code on server. The browser is only used for display. This means that you can use your ordinary Java toolset to walk through your event handling. You don’t need firebug or any javascript knowledge, unless you are creating a custom widget. The &lt;a href="http://vaadin.com/book/-/page/preface.html" target="_blank"&gt;Book of Vaadin&lt;/a&gt; provides lots of detail on this model in their &lt;a href="http://vaadin.com/book/-/page/architecture.html" target="_blank"&gt;chapter on Architecture&lt;/a&gt;.

I have no desire to repeat the documentation here, but just provide enough of a glimpse in case you are more interested.

&lt;h3&gt;Would I use it?&lt;/h3&gt;
I think Vaadin fits in nicely within a specific niche. I would not use it for a normal website (nor do they recommend it), nor would I use it for a consumer-facing or heavily trafficked web application. The stateful model just doesn’t scale like that. 

However, there’s a whole other class of applications, management consoles, intranet web-apps and other systems that could just live on one server that are a perfect fit for Vaadin. Even more so if you can control which browsers the users run (IE javascript is really slow). These are the things that I really liked about the product:

&lt;ul&gt;&lt;li&gt;Complete documentation. You don’t have to dig through a user-generated wiki. They have the whole book up on the website.&lt;/li&gt;
&lt;li&gt;Friendly forums. A search shows multiple people that had the same problem. Instead of the usual, “use the search function,” that you see on a lot of other forums, there were real replies.&lt;/li&gt;
&lt;li&gt;All java. A developer can build an entire web-application with just Java. That’s really important if web-application programming isn’t a core competency.&lt;/li&gt;
&lt;li&gt;Doing things the Vaadin way is really easy. For instance, the &lt;a href="http://vaadin.com/addon/hbncontainer" target="_blank"&gt;hbncontainer&lt;/a&gt; makes building an app around hibernate trivial.&lt;/li&gt;
&lt;li&gt;The widgets really work like their desktop equivalents. The table responds to keystrokes and the split panels work.&lt;/li&gt;
&lt;li&gt;Vaadin hides the complexities of layouts on the web. You just specify your container strategy.&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;Were there problems?&lt;/h3&gt;

While Vaadin is pretty easy and built on a language I’m familiar with, there was still a learning curve. Most of my issues came from doing things outside of the Vaadin way.

&lt;ul&gt;&lt;li&gt;Vaadin and Maven don’t seem to get along too well. Trying to install the &lt;a href="http://vaadin.com/addon/visualizationsforvaadin" target="_blank"&gt;Visualizations&lt;/a&gt; plugin was a nightmare. Eventually I had to install it and its dependent sources into my test project to build the widget set.&lt;/li&gt;
&lt;li&gt;Documentation and examples on how to leverage your existing DAO layers was sparse and incomplete.&lt;/li&gt;
&lt;li&gt;The same goes for Spring integration, esp Spring Security.&lt;/li&gt;
&lt;/ul&gt;&lt;h3&gt;Conclusion&lt;/h3&gt;

If had to build a web app and didn’t have a web team, Vaadin is good way to go. You can build apps that have more than the basic “developer” look and feel without a whole lot of effort. The documentation lapses will surely disappear as the framework gains steam. 

The next post I’m going to write is about how to use your existing DAO structure with Vaadin.</description><link>http://tech.tejusparikh.com/post/10920305136</link><guid>http://tech.tejusparikh.com/post/10920305136</guid><pubDate>Thu, 05 Aug 2010 15:54:53 -0400</pubDate></item><item><title>Creating a Custom XSLT Function in Saxon HE</title><description>&lt;p&gt;In our XSTL workflow we make use of a lot of XPATH 2.0 features, such as it’s built-in regex support. Unfortunately, the default Java6 XML parsers only support XPATH 1.0.  The library we settled on is &lt;a href="http://saxon.sourceforge.net/#F9.2HE" target="_blank"&gt;Saxon HE&lt;/a&gt;, since it was free, supported the features we needed, and could be extended with Java functions.

One of my tasks was to convert all relative paths in an XHTML document to absolute paths. The server prefix was set as variable in the stylesheet. The transformer would have to determine if the selected path is a relative url, then work to resolve what the absolute path is based on the root passed into the page. It could be done with an advanced XSTL template, but since we already had the resolution function written in Java, it made more sense to write a Java plugin to Saxon. One of the missing features of Saxon HE is the seamless, reflection based integration of plugins. However, one can use the Extension Function API to achieve the same results.
&lt;!--more--&gt;
First on the agenda is creating an extension point:
&lt;pre lang="java"&gt;
package net.vijedi.saxon.extensions;

import net.sf.saxon.expr.StaticProperty;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.functions.ExtensionFunctionCall;
import net.sf.saxon.functions.ExtensionFunctionDefinition;
import net.sf.saxon.om.*;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.StringValue;

public class AbsolutizeUrl extends ExtensionFunctionDefinition {
    /**
     * The function will need a name you can call
     */
    private static final StructuredQName qName =
            new StructuredQName("", 
                    "http://vijedi.net/", 
                    "absolutizeUrl");

    @Override
    public StructuredQName getFunctionQName() {
        return qName; 
    }
}

&lt;/pre&gt;

The extension point extends &lt;code&gt;ExtensionFunctionDefinition&lt;/code&gt;. I went ahead and created a constant that will store the name of the class and the function to return it. You will use this to access the function from inside of your XSLT.

Now it’s time to think about the interface of this function. The function can take up to two string parameters, the absolute url base, and an optional url to process. The url to process is optional since it is not a requirement that an &lt;code&gt;&lt;a&gt;&lt;/code&gt; will have an &lt;code&gt;href&lt;/code&gt; attribute. The function will return either a string or null if the second parameter does not exist. This is how you define this interface in the code.

&lt;pre lang="java"&gt;
private final static SequenceType[] argumentTypes = new SequenceType[] {
        SequenceType.SINGLE_STRING,
        SequenceType.OPTIONAL_STRING
};

@Override
public int getMinimumNumberOfArguments() {
    return 1;
}

@Override
public int getMaximumNumberOfArguments() {
    return 2;
}

@Override
public SequenceType[] getArgumentTypes() {
    return argumentTypes;  
}

@Override
public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
    return SequenceType.makeSequenceType(
            suppliedArgumentTypes[0].getPrimaryType(), StaticProperty.ALLOWS_ZERO_OR_ONE);
}
&lt;/pre&gt;

Once the interface is defined, it’s time to define the actual work. The actual call is handled by a class that extends &lt;code&gt;ExtensionFunctionCall&lt;/code&gt;. I like to define these as inner classes of the &lt;code&gt;ExtensionFunctionDefinition&lt;/code&gt;.  The pattern for this class is pretty simple. You need to process the arguments to the function. Saxon will give you wrapped arguments that you will need to unwrap. Then you need to call the actual logic (which should be in a separate class for re-usability) and finally wrap and return the value.  Just as crucially, you need to override the function that tells the Saxon parser to use your implementation of &lt;code&gt;ExtensionFunctionCall&lt;/code&gt; for this definition.

&lt;pre lang="java"&gt;
    @Override
    public ExtensionFunctionCall makeCallExpression() {
        return new AbsolutizeUrlCall(); 
    }

    private static class AbsolutizeUrlCall extends ExtensionFunctionCall {

        @Override
        public SequenceIterator call(SequenceIterator[] arguments, XPathContext xPathContext) throws XPathException {

            StringValue pageUrlSV = (StringValue) arguments[0].next();
            if(null == pageUrlSV) {
                return EmptyIterator.getInstance();
            }

            StringValue hrefUrlSV = null;
            if(arguments.length &gt; 1) {
                hrefUrlSV = (StringValue) arguments[1].next();
                if(null == hrefUrlSV) {
                    return EmptyIterator.getInstance();
                }
            }
            
            String pageUrl = pageUrlSV.getStringValue();
            String hrefUrl = hrefUrlSV.getStringValue();

            // Url transformation magic goes here

            Item item = new StringValue(fullUrl);
            return SingletonIterator.makeIterator(item);  
        }
    }
&lt;/pre&gt;

That completes the definition of the function. You can find the full example code on &lt;a href="http://gist.github.com/487428" target="_blank"&gt;GitHub&lt;/a&gt;.

Now that you’ve written an extension, you need to tell Saxon that this function exists. For this, you will need to add the following to wherever you are currently accessing the &lt;code&gt;TransformerFactory&lt;/code&gt;.

&lt;pre lang="java"&gt;
private TransformerFactory getTransformerFactory() throws net.sf.saxon.trans.XPathException {
    TransformerFactory tFactory = TransformerFactory.newInstance();
    if(tFactory instanceof TransformerFactoryImpl) {
        TransformerFactoryImpl tFactoryImpl = (TransformerFactoryImpl) tFactory;
        net.sf.saxon.Configuration saxonConfig = tFactoryImpl.getConfiguration();
        saxonConfig.registerExtensionFunction(new AbsolutizeUrl());
    }
    return tFactory;
}
&lt;/pre&gt;

This code checks to see whether or not you’re using a Saxon processor, and if so, registers your new function within it.

Finally, it’s time to update the stylesheet to use the new function. You’ll need to add the function to the namespace, using the same parameter found in the second argument of the &lt;code&gt;StructuredQName&lt;/code&gt; constructor.

&lt;pre lang="xml"&gt;
&lt;stylesheet xsl="http://www.w3.org/1999/XSL/Transform" vn="http://vijedi.net/" version="2.0"&gt;&lt;/stylesheet&gt;&lt;/pre&gt;

Now you can use it like any other function:
&lt;pre lang="xml"&gt;
&lt;attribute name="href"&gt;&lt;value select="vn:absolutizeUrl('http://www.example.com/absolutepath', @href)"&gt;&lt;/value&gt;&lt;/attribute&gt;&lt;/pre&gt;&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920304532</link><guid>http://tech.tejusparikh.com/post/10920304532</guid><pubDate>Fri, 23 Jul 2010 09:31:13 -0400</pubDate></item><item><title>Keeping Test Emails out of the Wild In Rails</title><description>&lt;p&gt;There are a few cardinal sins for a developer: deleting the production database, deploying code to the wrong machine, and sending out emails to all the mock users. These situations happen because the terminal window on production looks an awful lot like the terminal window on dev.  I don’t have solutions to the first two problems, but preventing emails to the test user database is pretty easy in Ruyb on Rails.
&lt;!--more--&gt;
Two solutions I’ve found are &lt;a href="http://github.com/pboling/sanitize_email" target="_blank"&gt;santize_email&lt;/a&gt; and &lt;a href="http://github.com/myronmarston/mail_safe" target="_blank"&gt;mail_safe&lt;/a&gt;.  These are both ActiveRecord extensions that allow the user to set an override address that will be the recipient of the email.

&lt;code&gt;Sanitize_email&lt;/code&gt; is the first solution I tried.  It’s configuration is straight forward and it can either be installed as a plugin or gem. Personally, I like gems because they can be shared across multiple projects. Once you’ve installed the gem, you need to configure an initializer with the following (from their README):

&lt;pre lang="ruby"&gt;
    # Settings for sanitize_email gem.  These can be overridden in individual config/%env%/environment.rb files.

    require 'sanitize_email'
    ActionMailer::Base.sanitized_recipients = "jtrupiano@gmail.com"
    ActionMailer::Base.sanitized_bcc = nil
    ActionMailer::Base.sanitized_cc = nil

    # optionally, you can configure sanitize_email to to include the "real" email address as the 'user name' of the
    # "sanitized" email (e.g. "real@address.com &lt;sanitized&gt;")
    ActionMailer::Base.use_actual_email_as_sanitized_user_name = true # defaults to false

    # These are the environments whose outgoing email BCC, CC and recipients fields will be overridden!
    # All environments not listed will be treated as normal.
    ActionMailer::Base.local_environments = %w( development test staging )
&lt;/sanitized&gt;&lt;/pre&gt;

You can set the configuration to override the recipients, the cc, and the bcc.  One could use &lt;code&gt;sanitize_email&lt;/code&gt; to automatically set a bcc for all production emails, along with setting all three to prevent emails from going into the wild.  Another neat feature is that it provides all Mailers with the &lt;code&gt;force_sanitize&lt;/code&gt; method, which programmatically traps emails through a specific path.

&lt;code&gt;Mail_safe&lt;/code&gt; is available strictly as a gem.  It’s configuration is a little simpler.  The following is the basic config from their README:

&lt;pre lang="ruby"&gt;
  if defined?(MailSafe::Config)
    MailSafe::Config.internal_address_definition = /.*@my-domain\.com/i
    MailSafe::Config.replacement_address = 'me@my-domain.com'
  end
&lt;/pre&gt;

It doesn’t allow distinct addresses for bcc, cc, and recipients, preventing it’s use for automatic override addresses.  While it lacks that feature, it does allow addresses for white-listed domains to be delivered, as well as allowing users to provide a proc for the options settings.  For example:

&lt;pre lang="ruby"&gt;
    MailSafe::Config.internal_address_definition = lambda { |address|
      address =~ /.*@domain1\.com/i ||
      address =~ /.*@domain2\.com/i ||
      address == 'full-address@domain.com'
    }

    # Useful if your mail server allows + dynamic email addresses like gmail.
    MailSafe::Config.replacement_address = lambda { |address| "my-address+#{address.gsub(/[\w\-.]/, '_')}@gmail.com" }
&lt;/pre&gt;

Our choice was to use &lt;code&gt;mail_safe&lt;/code&gt; since it did allow white-listed domains to be delivered normally. This fit the feature set of giving us a safety net incase our mock data got pushed to a system with a live mail-server, while still enabling our test users to use the application.&lt;/p&gt;</description><link>http://tech.tejusparikh.com/post/10920303511</link><guid>http://tech.tejusparikh.com/post/10920303511</guid><pubDate>Tue, 29 Jun 2010 23:24:47 -0400</pubDate></item></channel></rss>

