Beer from afar

Posted by Cameron Stokes on March 06, 2010
beer / No Comments

I’m a beer lover.  I don’t hide it, I don’t deny it, I think and talk way too much about beer.  The other night I had a dream that our Scotch ale (currently in the fermenter) turned out to be the best beer ever.  One of the many upsides to this obsession is that friends and family know how much I love beer and help feed my obsession.  Case in point…just this week I received two special deliveries!

The first delivery was from a friend who just returned from California.

California Delivery

California Delivery

From left to right: Brew Free or Die IPA from 21st Amendment Brewery, Hitachino Nest White Ale and Hitachino Nest Red Rice Ale from Kiuchi Brewery, and Pliny the Elder from Russian River Brewing Company.

The next delivery came by way of my Grandmother from North Carolina.  There’s a great little beer store in her town and she’s recently started going and asking the owner about beers that I might like.

Beer from North Carolina

North Carolina Delivery

From left to right again: Fourteen Ale from Wyerbacher, Celebrator Doppelbock from Ayinger Bier, Dragon’s Milk from New Holland Brewing Company, Urthel Samaranth from De Leyerth Brouwerijen, and Samichlaus from Castle Brewery Eggenberg.

Some of these I could likely find in Georgia but don’t think I’ve seen any of them before.  I’m fairly certain I could find the Hitachino Nest beers locally but I know for a fact 21st Amendment and Russian River do not distribute to Georgia, though I hear 21st Amendment will be starting soon.  I can’t wait to try each of these beers but am most excited about Dragon’s Milk, Pliny the Elder, and Fourteen Ale.

In other beer news, I’ve posted photos of the Winter Beer Carnival Rhonda and I attend last weekend; it was a blast!  Photos are here.

Tags:

Announcing kui!

Posted by Cameron Stokes on February 05, 2010
java, kui / No Comments

I am excited to announce the initial release of kui!  kui is a modern, browser-based administration tool for Java applications supporting the JMX specification.  While tools already exist to monitor Java applications using JMX, kui takes a different approach to cure your JMX woes!

Key features of kui are:

  • Browser-based: Once installed, all you need is a browser to access your MBeans.
  • Easy-to-use interface: kui provides a familiar and consistent interface for viewing and administering your MBeans.
  • Standards based: kui works with a wide variety of application servers and browsers.
  • Pure Java and JavaScript: kui is written using Java and JavaScript for easy modifications.
  • Open source: kui is distributed under the New BSD License.

Head on over to the kui website for more information, screenshots, and available downloads.

Tags: ,

Getting things done with a list

Posted by Cameron Stokes on December 30, 2009
random / No Comments

I consider myself a very focused and productive person, but over the past couple of weeks I’ve realized that I am much more productive when working from a task list.  The list keeps my mind from wondering to other tasks and I get a great satisfaction in checking tasks off and reviewing the list at the end of the day to see what I have accomplished.  I have some ideas on how to improve my list (and digitize it); let’s see how much more productive I can get!

This week’s task list:

My latest to-do list

This week's task list

Tags:

Intercepting controllers in Spring MVC

Posted by Cameron Stokes on December 26, 2009
software development, technical / No Comments

Working on my latest project the past couple days I was trying to figure out a way to enforce authentication for some requests but not others.  I first wrote a Filter but when I started mapping the filter to my specific URLs I realized how tedious this could become.  I then remembered that Spring allowed for interceptors in its web framework and after a quick glance through their documentation I found the section I was looking for.  Unfortunately this still wasn’t exactly what I needed as Spring applies your interceptors to all requests configured in your handler mapping.  Looking at the HandlerInterceptor API I found I had access to the handler that was being processed and I just needed to decorate my handlers that needed authentication and adjust my interceptor to first check the handler.  I decided to create an empty Interface named AuthenticatedController which my controllers could implement to indicate they needed to be protected from unauthenticated access.  You could also do this using annotations, but here’s my code:

AuthenticatedController.java

