Archive

Posts Tagged ‘java’

Avoid an MVEL Bug In Drools Snapshots

January 20th, 2010

If you’re working with Drools trunk snapshots, you may be tripping over a bug in MVEL that caused me to lose about a day. On the RHS (right-hand side, the consequence) of my rule I had the following:

Which resulted in this error: [Error: unable to access property (null parent): $obj]

However, if I call an accessor or otherwise do something with the object before passing it off to the constructor, it works fine:

Right now this appears to be a problem in MVEL, but I don’t know enough about the internals of Drools of MVEL to say for sure. Ideally this workaround will keep you moving forward.

nick Entry ,

Customizing JAXB’s Namespace Prefixes

November 21st, 2008

At a recent event in Denver, some of our integration partners complained about the namespace prefixes in the XML we generated. By default, JAXB creates simple prefixes like “ns1″, “ns2″ and so on. I’m not sure it matters unless you’re processing XML using some archaic means, but keeping partners happy is usually a good idea, so I turned to the JAXB API.

JAXB makes prefix customization pretty easy through the NamespacePrefixMapper class, found in the com.sun.xml.bind.marshaller package. The abstract class has one method to implement:

From here, it’s a simple matter of returning the prefix you want for a given namespace, then telling your JAXBContext about your implementation:

If you’re also using javax.xml.xpath.XPath, your NamespacePrefixMapper can also implement javax.xml.namespace.NamespaceContext, centralizing your namespace customization in a single class.

nick Entry , , , ,

More Maven Woes Follow-Up

February 3rd, 2008

Various people have responded about my Maven complaint, suggesting explicitly excluding the JAR. I tried it, and it didn’t work. Like I said, I’m new to Maven so it’s possible I missed a “simpler” fix.

nick Entry ,

Article: Introducing Apache Wicket

January 29th, 2008

With Apache Wicket 1.3.0 out for a while now, it was time to finish my article and turn it over to TSS to publish. The article went up yesterday and the response has been very positive so far.

I’m hoping to make this a short series, although future articles probably won’t be 22 pages long. If you’ve read the article, I’m always interested in your feedback.

nick Entry ,

Reset those mock objects

November 21st, 2007

Lately I’ve been rolling mock objects into my unit tests. I selected EasyMock since it came up first in the Google search. Everything was going well until I wanted to test return values with the expectLastCall(…) method. If you’re not familiar:

It seems to follow the (disjointed) EasyMock documentation, but fails with “Unexpected method call find(1)”. Since I’m creating my mock objects at the start of every test method, I needed to call reset(…) on my mock objects. Using TestNG, this is straightforward:

nick Entry , ,