Java Ninja Chronicles By Norris Shelton

Things I learned in the pursuit of code

This is what you get when you try to test code that relies on Java EE APIs. You can compile the code because the javaee;javaee-api;5 dependency has stubs for the methods. Unfortunately, it does not contain implementations for the methods which causes your tests to blow-up. You get around this by including the implementation BEFORE tha javaee5 dependency.

Glassfish 2


Glassfish 3


April 9th, 2012

Posted In: Java, JUnit, Maven

Leave a Comment

We added Springframework to a legacy application. We encountered places where we needed access to Springframework beans by non-Spring beans. The Spring context was loaded by:

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

The appeared to work fine, but what we did not realize until we looked at the logging was that the Spring context was refreshed every time this was called. This is a no-no when you have over 1000 classes under packages to be scanned.

The correct way is by:

ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

This worked for the Servlet API objects. We had some POJOs that did not have access to the Servlet API. We were already performing special processing via a filter to add various objects to the current context by using ThreadLocal.

April 4th, 2012

Posted In: Java, Spring

Tags: ,

Leave a Comment

Normally, I have been able to generate a Soap client and be on my way. This particular time I had to perform some business logic on the client. One of the first things that I encountered was the nuisance of debugging classes without a toString() implementation. It’s no biggie, but it does waste time when you have to open a class to inspect it’s contents. When it has a toString() implementation, your editor will generally use this to display the class. Making one less step that I have to perform.

The business logic I had to implement involved splitting a list of items into two groups, according to the value of one of the properties. In addition, if the object was already in the list, but had a different address, I had to add the current address to the existing object instead of adding it again. Great. Now I need to be able to identify an object in a list. I found that JAXB-2 Basics added implementations of equals() and hashcode() methods.

Just when I thought I was done, I had to add the serializable interface because the web application is marked as distributable. This wasn’t provided by JAXB2-Basics and I had to use an XML binding to add that.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""



        <!-- Jetty is needed if you're are not using the CXFServlet -->

            Spring dependencies - needed to force a newer version than CXF used


                                    <!--note: Started getting errors by having this hit their URL directly-->

To use JAXB2-Basics, I added the module dependency starting at line 52. I also added a dependency for the cxf-codegen-plugin at line 93. After that, I had to add the at line 83.

  • -xjc-XtoString – triggers the generation of the toString() method
  • -xjc-Xequals – triggers the generation of the equals() method
  • -xjc-XhashCode – triggers the generation of the hashcode() method

The jaxb binding took a bit more work, but was fairly easy also. I specified the binding file on line 80. ${basedir} is a maven variable that is set to the directory of the module. The binding file is fairly straight forward. I specified a global binding that said serializable. I also specified the optional uid. If the uid is specified, then the value will be specified in the classes. NOTE: that the same uid value will be specified for all classes.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings version="2.0" xmlns:jaxb="">
            <jaxb:serializable uid="1"/>

April 3rd, 2012

Posted In: Java, Maven, xml

Tags: , ,

Leave a Comment

I have a JSP tag file named collapsiblePanel with the following attribute declaration for a JSP fragment.

<%@ attribute name="content" required="true" fragment="true"
              description="Passed as fragment, renders content1 inside of panel." %>

I am using the tag around some output to create a collapsed panel.

                <tags:collapsiblePanel id="principalsSection"
                                       heading="Principals (${fn:length(business.principals)} Found)">
                    <jsp:attribute name="content">
                        <c:if test="${not empty business.principals}">
                            <div class="jx-container">
                                <table class="jx-table">
                                        <c:forEach var="principal" items="${business.principals}" varStatus="status">
                                            <tr class="${jxp:rowClass(status)}">
                                                    ${} ${} ${}

The collapsible panel adds an arrow before the heading and makes the arrow and the headging a clickable area that will trigger the uncollapse. I did not want to add the arrow or the clickable area if there wasn’t anything to uncollapse. I tried to test for this by saying

<c:if test="${empty content}">

This is supposed to work, but in Glassfish 2.1.1 content contains the reference to the content fragment. I worked around this by:

<jsp:invoke var="content" fragment="content"/>
<c:if test="${empty content}">

This did the trick. I evaluated the JSP fragment and placed the result in a variable also named content. I was able to then act on it like a normal attribute.

April 3rd, 2012

Posted In: Java, JSP

One Comment

WP to LinkedIn Auto Publish Powered By :