curl: show header only / http get

If you only want to show the headers of your http response, you may want to use the following switches:

  • -D = dump headers
  • -s = silent mode
  • -o /dev/null = send all output do dev null

The curl request looks like this:

$ curl -s -D - https://www.path.to/my.file -o /dev/null

The output should looks like this:

HTTP/2 200
last-modified: Tue, 13 Dec 2016 12:08:30 GMT
etag: W/"183836-1481630910000"
server: Apache
x-magnolia-registration: Registered
pragma: no-cache
content-type: application/x-font-otf;charset=UTF-8
content-length: 183836
accept-ranges: bytes
cache-control: public, max-age=8236
expires: Mon, 02 Jan 2017 13:11:32 GMT
date: Mon, 02 Jan 2017 10:54:16 GMT

Apache Lucene 2.9 ist da!

Das beliebte Java-Sucheframework Apache Lucene ist in der Version 2.9 erschienen. Neben einem überarbeiteten Unicode-Support gibt es ein neues Query-Parser-Framework. Umsteiger von Version 2.8 sollten jedoch aufpassen, da sich die API zum Teil geändert hat. Auf JAXEnter wurde übrigens eine Artikelserie zum Thema Lucene eingerichtet.

Unix / Linux: was macht mein Prozess?

There are some useful tools to check the load of your box / server – even when you have just only very less permissions (ant ‚top‘ is not available):

  • ptree – all processes with pid
  • prstat – similar to top
  • kill -3 <pid> – print (java) stack strace and dump to log
  • ps -aelf – you sh’d know it. Otherwise: forget your password.

Wicket in Action

There are dozens of Java frameworks out there, but most of them require you to learn special coding techniques and new, often rigid, patterns of development. Wicket is different. As a component-based web application framework, Wicket lets you build maintainable enterprise-grade web applications using the power of plain old Java objects (POJOs), HTML, Ajax, Spring, Hibernate, and Maven. Wicket automatically manages state at the component level, which means no more awkward HTTPSession objects. Its elegant programming model enables you to write rich web applications quickly.

Wicket in Action is an authoritative, comprehensive guide for Java developers building Wicket-based web applications. This book starts with an introduction to Wicket’s structure and components, and moves quickly into examples of Wicket at work. Written by two of the project’s earliest and most authoritative experts, this book shows you both the “how-to” and the “why” of Wicket. As you move through the book, you’ll learn to use and customize Wicket components, how to interact with other technologies like Spring and Hibernate, and how to build rich, Ajax-driven features into your applications.

Weitere Infos auf manning.com

Apache Tomcat mit eigener Java VM starten

Apache Tomcat velangt nach einer Java VM – jedoch möchte man ggf eine andere verwenden, als auf dem System installiert ist?!

Apache Tomcat wird über ein Script gestartet, in dem sich auch wunderbar die entsprechenden Variablen überschreiben lassen. Wichtig ist dann nur, dies auch für das Shutdown-Script zu erledigen.

Durch Anpassung des startup.sh – Scriptes ist dies also einfach möglich!

# set my own java path
export JRE_HOME=/usr/java/jre1.6.0_01
# increase memory size
export JAVA_OPTS=-XX:MaxPermSize=512m

Es wird nun eine Java VM von einem bestimmten Pfad verwende, und auch die Optionen um den zu nutzenden Speicher zu vergrößern können gleichmit angegeben werden.

In der Datei shutdown.sh sollte jedoch mindesten die Zeile export JRE_HOME=/usr/java/jre1.6.0_01 nochmals angegeben werden, da ansonsten wieder die systemweit genutzte Environment-Variable verwendet werden würde.

Apache Tomcat und mod_jk / ajp13 auf SuSE Linux

Nach wie vor ist der Apache Httpd schneller als ein Apache Tomcat, wenn es um die Auslieferung von statischen Inhalten geht. Gerade in Verbindung mit Tomcat bietet der Apache Httpd noch weitere Vorteile: durch das Modul mod_jk kann eine ganze Farm an Tomcat-Servern per Load Balancer angeschlossen werden!

