Category: Java

Add Connection Pool with auto connection cleanup functionality for Tomcat 7 and MySQL

Since we don’t want to use external classes or libraries to handle database connections for our web applications we should stick to what comes built-in with the container server – in my case Apache Tomcat 7 and MySQL database server. To keep the database connection pooling and cleanup functionality on the server-side you can use […]

Tomcat 7 Fails to load Resource Factory class

In case you get the exception Could not load resource factory class when trying to retrieve the Connection object from the JDBC connection resource pool based on the factory class org.apache.tomcat.jdbc.pool.DataSourceFactory make sure to check if tomcat-jdbc.jar is installed in the tomcat/lib directory. Please note that this file is not installed by default on most […]

Serving Files using Jersey Web Service (JAX-RS)

There are a lot of tutorials out there explaining how to send binary data (i.e. application/octet-stream) as response for Jersey web services (Java JAX-RS). Two possible solutions are based on either returning a Response or StreamingObject containing the appropriate binary data stream. Below you find a simple example for both scenarios: Additional checks have been […]

Convert GPS Coordinates to Address using Google Geocoding API using Java

Google Maps makes it easy to convert addresses to their corresponding GPS coordinates using the Geocoding API. But what if you want to do the reverse, i.e. convert GPS coordinates to the corresponding address? Simple, just use Google’s ReverseGeocoding functionality. Below you find a simple Java example of how to use the API to convert […]

Setting Custom Portlet Titles in Liferay

Setting custom portlet titles in Liferay can be a little tricky. Changing the title via the portlet configuration in the frontend is easy but when it comes to reading the custom title property programmatically things seem to get a little messy. Setting the Title So, first of set your portlet title as usual via the […]

Bugfix for urbanairship-java SDK Connection Still Allocated

Apart from another bug reported in there also exists a bug related to the internal use of BasicClientConnManager for sending HTTP requests. The Cause When trying to send multiple HTTP requests using sullis urbanairship-java SDK (occasionally) an IllegalStateException is thrown. This is caused due to the fact that the version does not release open […]

Bugfix für urbanairship-java SDK JsonParseExceptionBugfix for urbanairship-java SDK JsonParseException

There (still) exists a bug in urbanairship-java SDK related to parsing valid ISO8601 dates. The original bug report can be found here: GSon date parsing error. The Cause ISO8601 states that for date-time strings the separator “T” can be left out. Unfortunately the urbanairship-java SDK expects only fully qualified ISO8601 strings. Thus, when it receives […]

Setting Custom Timezones in Liferay

By default Liferay uses UTC as timezone. In order to set custom timezones you may choose from the following options: Create an EXT-Plugin Specify timezone in Tomcat’s setenv script EXT-Plugin Create an EXT-plugin (or use your existing one) and put in extyour-extdocrootWEB-INFext-implsrc using the following setting: Be sure the deploy and restart Tomcat afterwards. […]

Custom Response Types in Jersey SecurityContext

Sometimes you might need to return custom response types in your SecurityContext implementation when using Jersey RESTFul web services. Basically, there are two options available to do so: Use and throw a WebApplicationException or write your own ExceptionMapper Throw WebApplicationException Custom ExceptionMapper The other (even nicer option) is to write your own ExceptionMapper:

Setting Custom User Model Attributes in Liferay

Oftentimes you will need to extend Liferay’s built-in User model by adding custom attributes, such as a list of preferred settings. Fortunately, Liferay provides developers with an ExpandoBridge implementation to do so. Thus, in order to add custom attributes simply use the Custom Fields option via the Control Panel (or programmatically). Search for the User […]

Determining Absolute Path for FileEntry in Liferay

In case you are wondering how to determine the absolute path to FileEntry objects in Liferay (i.e. Document and Media Library elements) here is how it works. First, add the following to your Then, to calculate the absolute path for a FileEntry use the following code: Note that in order to get the foldername […]