public interface AuthenticatedController {
    // This is empty on purpose.
}

SimpleController.java

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

public class StateController implements AuthenticatedController {

    public ModelAndView handleRequest( final HttpServletRequest httpServletRequest,
            final HttpServletResponse httpServletResponse ) throws Exception {
        ...
    }

}

AuthenticationInterceptor.java

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

public class AuthenticationInterceptor extends HandlerInterceptorAdapter {

    public boolean preHandle( HttpServletRequest request, HttpServletResponse response,
            Object handler ) throws Exception {

        if ( !( handler instanceof AuthenticatedController ) ) {
            // Authentication not needed, allow request to continue.
            return true;
        }

        boolean isAuthenticated = checkAuthentication(...);

        if ( !isAuthenticated ) {
            // User is not authenticated, handle response as needed, and halt processing.
            response.setStatus( HttpServletResponse.SC_FORBIDDEN );
            return false;
        }

        // User is authenticated, allow request to continue.
        return true;
    }
}

spring-beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean name="authenticationInterceptor" class="custom.AuthenticationInterceptor" />

<bean name="urlMapping"
    class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="interceptors">
         <list>
	     <ref bean="authenticationInterceptor" />
	</list>
    </property>
    <property name="mappings">
	<props>
            <prop key="/controller1.json">controller1</prop>
            <prop key="/controller2.json">controller2</prop>
            <prop key="/controller3.json">controller3</prop>
        </props>
    </property>
</bean>

</beans>

Tags: , ,

Using svnversion from Ant

Posted by Cameron Stokes on December 12, 2009
software development, technical / No Comments

At work we use a combination of Subversion (svn), Maven, and Ant to build and deploy our applications and integrate the svn revision number into our deployment packages.  As an example, if we’re packaging our callcenter application our build scripts will create a callcenter-7175.jar package.  This makes it easy for us to upgrade and rollback between versions as needed.

The svnversion program makes it easy to get the revision number of your working copy by simply executing the program:

macbookpro:rel-091105 stokesc$ svnversion
7175

To use this from Ant we can use the exec task. The example below will execute svnversion and capture its output into the Ant property repository.revision which is used later on in our build script:

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Build Script" default="make" basedir=".">

    <target name="make">

        <!-- Get current working directory. -->
        <exec executable="pwd" outputproperty="dir.root" />

        <!-- Get subversion revision number. -->
        <exec executable="svnversion" outputproperty="repository.revision" />

        <echo message="Repository revision is ${repository.revision}" />

    </target>

</project>

This worked well for us for a few years but when we needed to build from an older branch the revision number wasn’t representative of the last revision in the branch.  Looking at the options for svnversion I found passing -c will return the revision number of the last change rather than the current revision which is what we really wanted.

macbookpro:rel-091105 stokesc$ svnversion -c
1:6985

You can see the difference in revision numbers from this command versus the one above, but this still isn’t perfect due to the starting revision number that’s been added.  A little change to our Ant script can strip this off for us.  Here we use the redirector and filterchain types and a regular expression to modify the output.

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="Build Script" default="make" basedir=".">

    <target name="make">

        <!-- Get current working directory. -->
        <exec executable="pwd" outputproperty="dir.root" />

        <!-- Get subversion revision number. -->
        <exec executable="svnversion" outputproperty="repository.revision">
            <!-- Specify '-c' to get last changed rather than current revisions. -->
            <arg value="-c" />
            <!-- Use redirector/filterchain to parse output.
                 svnversion -c will return output in format [initial]:[current]
                 and we want to strip off [initial]: -->
            <redirector>
                <outputfilterchain>
                    <tokenfilter>
                        <replaceregex pattern="[0-9]+\:" replace="" />
                    </tokenfilter>
                </outputfilterchain>
            </redirector>
        </exec>

        <echo message="Repository revision is ${repository.revision}" />

    </target>

</project>

We’re now able to go back and package older versions of our application with a true indication of their svn revision.

Tags: , , , ,