jump to navigation

Setting up SSL on Apache October 28, 2010

Posted by maxmil in : Apache,Java,Security , add a comment

Just had to set up SSL on Apache which uses mod proxy to forward requests to Tomcat.

So that i don’t forget here are the steps and commands that i had to execute.

Create self signed certificate

1) Create private key

openssl genrsa -des3 -out server.key 1024

2) Create csr

openssl req -new -key server.key -out server.csr

NOTE: CN should correspond to domain (may use *)

3) Remove passphrase from private key

cp server.key server.key.org
openssl rsa -in server.key.org -out server.key

4) Generate self signed certificate

openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

5) Copy key and certificate

cp server.crt /etc/ssl/certs/
cp server.key /etc/ssl/private/

Configure Apache

1) Make sure mod_ssl is loaded

a2enmod ssl

2) Modify path to key in default virtual host /etc/apache2/sites-available/default-ssl

SSLCertificateFile /etc/ssl/certs/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key

Configure Java

1) Connect to apache en browser via https to get certificate. Confirm security exception.

Note that if you already have an exception confirmed you can delete (in firefox Edit > Preferences > Advanced > View Certificates > Servers)

2) Export certificate (in firefox Edit > Preferences > Advanced > View Certificates > Authorities).

3) Navegate to JVM: /usr/lib/jvm/java-sun-x/jre/lib/security

4) Import:

keytool -import -alias servername -keystore cacerts -file /exported/server.pem

NOTE: The default password for the jdk keystore is “changeit”

BlazeDS Hibernate Lazy loading problem solved October 8, 2010

Posted by maxmil in : BlazeDS,Java , 2 comments

I finally got around to working on a solution to the lazy loading problem that exists when using hibernate with BlazeDS.

I think that the solution is a pretty clean one. It consists in an annotation that you put on methods returning results to BlazeDS.

The annotation configures what part of the object graph is excluded from serialization.

I was going to use dpHibernate or Gilead but didn’t really need all the advanced features of initializing associations from flex.

This solution is a light and easy one.

The code and a jar are available on GitHub

Installing JDK 6 Update 10 on debian Lenny November 17, 2008

Posted by maxmil in : Debian,Java , 3 comments

At the time of writing both the JRE and JDK 6 Update 10 have been released for over a month but are not available on the non-free branch of the official debian testing repositories. I imagine that this is because Lenny is about to go stable and the maintainers are not accepting new versions, only bug fixes.

This is a shame because Update 10 includes a major revamping of client side Java with new look and feels and much improved applets.

Being impatient i wanted to try this out.

Normally to install sun binaries as debian packages i use java-package which nicely prepares a .deb file that i can use dpkg to install. The advantage of this technique is that the new package integrates nicely with the overall system allowing you to use update-alternatives etc.

However, trying this, i found that java-package has not been updated to handle Update 10 either. The problem seems to be that it only works with versions 6 Update X where X is one single digit.

More info can be found here http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=504778

For my architecture the solution was to add this to /usr/share/java-package/sun-j2sdk.sh
"jdk-6u10-linux-i586.bin") # SUPPORTED

just after
"jdk-6u"[0-9]"-linux-i586.bin") # SUPPORTED

My architecture is i586, modify this according to yours.

Then, as usuall to prepare, install and set as default.
$ fakeroot make-jpkg jdk-6u10-linux-i586.bin
$ sudo dpkg -i sun-j2sdk1.6_1.6.0+update10_i386.deb
$ sudo update-alternatives java --config

I then wanted to try the new draggable applet feature. So i went to http://java.sun.com/developer/technicalArticles/javase/6u10_applets/ but the demo didn’t work and whats more the page told me that i didn’t have update 10 installed.

However my browser definitely is running the update 10 plugin, as verified on this site.

Could it be because i’m running iceweasel and not firefox?

Getting stdout from Tomcat 6 May 8, 2008

Posted by maxmil in : Java,tomcat , 2 comments

I am using tomcat version 6.0.14 and have been wrestling with its logging facilities. I use Log4J in my application which logs pretty much all i need to my designated log file.

However the other day i had a production error related to a hibernate query. When i turned on the hibernate show_sql property i expected the database queries to show up in the standard output of tomcat.

Since tomcat executes as a service there is no console in this version of tomcat and there is not stdout.log file in [tomcat install directory]/logs. The file used by tomcat is localhost_[datestamp].log, however my queries did not show up there either.

The solution was to add the swallowOutput attribute to my context definition with value “true”.

Open source java properties file translator January 3, 2008

Posted by maxmil in : Java , add a comment

Must have a closer look at Attesoro

Generics in Java and C# September 23, 2007

Posted by maxmil in : Java , add a comment

Brilliant article for understanding generics and the difference between the implementations in Java and C#.


Missing xalan2.jar in latest debian update of tomcat5.5 September 20, 2007

Posted by maxmil in : Debian,Java , add a comment

Just updated tomcat5.5 and several apps starts complaining that they couldn't find the class org.apache.xalan.processor.TransformerFactoryImpl.

This is because xalan2.jar is not in the /usr/share/tomcat5.5/common/libs directory.

The solution for me was to create a soft link to this directory. From /usr/share/tomcat5.5/common/libs

ln -s ../../../java/xalan2.jar xalan2.jar

Initial parameters eclipse July 31, 2007

Posted by maxmil in : eclipse,Java , add a comment

After continued problems with permGenSpace errors in eclipse i’ve found a configuration that works, initialize eclipse with the following parameters
-vmargs -Xms512m -Xmx512m -XX:MaxPermSize=256m -XX:PermSize=128m
The last two are the important ones (i could probably reduce them but i have 2Gb of RAM so i’m not too bothered).

This is what each parameter does:

ms: initial memory of the application
mx: maximum memory of the application
PermSize: additional memory used by the VM (by default configured to 32Mb)
MaxPermSize: maximum permanent memory

Metatags and cache control better on server July 10, 2007

Posted by maxmil in : html,Java , add a comment

In IE7 i have’nt been able to override the cache of an html page with metatags.<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="-1" />
It seems that the browser takes no notice of these meta-tags.

If you are serving pages dynamically (in my case the pages are generated from jsp’s) a way round this is to set the headers of the response in the server. IE does then take notice.<% response.setHeader("pragma", "no-cache"); %>
<% response.setHeader("cache-control", "no-cache"); %>
<% response.setHeader("expires", "0"); %>

Identify java version on remote server and more… March 29, 2007

Posted by maxmil in : Java,jsp , add a comment

System properties are a useful way of determining information on a remote server.

Paste the following into a jsp deployed on the server…

java.versio = <%= System.getProperty("java.version") %><br>
java.home = <%= System.getProperty("java.home") %><br>
java.vendor = <%= System.getProperty("java.vendor") %><br>
java.vendor.url = <%= System.getProperty("java.vendor.url") %><br>
line.separator = <%= System.getProperty("line.separator") %><br>
os.arch = <%= System.getProperty("os.arch") %><br>
os.name = <%= System.getProperty("os.name") %><br>
os.version = <%= System.getProperty("os.version") %><br>
path.separator = <%= System.getProperty("path.separator") %><br>
user.dir = <%= System.getProperty("user.dir") %><br>
user.home = <%= System.getProperty("user.home") %><br>
user.name = <%= System.getProperty("user.name") %><br>