java

BankID on Mountain Lion

Norwegian BankID (used by most banks in Norway) uses a java applet for login.

The current combination of java, mac osx 10.8.x, applets and BankID is a mess.

Things to note:

  • Java 1.6 from Apple removed support for web applets - so you'll need Oracle java 7
  • Java 7 from Oracle will work - but - not in Chrome (Chrome doesn't support 64 bit java - Oracle don't provide 32 bit)
  • Most BankID pages test to see if java is enabled - and after installing java - it still gives the java not installed or enabled error. The issue seems to be that you have to activate the plugin by loading an applet that doesn't test for support - for example the one on http://www.java.com/en/download/testjava.jsp prior to trying to log in to the bank
  • BankID state that there is an issue in Firefox where the OK button does not get enabled - you can get around this by holding the CMD key in for a few seconds until it enables. This is claimed to be due to a bug between Firefox and java. Note that in my testing this is exactly the same issue in Safari and the same workaround works.

So - install Oracle java, go visit a test page - log in with a workaround to get OK buttons to enable and you might just be allowed to login to your bank.

The BankID applet needs to die.

Sources:

Setting a fixed hostname alias on mac overriding DHCP

This turned up as an issue when developing webapps.

If you set a fixed hostname (local.foo.bar for example) via an /etc/hosts alias to 127.0.0.1 (perhaps you need to have access to .foo.bar cookies or similar) then you can browse localhost via the local.foo.bar name.

However - when starting tomcat under java this gave an error on hostname/url. I've had the issue running tomcat 6 under java 7 - have had reports of tomcat 7 under java 6 also being an issue.

It turns out that Mac OSX takes the hostname given by DHCP - and this can change often.

Finding the current system JAVA_HOME on mac osx 10.5+

Technical:

I always forget where this file is located - so just as a reminder ;)

To find the current JAVA_HOME for the current user (set by java preferences) run:

/usr/libexec/java_home

Details from http://developer.apple.com/library/mac/#qa/qa1170/_index.html

Java Apps banned from new mac app store

Technical:

A follow up on Java deprecated on Mac OS X?

From a response in this thread we can read:

Apps that use deprecated or optionally installed technologies (e.g., Java, [PowerPC code requiring] Rosetta) will be rejected.

Java deprecated on Mac OS X?

Technical:

There's an interesting paragraph in the latest Mac OS X Java update relasenotes New and Noteworthy - a paragraph called "Java Deprecation".1

As of the release of Java for Mac OS X 10.6 Update 3, the version of Java that is ported by Apple, and that ships with Mac OS X, is deprecated.

Struts2 i18n where application default locale doesn't match app server locale

I have a struts2 (2.1.6) based webapp which has two languages - english and norwegian. The default language for the app is norwegian - the application server (glassfish 2.1) is running under the english locale.

It didn't seem to matter what value I passed in to the request_locale parameter - I always got english.

There are two language files:

  • global_messages.properties (norwegian)
  • global_messages_en.properties (english)

The struts constant struts.custom.i18n.resources was set to "global_messages" in struts.xml.

Grails pastebin updated

Just updated the grails based pastebin.

I got fed up (read embarrassed) by the autogenerated URLs. They were simply too long as it was using UUID to generate the URLs.

So - I generated a nice new function that will generate a short (3-10 chars) random string of upper/lower case letters and numbers.

This also allowed me to have a "short url" function (similar to tinyurl etc etc) without too much extra work.

Importing Groovy/GMaven/maven projects to Intellij IDEA

When importing a maven pom that uses the gmaven plugins - remember to go into project structure settings and set src/main/groovy as sources and src/test/groovy as test sources.

I'd also like to know why on import of a project that has had mvn install run on it causes Idea to have issues about generated source mismatch etc - mvn clean then a rebuild in Idea will fix this but I can't pin down what is not right.

Creating new SSL keys with keytool for glassfish

I needed to generate a new certificate for glassfish's admin pages.

Instead of using the normal OpenSSL self-signed certificate it was easier just to use the java keystore keytool

keytool -genkey -keyalg RSA -alias
<alias_referred_to_in_glassfish>
-keystore glassfish/domains/domain1/config/keystore.jks
-storepass changeit

Note the -keyalg RSA - keytool by default uses DSA and firefox 3.0 will not accept this even with an added security exception.

Spring, Aspects, @Configurable and Compile Time Weaving using maven

Why do most people use Load Time Weaving (LTW)? It requires replacing the javaagent/classloader of your JVM which can lead to all sorts of issues.

