In a certain stage of webapp-development, there is the requirement to deploy your application to a “real” webserver. If you are using Maven for your build-management you probably use the provided jetty plugin. This plugin allows you to start your application without downloading and configuring a webserver on your own.
The difference between a webserver on the internet and a local machine is the accessibility and the need, to encrypt your sessions. This is normally done by providing a HTTPS-protocol access to your web-application.
Hubert Klein Ikkink has written a nice blog-post how this can be achieve with the jetty-maven plugin.
Click here for the blog-post
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.
I just created a small piece of java-code, which allows you to receive geo coordinates (longitude / latitude) for a certain address.
It’s quite simple to use:
final CoordinateTool ct = new CoordinateTool();
final Coordinate coord = ct.getCoordinateForAddress(YOUR_ADDRESS);
Another feature is the possibility to load a route from A to B. You have the possibility to get this route as String or to save it to a File.
final CoordinateTool ct = new CoordinateTool();
final String route = ct.getRouteForAddresses(YOUR_ADDRESS, YOUR_DESTINATION);
ct.saveRouteForAddresses(YOUR_ADDRESS, YOUR_DESTINATION, FILENAME);
If you need the distance between two addresses or coordinates, you can use this “getDistanceBetween” method.
Download:
Library
Source.