Für den Betrieb benötigt man:

  • einen funktionierenden Apache Httpd-Server
  • einen funktionierenden Apache Tomcat-Server
  • das Modul mod_jk, welches auf der Tomcat-Webseite zum download erhältlich ist

Das Modul habe ich zur Vereinfachung nach dem Download in „mod_jk.so“ umbenannt und im Lib-Verzeichnis des Apache Httpd abgelegt (auf SuSE Linux 10.2: /usr/lib/apache2).

Der Apache Httpd ist auf SuSE Linux so konfiguriert, dass alle Dateien, die auf *.conf enden und in /etc/apache2/conf.d liegen, automatisch zu httpd.conf (bzw default-server.conf) included werden. Das macht die weitere Konfiguration einfach, denn nun müssen in dem o.g. Verzeichnis nur zwei Konfigurationsdateien abgelegt werden.

Die Datei tomcat.conf bindet mod_jk ein:

# Load mod_jk module
# Update this path to match your modules location
LoadModule jk_module /usr/lib/apache2/mod_jk.so
# Declare the module for <IfModule directive> (remove this line on Apache 2.x)
#AddModule mod_jk.c

# Where to find workers.properties
# Update this path to match your conf directory location (put workers.properties next to httpd.conf)
JkWorkersFile /etc/apache2/conf.d/workers.properties

# Where to put jk shared memory
# Update this path to match your local state directory or logs directory
JkShmFile /var/log/apache2/mod_jk.shm

# Where to put jk logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
JkLogFile /var/log/apache2/mod_jk.log

# Set the jk log level [debug/error/info]
JkLogLevel debug

# Select the timestamp log format
JkLogStampFormat „[%a %b %d %H:%M:%S %Y] “

# Send everything for context /examples to worker named worker1 (ajp13)
JkMount /application/* worker1

In der Datei müssen ggf. die Pfade zu mod_jk.so sowie zu den Log-Files angepasst werden.
Mit JkWorkersFile wird auf die Konfigurationsdatei des mod_jk referenziert. Alle Anfragen im Format http://www.domain.tld/application werden nun an mod_jk übergeben.

Die Datei workers.properties ist – sofern nur ein einziger Tomcat-Server angebunden werden muss, sehr kurz:

# Define 1 real worker using ajp13
# this coud be al list in the format
# worker.list=worker1, worker2, worker3, worker4
worker.list=worker1

# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009

Das Format zum Konfigurieren der einzelnen Worker ist also worker.<workername>.<property> . In der Beispielkonfiguration wird also nur ein Worker mit dem Namen „worker1“ genutzt, der auf dem gleichen Host läuft und mittels dem Protokoll ajp13 angesprochen wird.

Über die URL http://www.<domain>.<tld>/application erreicht man nun also direkt die Application auf dem Tomcat.

Quellen & weiterführende Links:

Weiterleiten mit .htaccess

Auf über 60% aller Webserver läuft ein Apache Httpd-Server. Zu Recht, denn der Apache-Server beweist immer wieder seine vielfältigen Fähigkeiten und hohe Zuverlässigkeit.

Ein wichtiges Feature ist die .htaccess-Datei, mit der sich Zugriffe auf Verzeichnisse „umdefinieren“ lassen können – so zum Beispiel auch Weiterleitungen realisieren lassen:

Redirect /verzeichnis http://www.my-container.de

… leitet alle Anfragen an http://www.my-container.de/verzeichnis direkt an http://www.my-container.de weiter.

Das funktioniert auch mit einzelnen Dateien, als Ziel ist natürlich auch ein anderes Verzeichnis gültig:

Redirect testdatei.html http://www.my-container.de
Redirect /verzeichnis /anderesVerzeichnis

Und auf die gleiche Weise kann auch eine ganze Domain umgeleitet werden:

Redirect / http://www.my-container.de

Diese Umleitungsfunktionen sind unabhängig vom verwendeten Browser und werden nur vom Server gesteuert. Somit funkltioniert diese Technik auch bei Browsern, die z.B. die Meta-Angabe „meta redirect“ nicht interpretieren.