Blog
Thoughts on programming, systems, robotics, and everything in between, sharing what I learn and build.

Unit Testing for Spring MVC Controllers
Once the services, DAO, and supporting classes are tested, it’s time for the controller. Controllers are often the hardest layer to test, so many developers (based on observation) reach for Selenium or, worse, test by hand. That works, but it makes exercising individual logic branches awkward and slow, and no one wants to wait for a browser to spin up before checking in code. The Spring MVC Test framework solves this by driving full controller logic through fast unit tests, and it has lived in Spring’s core ever since Spring 4.
Spring 4 MVC Hello World Tutorial Using Maven
In this tutorial we build the smallest useful Spring MVC application: a controller that reads a request parameter and renders it in a JSP view. It is the classic “Hello World”, but the wiring it shows (a DispatcherServlet, a bean configuration, and a view resolver) is the same wiring every larger Spring MVC application is built on. Note: This tutorial has been updated for Spring Framework 7. It was originally written in 2014 for Spring 4 and the javax.* servlet API; the configuration below now uses the jakarta.* namespace, drops the Eclipse-specific setup for a plain Maven command, and runs on Jakarta EE 11 (Tomcat 11+). We keep XML configuration and web.xml so every piece of the wiring stays visible. The same beans map one-to-one onto a @Configuration class if you prefer Java config.
Jenkins Installation and Configuration with Maven and GitHub
In this tutorial we install Jenkins and configure it to build a Maven project hosted on GitHub. Note: This post has been updated for Jenkins 2.5x running on Java 21. The original 2014 version deployed Jenkins as a WAR inside Tomcat 7 on Java 7 and walked through a UI that has since changed substantially. Modern Jenkins is self-contained, so you no longer need a separate servlet container, and Git/Maven support now ships with the suggested plugins. The setup below is therefore shorter than it used to be.
Zend Framework 2: Get Parameters
The easiest way to read request parameters in a Zend Framework 2 controller is the Params plugin, introduced in beta5. It has utility methods to make it easy to access different types of parameters. As always, reading the tests can prove valuable to understand how something is supposed to be used. Note: Zend Framework 2 has been deprecated. The project moved to the Linux Foundation in 2019 and lives on as Laminas; the Zend\ namespace became Laminas\, so the plugin shown here is now Laminas\Mvc\Controller\Plugin\Params (in the laminas/laminas-mvc package). The API is unchanged, so the examples below still apply after that rename.
Zend Framework 2: Redirect to 404 page in Controller
I’ve been getting into trouble for several hours with redirecting to the 404 page in Zend Framework 2. Note: Zend Framework 2 has been deprecated. Zend Framework was migrated to the Laminas Project in 2020, where development continues today. The notFoundAction() technique below still applies in laminas-mvc. I asked about this on Stack Overflow. What Didn’t Work Before that, I was using the following code: $this->getResponse()->setStatusCode(404); return; This sets the HTTP status code to 404, which looks fine at first. But it only changes the response header; it doesn’t dispatch the error controller, so once I built a custom 404 page I found that it never rendered.
How To Convert Byte[] Array To String in Java
It is common to convert a String into a byte[] array and back again. The catch is that how you convert depends on what the bytes actually are: human-readable text in some encoding, or arbitrary binary data such as the output of a cipher. Using the wrong approach silently corrupts your data. Note: This post has been updated to always specify a charset explicitly and to cover the binary-data case. The original advice — new String(bytes) — relies on the platform’s default charset, which makes the result differ from machine to machine, and it cannot round-trip binary data at all. Both pitfalls are addressed below.
Building Vim from Source
Most Linux distributions ship a stripped-down Vim — often without +python3, +clipboard, or GUI support, and rarely the newest release. Building Vim yourself fixes all of that: you decide exactly which language interpreters and features get compiled in, and you get whatever version is on Vim’s master branch. The process is straightforward. This guide walks through it on a Debian-based distro such as Ubuntu. Note: This post has been updated from its original 2013 version to match how Vim is built today. The source has moved from vim.org’s Mercurial repository to GitHub, the Python 2 interpreter has been swapped for Python 3 and the GTK2 GUI for GTK3, and configure flags that newer Vim removed (such as --enable-sniff and the now-default --enable-multibyte) have been dropped.
Install PHP and PHPUnit on Windows/Ubuntu
Note: This post has been updated for PHP 8.5 and PHPUnit 13. The original 2013 version installed PHPUnit through PEAR (go-pear, pear channel-discover pear.phpunit.de), but PEAR has since been retired and PHPUnit no longer ships through it. The current approach is to install PHPUnit with Composer or as a standalone PHAR, both shown below. PHPUnit is the de-facto testing framework for PHP. This guide gets PHP and PHPUnit running on Windows and Ubuntu, then writes and runs a first test to confirm the setup works.