Spring Injection in JUnit4 – Testcases

If you use maven then you should make sure to have the following dependencies within your pom:

Your test class should look like this:

The ContextConfiguration has to be setup with the spring configuration file, which contains all the beans that can be used for injection.

If you get initialization errors or ClassNotFoundExceptions then you should make sure to have the correct version of your dependencies installed. For JUnit it’s recommended to stick with version 4.4 since the newer versions throw a ClassNotFoundException if you combine your tests with Spring Injection.

Posted in Uncategorized | 1 Comment

Run Eclipse in JDK-mode

If you wanna use the M2E Plugin (Maven for Eclipse) then you probably came across the error message that you should run you eclipse in a JDK environment instead of a JRE. To do so you have to create a shortcut for your Eclipse application and add to the properties the argument:

It’s not enough to do it inside the eclipse.ini! Moreover you should point to the JDK release within your Eclipse under “Installed JREs”.

Posted in Eclipse | Leave a comment

Velocity Macro: Exception when getting undefined localized string

When I was playing around with localization within Velocity Macro I received some bad exception when I was trying to get a localized string whose key doesn’t exist.

“Can’t find resource for bundle java.util.PropertyResourceBundle, key”

It was even worse that the rest of my template wasn’t rendered just because of a missing localisation key. That’s pretty bad and I would rather see one non-localized key instead of nothing at all. When those localisation keys are generated dynamically these exception can come even more often if you change some value in one spot for example not thinking about that this one is used for localisation.

Read more... (220 words, estimated 53 secs reading time)

Posted in Jetspeed, Velocity Macro | Leave a comment

Add customized Like-Button to your website

I was trying to put one of those Facebook-Like Buttons onto one of my websites. Of course I didn’t want to use their style(s), but a different one that would fit into the design of my site. On the other hand the original design every one knows and also knows the meaning immediately. However, if you wanna change the style of your Like-Button than it won’t be easy!

The usual way to get your Like-Button onto your site is to go to the Facebook website and get fetch some code that you simply put onto your page. Afterwards you have a fully functional Like-Button with lots of features. You can even write a comment, once you clicked the button and are logged in to Facebook.

Read more... (556 words, estimated 2:13 mins reading time)

Posted in Javascript / HTML / CSS | 1 Comment

Servlet/Portlet Filter for Url-Rewriting

When it comes to URL rewriting the first thing that comes in mind is using the Apache config file httpd.conf. That’s generally good but has the disadvantage that your webapp cannot be installed without modifying a system file with root access, which not everyone might have. Anyway … this could look something like this:

Another nicer approach is to use this URL-RewriteFilter, which will be part of your webapp. You just need to copy the library into the lib-folder of your webapp and activate the filter in your web.xml like this:

This will filter all incoming URLs from the root, before they actually reach the webapp’s code. Check out the website for more options! If a webapp has for example the path “/my-portal/portal/default-page.psml” which points to your start page of your Jetspeed Portal, then you can access this page with “/startPage” by adding this rule to your configuration file (urlrewrite.xml) in your WEB-INF directory:

If you also want to have rewritten all your links of your website, you need to define an outbound rule. So every link within your JSP or Velocity Macro page will also point to the pretty URL. However it is important to use “response.encodeURL(…)” for all links! In other words use

for jsp-pages or

for vm-pages, otherwise they might not be send through the filter, so better mark them all :) The outbound-rule has to be defined something like this:

Posted in Apache, Java | Tagged , , | Leave a comment