Monthly Archives: April 2013

Execute JerseyTest case within Eclipse

If you execute a test case within Eclipse, it is possible to fail already on the build of the WebDescriptor. You should add

-Djersey.test.containerFactory=com.sun.jersey.test.framework.spi.container.external.ExternalTestContainerFactory

to your Debug/Run configuration to test against the deployed WAR on the Glassfish server, which runs within Eclipse. Normally the init process of the JerseyTest should find a factory class, if it is within the classpath. The pom.xml contains a dependency to something like

<groupId>com.sun.jersey.jersey-test-framework</groupId>
<artifactId>jersey-test-framework-external</artifactId>

which provides the ExternalTestContainerFactory. But Eclipse could not find it and got a NPE on startup of every test case.

GWT no longer supports Quirks Mode

To prevent that warning, you should add

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

to your “index.html”. The standard page for a GWT project in Eclipse doesn’t contain a DTD reference, so you should add “loose.dtd”. An alternative could be, that you add

<extend-configuration-property name="document.compatMode" value="BackCompat">

to your module XML file. But this only hides the warning and doesn’t solve the problem.

HTPP -> HTTP redirect on Glassfish 3.1.2.2

Execute this on your Glassfish machine:

###
### HttpToHttpsRedirectOnDifferentPort
###
asadmin create-protocol --securityenabled=false http-redirect
asadmin create-http-redirect --redirect-port 443 --secure-redirect true http-redirect
asadmin create-protocol --securityenabled=false http-redirect-base
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-listener-2 --classname com.sun.grizzly.config.HttpProtocolFinder https-finder
asadmin create-protocol-finder --protocol http-redirect-base --target-protocol http-redirect --classname com.sun.grizzly.config.HttpProtocolFinder http-redirect
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.protocol=http-redirect-base

Finding a file containing a particular text string

To find a text within all files of a directory use the following command:

grep -H -r "needle" /hay/stack

Set date and time on a Linux command line

You can set date and time of a linux server with:

date +%Y%m%d -s "20131228"

which sets the date to the 28th of December in 2013.

date +%T -s "20:15:45"

which sets the time to a quarter past 8 PM (and 45 seconds).

If you set the system datetime, you can also set the hardware clock:

hwclock --systohc --localtime