J2EE Filters and websphere application server 6.1

By default websphere application server (WAS) 6.1 (maybe 6.x) has the J2EE filters disabled.

Don’t know why. Don’t ask it to me. I only know that the custom rewrite/redirect I made in my J2EE filter didn’t work until I told middleware office to set a websphere custom property.

The property to set is com.ibm.ws.webcontainer.invokefilterscompatibility and has to be set to true. You can find where to set it under the websphere administration console following this path Application Servers -> <server> -> Web Container Settings -> Web Container -> Custom Properties.

Easy once you know what to do. 🙂

xslt 1.0 and upper/lower case

by assbach from flickr

When you have to manage upper/lower case and you are in XSLT 1.0, you have no other comfortable choices than using the translate function, here’s an example.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:variable name="lower">
   abcdefghijklmnopqrstuvwxyz
 </xsl:variable>
 <xsl:variable name="upper">
   ABCDEFGHIJKLMNOPQRSTUVWXYZ
 </xsl:variable>
 <xsl:template match="/">
 <xsl:value-of select="translate('goldrake',$lower,$upper)"/><!--GOLDRAKE-->
 <xsl:value-of select="translate('MAZINGA',$upper,$lower)"/><!--mazinga-->
 </xsl:template>
</xsl:stylesheet>

SSL and Java (ciak 2)

credits: Vagamundos (from flickr)

credits: Vagamundos (from flickr)

Last time we spoke about accessing a site via HTTPS using the pure Sun way.

Today, we see the same problem, solved with the apache HttpClient libraries. This library require a keystore specified in the code. In order to generate a keystore, you will have to download a certification file as described in the previous post and then create a keystore using the keytool program. I don’t remember well how to create a new keystore with the required certificate via keytool (I did’t write it down), but reading the help of the program it should be something like:

keytool -importcert -alias <my_alias_certificate> -file <path_to_the_cer_file> -keystore myKeystore.ks

where myKeystore.ks is the name of the file containing the keystore. The pros of using this approach is that you can provide a .ks file among with the program, in a location desired and the program will use it, avoiding post-installation procedures to register the certificate on each jvm.

So, assuming to have our keystore into a sub-directory certs the code for using the site is in the pdf as usual.

SSL and java

credits: ph0t0 (from flickr)

credits: ph0t0 (from flickr)

Sooner or later it happens that you have to access an https via Java. Accessing a generic http (non ssl) site is quite easy using the URL and URLConnection objects.

When you try to access a site through SSL the main problem is that most sites does not have a registration in the java’s Certificate Autorithy (CA), causing the framework to refuse connection to that site. So the main solution is to register the certificate of that site in the java’s CA.

So, the things to do are:

  1. download the site certificate
  2. register it in the java’s CA
  3. accessing the site

Downloading the certificate

In order to download the certificate we are gonna use Firefox. With firefox navigate to the site and if required accept the certificate. Double click on the icon of the certificate (1), in the screen that appear choose view certificate (2), on details tab (3) use the export button (4) and save it wherever you want (5).

screen

Register the certificate

Once downloaded the .cer file (X 509 Certificate DER), you can import it into the CA using the a command line program deployed with the j2se installation: keytool.

Java’s CA and keytool are available in the $JAVA_HOME/lib/security/ and an example of using the keytool (under windows) is the following

C:\Program Files\Java\jre6\lib\security>keytool -import -trustcacerts -alias fonsai -keystore cacerts -file fonsai.cer

where fonsai.cer the file name of the certificate just downloaded.

Maybe if you are using eclipse, you will have to restart the workbench in order to make the registration visible to the jvm.

The main counterpart of using this approach is that you have to register the certificate for each jvm running the program and since certificate can expire you should have to do this operation more than one time. I advise to automate the registration operation with a shell script to be distributed among with the program.

Accessing the site

Once registered the site’s certificate, you can access it as usual using the URL and URLConnection objects. It should be enough to tell (via System.properties) an SSL provider. Here is a PDF with the code.

[CakePHP] Alias in the url. Take 2

Some days ago, I posted about having dynamic URL aliases with cake-php 1.1.18. In that post I used the AppError object trapping the missingAction error.

When I was ready for production environment, during tests I wondered that the AppError is ignored when core debug level is set to 0. While I’m asking about the utility of this behavior, I asked in the list and searched for a solution.

One solution could be to take the __construct method from the ErrorHandler, removing the Configure::read() test and paste it into the AppError::__construct() without calling the parent::__construct(). But in this way if some new feature, fixes, etc. is distributed within that method you’ll probably miss it until you monitor each release.

Finally I opted for useing the routes.php file mapping each action and then mapping the “missing action” to the controller::view() action and the manage the code inside it. Here is a PDF with an extract of the code.

[Script-Fu] webify

Finally I entered also the Script-Fu world. For the photography school I’m attempting I had to deliver to my teacher about 350 photos. posting them i JPG full resolution would have been raving. So I though to my self, why don’t learn a bit of script-fu and do a script for Gimp that will convert a directory of JPG into others JPG of smalles size?

I know I could have searched for something already done but I wouldn’t have learned Script-Fu/scheme.

This is my first script. I surely have not followed conventions and surely it could have been done better. Maybe there will be a time when I will improve it. For now it’s it and it’s working for my tasks.

The script will take a single JPG or all JPGs in a Directory, resize it to a custom size (by long image side), default 800px, convert it to 72dpi and save it with a different name. Leave a color version or a quick conversion to grayscale. This last one is useful in order to have a look for an entire set if it looks better in color or B&W.

However here is the source code (pdf) to copy and paste into an scm file.