Our app throws all sorts of exceptions. Well, it doesn't usually. It shouldn't normally. Er... But, when it does we want to put in some handling so that the app doesn't blow up in some unsuspecting user's face. And even then, sometimes we want special handling for certain exceptions and make sure others are just caught. And that's what we'll do with AccessDeniedException.
In Java Land, everything is tied up in multiple layers of multi-colored wrapping paper. The abstraction often provides niceties and protections and convenience, etc. But, sometimes it practically makes you forget where you are. For instance, why would anyone write a little howto on requesting something over the web from the context of the web. That should be easy, right? Well, yes, I think so. And it turns out it is in Java, as it is in many other languages. It's just that there you're super close to the HTTP protocol all the time, and in many Java ...
BackboneJS is setup to do some pretty sweet single-page app action. And of course, a single page app will probably be wanting to talk to web services on the server. And if your server code is doing the Java jive, then a great way to expose your REST services is via JAX-RS. It's as easy as Mikey singin' ABC-123!
In addition to some sweet Inversion of Control injection action, Spring brings flowers and baby deer. And it brings some nice database connection help. Spring JdbcTemplate is a vanguard of strength and ease for connecting to your favorite RDBMS. And it so happens that the DBA I'm working with right now digs the stored procs. So, we'll meet in the middle with some more goodness born of Spring.
Recently, I've been working on a project where I've tried to use AES encryption for the first time. I didn't have to implement it myself, thank goodness, but I still ran into a few snags. Perhaps you can avoid my pitfalls and rise to new greatness on the peaks of glory and fortitude! This article title sounds like a laundry detergent.
By default, Java has a limit on the length of your encryption key. The limit, by default 128-bit, seems a little small and dated. So, let's break through that glass ceiling! With the hammer of Thor!
I've always wanted to know the best way to iterate over the elements in a map. Here's one way I've found that works.
[flash bang!] Say words like generics, enums, or interfaces, and you've immediately transported to the realm of conjured whirlwind sandstorms and curved-sword-weilding assasins. Well, I guess we're going there, because I think this is pretty cool. Plus, undocumented, or at least un-reiterated to myself, and later I'll look at it and think it's just pretty complicated. Prepare for angle brackets in the amount of parens in lisp.
We all know that contains() is a handy way to check for the presence of an item in a HashSet. The java docs state: "Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e))." So, you just need to override equals() the way you want, and everything's hunky-dory, right? Wrong!
In the Java world, we don’t get closures until Java 7. Groovy already has them. Here's what I’ve learned about these important programming structures, and why they're powerful.
Have you ever had a problem with ajax requests caching in Internet Explorer. I have, and recently I came across a nicer solution than I have traditionally used. In the past, I have used a unique parameter on the url to keep IE from caching previous requests to the same url, like so:
Here is a "new and shiney" presentation for running Django on Jython. It's based on my experiences with the DjangoJython tutorial.
As is discussed in the slide deck, and hence the subtitle of the presentation, much could be helped by more careful reading of documentation. Well, moments ago, I decided that I hadn't checked out django-jython 1.1. Well.... turns out many more problems could have been helped by using this later version. Sweet!
In Ubuntu 9.10, they removed Java 5 from the update repositories for Karmic because Java 5 was end of lifed in Oct. 09. This has made it more cumbersome for the Java 5 user on Karmic. Luckily, cumbersome is still pretty easy.
My first experience with Spring Webflow is on a project that uses Webflow 1.0.5. So far, I'm impressed. Apparently, Webflow 2 offers even more incredible awesomeness, but thusfar I would put my webflow experience over that of my previous couple years in Seam. (I was just waiting for a chance to abandon that library anyway.)
Sometimes you want Maven to compile your code with a different JDK than is the one assigned to your JAVA_HOME. For instance, I have code in a project that I'm working on that only compiles on Java 1.5. My JAVA_HOME, however, is 1.6. So, how do we specify the JDK for Maven?
Sometimes you need to install a security certificate for authentication to work for certain services -- services that are accessed by your java application that requirement a secure connection. For instance, needing to authenticate against an LDAP server from one of our apps, we had to run a little InstallCert.java on all JDKs used to run the app.
In developing an email notification system recently, we became interested in code acting differently depending on what environment we were in. A potentially good solution for this is environment-based dependency injection. This means that different Spring beans, for instance, will be used depending on the environment, ie dev, test, etc. This is useful for something like emailing, because we may not want real emails hitting the mail server in dev or test environments, but we do in prod. With some Spring constructs, it's pretty easy.
Often when coding, we use a single local variable multiple times, overwriting the value many times. It is considered good practice to move the variable out of the looping overwrite and into the smallest scope of code that is run once. But, this makes the code a little bit less concise. So, how useful is it, anyway? I wanted to run a few little tests and see if there's really a noticable difference in performance.
EasyMock is a great tool for separating external dependencies from unit tests. There is a learning curve to learning the mock method of testing, and unfortunately, EasyMock does not give very good prompts when you do something wrong. The exception messages are actually quite cryptic. This article is meant to be a crude mapping of exception output and the behavior that might have caused it. At least, this is a log of many of my experiences with EasyMock and how I usually get into the messes I do. It is quite possible that the same exception output could be had ...
On Ubuntu 9.04, Jaunty, Compiz comes running out of the box on the mid-level preset for desktop effects. These effects and generally beautiful and pleasing, but a couple of the apps that I use are Java-based and have some compatibility issues with Compiz. At least for my apps, I've found a way around this issue.