Let's take a look at getting Compile Time Weaving (CTW) instead.

This post is using spring 2.5.2, aspectj 1.5.4, java 1.5. (Spring 2.5.4 uses a later version of weaver (3.0 vs. 5.0) - I assume AspectJ 1.6.0 but the aspectj-maven-plugin is also based around 1.5.4 - so for now we'll stick with this combination.)


Java can't send mail due to a certificate error

I use a plugin to Aperture to send mail to gmail. It was failing due to a

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path
building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target

The plugin author (plugin home page) found the following utility:

http://blogs.sun.com/andreas/entry/no_more_unable_to_find

Compile Time Weaving of spring aspects in Intellij Idea

To enable compile time weaving of the spring aspects (spring-aspects.jar) in Intellij IDEA (I am using 7.0.3 - but I assume this to be similar for other versions):

  1. Install and enable the AspectJ plugin (http://intellij.expertsystems.se/aspectj.html) - it was available in the plugin manager lists by default
  2. Under Settings > AspectJ Weaver, search for aspects - add the spring-aspects jar and enable weaving
  3. In the build menu - make sure AspectJ weaving is enabled

Deploying jars to third party maven repository via WebDAV

Technical:

Normally you deploy to a third party repository with a command similar to:

mvn deploy:deploy-file -Dfile=/path/to/file -DrepositoryId=repositoryId
-Durl=wagon:protocol://path/to/repo -DgroupId=groupId -DartifactId=artifactId
-Dversion=version -Dpackaging=packageType

But - to deploy via webdav needs a snapshot wagon.

To do this - create a temporary pom in the directory you are in (create a scratch dir or similar). This should contain:

Adding self-signed https certificates to java keystore

There are several reasons you may need to add a self-signed https ssl certificate to your local java keystore.

For me - its so that maven can access DAV shares for repository deployment.

Illegal type in constant pool

After adding

CATALINA_OPTS=-javaagent:/path/to/aspectweaver-1.5.3.jar

tomcat started failing - giving an "Illegal type in constant pool" about log4j.

This seems mainly to be due to lib differences.

To get this running on tomcat 5.5.23 I had to:

1) copy the log4j jar from my webapp to the common/lib dir (log4j was not present here before)

2) copy the commons-logging-api jar to the bin directory (replacing the version that was here before).

It seems that aspectjweaving can cause increased sensitivity to classloading/versioning problems.

spring-ldap and NoClassDefFoundError com.sun.jndi.ldap.ctl.ResponseControlFactory

When using spring-ldap - if you get a NoClassDefFoundError for com.sun.jndi.ldap.ctl.ResponseControlFactory then you need the ldap booster pack (currently 1.0).

This is available from Sun:

http://java.sun.com/products/jndi/downloads/index.html

Go to the JNDI 1.2.1 page and grab JNDI/LDAP Booster Pack 1.0 (ldapbp-1_0.zip)

Unzip and then install as an artifact:

Spring AOP and maven dependencies (<aop:spring-configured/>)

Or - why does it say my spring context xml is invalid on <aop:spring-configured/>

I've been trying to add the @Configurable to a spring project.

This means that I had to have a <beans> tag that looks like

Switching between java JDK's on debian

I use the java-package make-jpkg to install java JVM's. I have mostly used sun's JVM's up to now.

I wanted to easily switch between them (which the alternatives mechanism handles well) but also to keep the relevant JAVA_HOME in sync (for things that still need this in the environment).

The following script I added to my .bashrc

switch_java () {
case $1 in
4 ) JAVA_HOME=/usr/lib/j2sdk1.4-sun ;;
5 ) JAVA_HOME=/usr/lib/j2sdk1.5-sun ;;
esac

libapache-mod-jk under sarge

Sarge installation. Apache is 1.3.x (packaged). JBoss is 3.2.7 with tomcat.

Aim: ajp13 working

For each (or at least several) virtual host under apache we have an equivalent webapp running under jboss. We'd like to use apache as the front end server.

So - here's an example app URL:

http://hostname:8080/app/

This should be accessable under

http://hostname/app/

mod_rewrite will be used to handle

http://hostname/ -> http://hostname/app/

since some things are apache only (awstats etc).

First - get libapache-mod-jk installed

apt-get install libapache-mod-jk

Displaying classpath in ant

Technical:

Something I always forget :-)

Given

<path id="class.path">

use


<property name="cp" refid="class.path"/>
<echo message="Classpath is ${cp}"/>

Subscribe to RSS - java