Translate

September 10, 2013

Enable compression on Tomcat

The challenge

You always want your web application to load as fast as possible. One of the recommandation is to enable compression to reduce the number of bytes sent over the network. And here is how you do so in Tomcat

The solution

Edit your server.xml (location varies depending on the distribution but you can usually find it under %tomcat_home%/conf). Find the connectors you are using (there may be more than one) and add the part marked in red so the connector looks like this:

   <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"  
         maxThreads="150" scheme="https" secure="true"  
         clientAuth="false" sslProtocol="TLS"  
         compression="on" compressionMinSize="10"  
         noCompressionUserAgents="gozilla, traviata"  
         compressableMimeType="text/html,text/xml,text/javascript,text/css,application/javascript" />  

Restart tomcat and you are good to go.

September 3, 2013

Caused by: java.security.InvalidKeyException: Illegal key size

Java Crypto Error

The problem

You may come across a stack trace saying java.security.InvalidKeyException: Illegal key size when using some encryption library and wonder why.  Here is an example:
java.lang.IllegalArgumentException: Unable to initialize due to invalid secret key
 at org.springframework.security.crypto.encrypt.CipherUtils.initCipher(CipherUtils.java:110)
 at org.springframework.security.crypto.encrypt.AesBytesEncryptor.encrypt(AesBytesEncryptor.java:65)
 at org.springframework.security.crypto.encrypt.HexEncodingTextEncryptor.encrypt(HexEncodingTextEncryptor.java:36)
 at ..........
Caused by: java.security.InvalidKeyException: Illegal key size
 at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1024)
 at javax.crypto.Cipher.implInit(Cipher.java:790)
 at javax.crypto.Cipher.chooseProvider(Cipher.java:849)
 at javax.crypto.Cipher.init(Cipher.java:1348)
 at javax.crypto.Cipher.init(Cipher.java:1282)

The reason

There can be multiple reason but this is usually due to a missing implementation of the encryption algorithm or some restriction in key length from old times.

The solution

Quite simply, you need to add the "Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files". You can get it from here for Java 7 and here for Java 6. Just unpack it and copy the jar files to </path/to/jre>/lib/security/ and restart your application.

August 30, 2013

Git username and password

The challenge

I come across a common problem when working with Git. I am a consultant and working on different projects. This means that I do have multiple Git repository to commit to. All of them have some kind of user recognition in a web GUI. This means that the web scans the commit for the user's name and email address to check against its users and find the correct one. This will resolve, for example, into a profile picture beside the commits. As, amongst others, Atlassian Stash does.
There are multiple solution to set your name and email depending on the client you use but it is cumbersome at best.

The solution

There is a very simple and easy solution. As Git allows settings per repository, you can define a name and email for each of them. After navigating to the repository you want to configure, write:
 git config --local user.email "your@email.com"  
 git config --local user.name "Your Name"  

You may also want to set a "default" settings for new repositories. To do so, you can use the --global instead of --local
 git config --global user.email "your@email.com"  
 git config --global user.name "Your Name"  

This will set these settings for your user. You can even go further and set it with the --system. This will be active for all users on this computer

August 22, 2013

DOS format file and how to fix this in Vim

Background

You may have experienced that a script will not run on a linux machine after being edited on Windows. You get an EOF error or " bad interpreter /bin/sh^M"

The problem

This is due to how Windows file adds the line break at the end of each line. To check if this is your problem, open the file in vim. You will see ^M at the end of each line. You may also get a message related to DOS at the bottom of the window.

Solution

To fix this, there is a simple command in Vim. Type:
 :setlocal ff=unix  
And you will get the file with the correct. Save the file and, now, you will be able to run it.

August 21, 2013

How to delete all Subversion information on a local repository

Background

There are times when subversion gets messed up bad. Last time, I had a network interruption and the local repository got locked. After trying different commands to try to free it (like svn cleanup), it just wouldn't work correctly. Even after getting the lock back, the next update would fail.
I also got a friend that copied a folder from another location and, by doing so, removed som Subversion folders and corrupted the tree.

Solution

Not depending on how it got messed up, you'd want to clean it up. You may know that all informations are stored in .svn folders in every folder of your local repository already added to it. So, to remove all subversion informations, you need to delete all these folders. 
Manually, it can take some times. However, there is an easy command on *NIX based systems

 find ./ -name ".svn" | xargs rm -Rf  

This will delete all the folders for you.

August 7, 2013

ClassNotFoundException org.sonatype.aether.*

Maven changed Aether in version 3.1

If you have moved to maven 3.1 you may get this error:
 java.lang.NoClassDefFoundError: org/sonatype/aether/*   
 Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.*  

This is due to maven changing from Sonatype Aether to Eclipse Aether in the core. See release notes.
Some plugins are not updated yet. See the list on the maven wiki page.

If you have some custom plugins, they also may have the same problem. 
The only solution I found so far is to go back to Maven 3.0.x.


For more information

You can contact us at OSnode.

August 6, 2013

Themeroller to PrimeFaces theme by OSnode

PrimeFaces themes from jQuery Themerolle

This month, OSnode has deployed a new system to allow PrimeFaces users to easilly create new PrimeFaces themes from jQuery Themeroller. See the the PrimeFaces blog for post from Optimus Prime and you can use it from  this address.

Howto

  1. Go to themeroller page.
  2. On the left side, you get all settings you can change and it is rendered on the center and the right side.
  3. When, you are happy with how it looks, click dowload.
  4. Remember where you save the zip file then go to the OSnode converter.
  5. Give a name to your theme and select the zip file downloaded in step 3.
  6. Click the "Create theme jar" button.
  7. After some computing time, you will get the possibility to download the jar file.
  8. Include the jar in your project (see http://primefaces.org/themes.html for details)
  9. That's it! Use your custom theme in your favorite PrimeFaces application.

For more information

You can contact us at OSnode.