For a persistence service we needed a local cache. We decided to use a least recently used cache which allows to set a maximum size and automatically deletes the oldest elements.

A simple implementation based on the Java-Class LinkedHashMap can be found here:

LRUCache.java

If you need to access the cache with multiple threads, you can use the synchronized version:

LRUCache_sync.java

The usage of a Logging-Service in Tapestry is quite easy. You just have to use the @Inject Annotation in your classes.

import org.slf4j.Logger;
@Inject
private Logger logger;

A little bit more complicated is the usage in a Tapestry-Service. Here an @Inject Annotation will fail, so you would have to get an instance for your logger from another source. One possibility would be to use a build-method in your Module class. But then, you would have to distribute such method for each service which should use a logger.

Tapestry helps you here and can contribute the needed Logger instance if you insert a constructor method to your service:

import org.slf4j.Logger;

private final Logger logger;

public MyServiceImpl(final Logger _logger){
     this.logger = _logger;
     this.logger.debug("Successfully initialized MyServiceImpl);
}

Your Service will now be initialized with a working instance of the Logger-class.

A common problem when using confidential data is how to save it. Usually you would encrypt this data and save a encrypted version.

Java provides several build-in algorithms for symmetric-key cryptography (AES, DES …). To use those algorithms, you have to generate a secret-key and initialize a cipher for decryption and one for encryption with it.Those ciphers can now be used to crypt your data.

To simplify this task, I created a small library which provides the needed methods to decrypt and encrypt a String. There are several static methods to automatically initialize a crypter for a certain algorithm such as AES.

How to encrypt and decrypt a String:

Crypter myCrypter = Crypter.getAES_Crypter();
String encrypted = myCrypter.encrypt("my secret text");
String decrypted = myCrypter.decrypt(encrypted);

Download:

Library

Source

A big thank you goes out to the author of the used Base64-Coder: http://www.source-code.biz/

Innerhalb eines unserer Projekte lernen wir gerade die Vorteile von Maven kennen. Dies betrifft vor allem das dynamische Nachladen von benötigten Libraries und die Möglichkeiten, die man zum Deployen einer Anwendung hat.

Bei unserem Projekt handelt es sich einerseits um eine Tapestry 5 Anwendung. Diese lässt sich auf jedem beliebigen Server mit installiertem Maven über den Befehl

mvn jetty:run

starten.

Auf der anderen Seite haben wir dann noch eine einfache Java-Anwendung, die eine Verbindung über einen Socket aufbaut.

Als Einführung ins Thema Maven haben wir uns das folgende Buch gekauft:
Maven: A Developer’s Notebook (Developer’s Notebooks)

Zwar behandelt es eine etwas ältere Maven Version, es ist aber gut für die Grundlagen geeignet.

In the process of software development there is often the need for dummy object. One of the main reasons for their usage is the fact, that a database or another data-provider might not be ready or available in the current stage of development.

Normally a developer would implement some methods to create those dummy objects with random data. If you have many classes, this might become a quick time-consuming task. A good solution would be a library, which creates those objects automatically.

Den Rest des Beitrags lesen »