Our blog

Install Apache Tomcat 9 APR on Ubuntu 18

  • Download and install Tomcat (there are enough resources to read about this)
  • Install APR: sudo apt-get install libapr1 libapr1-dev
  • Go into the TOMCAT_HOME/bin directory and unpack the tomcat-native-xxx tarball
  • Edit /etc/environment and add this rule: JAVA_HOME=”/usr/lib/jvm/default-java”
  • Reload variables: source /etc/environment
  • Check if JAVA_HOME is set: echo $JAVA_HOME
  • Go into the tomcat-native-xxx/native directory and type:
  • ./configure –with-java-home=$JAVA_HOME
  • make
  • make install
  • You will need g++ for this:
    sudo apt-get install g++
  • Create or edit the $CATALINA_HOME/bin/setenv.sh file with following lines :
    export LD_LIBRARY_PATH=’$LD_LIBRARY_PATH:/usr/local/apr/lib’
  • restart Tomcat service
  • View catalina.out for:
    org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.21] using APR version [1.6.3].
29 Apr 2015
by cvringer

Creating virtual hosted apps with Apache

When you develop webapps, most often you don’t want users to type in complex urls like: http://ipaddress:8080/my-webapp/, but you want to use a nice DNS url like: http://www.myserver-DOT-com/ or: http://admin.myserver-DOT-com.

So, how do you do that? It’s actually not that hard. Using Apache’s virtual host module, you can easily ‘map’ web applications to an url. Here’s how:
Software: Apache 2.2, and a servlet container

Using Apache webserver and Tomcat or Glassfish or any servlet container, this is how you do it:

First, register you DNS names! Depending on your provider, you can do this yourself. In this example, you register two domains: www.myserver.com and admin.myserver.com. It could take some time for these names to be known at all DNS servers.

In apaches conf/httpd.conf make share these lines are enabled:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so

# Virtual hosts
NameVirtualHost *:80


#Here are the .conf files of your sites)
Include conf/sites/*.conf

Create one ore more virtual host file:
Here are two examples

Restart Apache, go to http://helloworld.com/ and you will see the webapp. Go to http://admin.helloworld.com/, and you will see your admin console.
Thats it! you are all done.

29 Apr 2015
by cvringer

Mocking a service with GMock

Here is a short example of a Grails unit test using Gmock. I published this example because it took me too long to figure out
how to do this. Gmock is very nice to work with, but poorly documented. Maybe it safes you an hour. This example mocks a Solr search service.

29 Apr 2015
by cvringer

Grails: Multiple logins per user

Sometimes you would create multiple logins for the same user in an application. You might want to login as administrator or as regular user, without entering all your personal data again, or without creating yet another email address. Here is how you do it.

– Setup a secured Grails application.(there are multiple ways of doing that)

– Create a relations between your regular user object (where you store firstname, lastname, email and so) and the Login object.

class Login {
     String username
     String passwordHash
     static belongsTo = [user:User]

and in the User class:

static hasMany = [logins: Login]

That’s it. You can create multiple logins for the same user,and you can even assign different roles per login, so the same user can login as administrator, and use another login with another role.


20 Apr 2015
by cvringer

Securing Milton Webdav with JAAS

I was working on our Document Management System, playing around with another webdav possibility. Our DMS uses JackRabbit for webdav.

Although it has been working fine for about 6 years now, it’s been causing a lot of overhead. So i looked into Milton (http://milton.io) which should be a nice lightweight solution. One can map it’s own model to Milton and thus enable webdav. For us, our model (in the database) is translated intro a nice webdav solution.

To get a feeling about Milton, you can download milton-anno-ref. It’s a working implementation, and runs out of the box. Note: To enable full Dav Level2 you need a (trial) license. Read more HERE.

Now, when you use Milton, you probably want to run it on Tomcat, or some application server. Maybe you already use something like JAAS. So how do you configure Milton to not use it’s own authentication mechanism, but the container managed one?

I’ll describe how you can use JAAS, and run it on Jetty, Tomcat or Glassfish. Ready? Let’s go then.

First: When you downloaded and installed Milton onto your favorite IDE, you have to disable Milton’s own securitymanager. The SecurityManager is injected in the default Configurator, so we have to build our own configurator. Here’s the code:

As you can see, we disable security by injecting a NullSecurityManager into the HttpManagerBuilder. This disables any authentication and authorization. Next, we tell Milton to use this Configurator. We also configure the security element in our web.xmlThis tells the container to authenticate all requests and give access to any authenticated user with the role milton-user. An OPTIONS request is always allowed. So, if you run Milton now, the container will authenticate, and once authenticated Milton can do it’s work.


In our DMS, ACL is not controlled by Milton, but in the database. So the query result depends on the user and the roles and permissions that user has in the database. For every query we need to know the logged-in user (Principal). In Milton getting the Principal is easy. Annotated methods can be extended adding the Request parameter. From this request you can get the Principal. Here’s how:

20 Apr 2015
by cvringer

Connect to Twinfield using Java

Twinfield has an extensive webservice API available. It has documented how to connect for popular technologies like C, .net and php. Unfortunately there is no Java tutorial available, so i wrote it down here. First, i’ll explain how to setup a Java project in Intellij using Spring-ws and maven. Of course you can use your own IDE for this. In a next entry i will explain how to create and abandon a session, and how to execute requests. Lets start!


First of all: If you want to download the full example and get quick and dirty in minutes, you can do that HERE. No need to further explore this page. Glad i could help!




Get to know a little more of the working code below, and build the bastard for yourself.
Many developers have precedeeded you. I’m sure you can build it too!


Step one: Create a maven project: In your IDE you can create a new maven project. In Intellij you will use file/new Project/Spring application. This will result in a maven-structured project, which contains a pom.xml file with some spring dependencies in it. You can also use command-line maven to create a new project. Details are HERE


Next, fill your pom with dependencies. An full pom example is HERE


Step two: Import the wsdl for session into your project and save it in scr/main/resources/wsdl. The maven-jaxb2-plugin plugin will take care of generating objects from the wsdl. If you run mvn clean install from your project root directory, Twinfield objects will be generated in your target directory.


For the coding part:
You will need a Spring configuration. I use an AnnotationBasedConfiguration class for this.

Next write the WebServiceClient implementation. A Unit test example is HERE (thanks #Kees). This example uses a
SessionDetails wrapper object to store the requested sessionId and actionUrl.


Note that the webserviceclient sets a SOAP Action variable. This variable is required by Twinfield and should define the action (Logon or Abandon). Now you have Twinfield connection, you can query or send XML to Twinfield.


Good luck coding!

© Keienberg Consultants