Adding a thread timeout to methods in Java
Sep 1st
When calling a method that could potentially take longer that you’d like to complete, it is possible to write code that will back out after a given time period.
This can happen in numerous circumstances where you’d like an application to maintain a degree of liveness. I’ve used it recently in an application that needed [...]
What info can you get from an HttpServletRequest?
Feb 1st
There are many methods on an HttpServletRequest, and if you’re anything like me, you’ll forget exactly what each of them returns. Rather than a long winded investigation into them all, here’s a sample URL:
https://localhost:8443/test/welcome?a=1&b=2
The ‘/test’ in the URL will map to a servlet called test. The servlet will dispatch the request to a JSP for [...]
Implementing Flash Scope in Java Web Applications
Jan 17th
While working recently on a Spring MVC project I found myself wishing it supported flash scope. I hunted around for a simple solution but couldn’t find anything that didn’t rely on having to import large framework libraries. After a little thought I came up with the following simple and lightweight solution that has worked really [...]
Working around a javax.net.ssl.SSLHandshakeException
Sep 27th
When trying to download data from an HTTPS connection, you might see the following exception reported:
javax.net.ssl.SSLHandshakeException: renegotiation is not allowed
This rather unhelpful error message can be raised on either the server or the client and indicates that the SSL libraries in Java cannot determine whether the CA that signed the server’s certificate is to be [...]
Specifying a different config file for Log4J
Sep 2nd
Generally, adding a log4j.properties file to the classpath is all that needed to bootstrap your Log4J runtime. In certain cases though you might want to override this behaviour.
I needed to do this recently and it took me a while to find out how to do it in the Log4J docs, so I though I’d make [...]
Getting a “Netscape security model is no longer supported” error when using IntelliJ
Aug 6th
I’ve been working on a JMS application that uses encryption with JNDI authentication and have encountered the following error message when running it:
Netscape security model is no longer supported. Please migrate to the Java 2 security model instead.
It turns out that this is a problem with the JDK’s plugin.jar file and can be fixed quite [...]
Getting Maven to work from behind a firewall
May 28th
Maven needs to access the Internet to download a number of things including POM files and dependent JAR files that are not held in your local repository. If you are trying to do this from behind a corportate firewall then you’ll need to configure Maven to work around it or you’ll get a load of [...]
Java 1.4 Debugger Not Working?
May 13th
There’s a bug that I’d encountered running the debugger in JDK 1.4.2 ages ago that reared it’s head again today. I’ve been working on a system that uses this old JDK and thought I’d note the solution here in case I ever came across it again.
The problem is encountered when the JVM is launched [...]
Using Mockito to Unit Test Java Applications
Feb 25th
If you’ve spent any time writing unit tests then you’ll know that it’s not always straight-forward. Certain things are inherently hard to test. In this post I’ll show you the basic principles of creating mock objects with a little help from the Mockito mocking tool.
One common problem faced when unit testing is how to test [...]
Using Assertions in Java
Feb 18th
I’ve been working on a project this week and have been delighted to see that the original team of programmers who developed it have made the effort to use assertions in their code.
The assert keyword was introduced in Java 1.4 and has since been a sadly under-used language feature. Assertions offer developers a neat [...]
