Monday, November 26, 2012

Why I hate Internet Explorer

Or more correctly, one of the reasons I hate IE.


Thursday, September 13, 2012

Is SetCharacterEncodingFilter a thing of the past?

I thought so. But I was wrong. I thought after all those years of hacking the encoding parameters in our java application they had sorted it out. In our latest migration to JBoss EAP 5 i made sure that we didn't need those hacks. But we also had to change the jsp and response encoding to UTF-8 for other reasons.

This turned out bad. JBOSS is hard set to ISO-8859-1 internally which means that a form submission in UTF-8 will decode incorrectly. Now, we did set the accept-charset tag on all forms, but Internet Explorer ignores the property. We tried to hack the poor explorer with ugly javascripts which made it work. But finally we let in an added the good old encoding filter anyway.

Our options was to either change the page encoding to ISO. This would have broken an old external system (yepp, it's old, it must get UTF-8, it "can't" be changed). Or we could have changed the encoding settings in the JBoss configuration files. This would have broken other applications on the same server.

But still, why did the JBoss community decide to take this path? How does users in non-western countries do? Is JBoss designed for Europe only?

Thursday, August 30, 2012

Struts 2 convention plugin in a WAR in a EAR in Jboss

This issue has been bugging my for a while and I have not found any solution to it so far. It seems from google results that I am not alone with this problem.

The problem occurs when you have a Struts 2 convention based web application (WAR) inside an EAR package. And deploy it on jboss. Because of Jboss using the vfszip packaging the open symphony ClassFinder fails with a message like

c.o.x.u.f.ClassFinder - Unable to read URL 
    [vfszip:/.../server/default/deploy/MyEar.ear/MyWebApp.war/WEB-INF/classes/]
    java.io.FileNotFoundException: 
    /.../server/default/deploy/MyEar.ear/MyWebApp.war/WEB-INF/classes/ 

So. Nobody solved it in a good way yet. I'm gonna go with this solution, it'll have to do for now.

Update: I tried to implement the linked solution using reflections, but failed. Basically it has the same issue and I'm still left with hard coding the list of classes.

Friday, August 10, 2012

Surefire plugin wont run my JUnit tests!

I spent way to much time on this trivial issue to not write it down. I ran into an issue where my unit tests (JUnit 4) were running fine in Eclipse but not by the maven surefire plugin.

Google served up numerous solutions to my problem but it didn't help me. My problem was much simpler. Eclipse will run any test in any class where the method is annotated with @Test. This does not apply to surefire. If the class is not named Test, surefire will not even look for tests in it. Hence, in maven projects, we should always name test classes that way.

Friday, April 27, 2012

Code coverage on JDK7 with Emma

The latest upgrade to JDK7 did go without any issues what so ever in terms of application functionality.

The only issue so far is with Emma which stopped recording code coverage and turned to breaking tests instead giving an "Illegal local variable table length 5 in method" error instead.

What you need is this:
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.12</version>
  <configuration>
    <argLine>-XX:-UseSplitVerifier</argLine>
  </configuration>
</plugin>

Thursday, April 5, 2012

Relative file paths on JBoss EAP 5.1.2

Apparently there was a change in which kind of file URLs are correct in JBoss EAP 5.1.2. This tiny little change caused a great deal of pain in my case throwing
"IllegalArgumentException: URI is not hierarchical" in one environment but not the other.

Very well. We use the PropertyPlaceholderConfigurer with relative paths for file locations to greatly simplify the configuration differences between deployement and development environments. This is all done by simply stating
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <value>config/application.properties</value>
    </property>
</bean> 

In the applicationContext.xml to load properties from a path relative to the execution path. Running the application with maven jetty makes development rapid and simply and almost no setup is required for new developers.

With the latest change in JBoss, this could have become a very big issue. However, after a long days fiddling, here's the solution with maintained behavior.
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <value>file:${user.dir}/config/application.properties</value>
    </property>
</bean>


Sunday, March 18, 2012

Migration from Weblogic 8.1 to JBoss 6

This post is not about a tiny application. Whilst still interested in building small, simple and single purpose application and modules one must also make a living.
Right now, one of my assignments is to evaluate the possibility of migrating a large near-legacy J2EE application from Weblogic 8.1 to JBoss 6.

The business case behind this is simple. The weblogic license is more expensive, we are not using any power-features of weblogic and the licensing is unsuitable for the new virtual environments. And yes, we must upgrade in any case. Here are my notes of what has to be done to make it run in JBoss. Since I know beforehand that security might be an issue, and we are not using security, if you have it, you may stop reading.

Many of the issues I had is because the weblogic seems less strict, and only small corrections was required.

JSP tags and TLDs

For some reason, once upon a time, there was an urge to copy TLDs (like the struts ones) and place them in the war/WEB-INF folder. They would then be referenced from the web.xml and incorrectly by path from the JSPs. I have seen this many times and it's probably not a special case. This has to be cleaned up. Removed the TLDs that are in some jar-file somewhere. Removed the references in web.xml and fix the declarations in your JSPs. The uri parameter must match the uri declared in the tld-file.

A small note on custom tags. If you have tag parameters in your jsps which are not in the TLD, JBoss (catalina) will throw an exception. Weblogic will silently ignore it.

EJBs and naming

Weblogic and JBoss does create JNDI names for EJBs differently. They are placed in different namespaces and you need to change which ContextFactory is used. Most importantly you should declare names for you EJBs in the jboss.xml file, otherwise it can be hard to figure out and pick up in your code.

ear Packaging

JBoss gets really cranky if you happing to package classes multiple times in your ear-archive. This easily happens when you have ejb-jars in the ear and also includes the ejb-client jars for dependent ejbs and wars. In maven, this is an easy fix by using the "provided" scope for client dependencies and possibly also using the skinnyWars option for maven-ear-plugin. With ant, you'll have figure it out manually of course and with an older version of maven-ear-plugin you have to put in packagingExcludes in you war-plugins.

Persistence

This part is maybe the most complicated one. This is due to two main reasons. Weblogics implementation of EJBQL is more powerful and you'll have to build up the jboss.xml and jbosscmp-jdbc.xml files, corresponding to weblogic.xml and weblogic-cmp-jdbc.xml, respectlively.

EJBQL

The weblogic implementation of EJBQL supports aggregate functions like MAX and SUM. This is not supported in EJB 2.0 but in 2.1. Thus it should not be a problem in JBoss 6. However, JBoss does not support aggregated functions in nested query and a query like this

SELECT OBJECT(logg1) FROM LOGG logg1 WHERE logg1.systemId = ?1 AND
    logg1.created = (SELECT MAX(logg2.created)
                   FROM LOGG logg2
                   WHERE logg2.systemId = logg1.systemId)
won't work!
Some on these can be rewritten. They can be split into two and programmatically merged or they can be reimplemented with JPA. I haven't determined the best solution yet.

A small note on EJBQL is, like with JSPs, Weblogic is much more tolerant to small grammatical errors. You might need to put in the whitespaces and missing closing parenthesis here and there.

Persistence mappings

For the jboss files mentioned above you can find xslt templates online to convert them. They might not help you with everything thou. I haven't seen one that handles the relational mappings between entities yet and you will need to read up on this in the JBoss documentation.

ID Sequences (auto-increment kind of)
This is quite simple once you've figured it out, however it took me a while. Just add this to each entity in jbosscmp-jdbc.xml
<entity-command name="oracle-sequence">
    <attribute name="sequence">THE_TABLE_IN_QUESTION_SEQ</attribute>
</entity-command>

Datasources

We are blessed with Oracle databases. You have to add the jdbc client jar to the default/server/lib directory and then you can setup the data source in the admin console. It seems buggy however and you might need to edit the xml-file on disk which is created. Pay attention that even if you set the JNDI name to MyDataSource the JNDI name becomes java:MyDataSource.