SpringSource has published release candidate 2 of the upcoming 3.0 release of their Spring Framework. New Feature is the compliance with JSR-330 (“Dependency Injection for Java”). The JSR was developed together by Google (for their Guice Framework and SpringSource (for their Spring Framework) and is finally approved since 14.10.2009.

A little example shows how to develop services with interfaces and implementations without dependencies to Spring Framework or Google Guice:

The Maven pom.xml


	4.0.0
	de.schaeftlein.dev
	jsr330-sample
jar
	jsr330-sample
	0.0.1-SNAPSHOT
	Sample App with Spring 3.0 RC 2 and JSR330

		3.0.0.RC2
	

	
		
			org.springframework
			spring-core
			${springVersion}
		
		
			org.springframework
			spring-beans
			${springVersion}
		
		
			org.springframework
			spring-context
			${springVersion}
		
		
			org.springframework
			spring-asm
			${springVersion}
		
		
			org.springframework
			spring-expression
			${springVersion}
		
		
			junit
			junit
			4.7
			test
		
		
			javax.inject
			javax.inject
			1
		
	
	
		jsr330-sample
		src/main/java
		${basedir}/src/test/java

		
		
			
				src/main/resources
				
					**/.svn
					**/.svn/**
					**/_svn
					_svn
					**/_svn/**
				
			
		
		
			
				src/test/resources
				
					**/.svn
					**/.svn/**
					**/_svn
					_svn
					**/_svn/**
				
			
		


				org.apache.maven.plugins
				maven-compiler-plugin
				
					1.6
					1.6
				
			

				org.apache.maven.plugins
				maven-eclipse-plugin
				
					true
					true
					
						_svn
						.svn
					
				
			

				org.apache.maven.plugins
				maven-jar-plugin
				
					
						
							true
						
					
				
			
			

				org.apache.maven.plugins
				maven-source-plugin
				
					
						attach-sources
verify
						
							jar
						
					
				
			
		
	

a simple encode/decode interface

package de.schaeftlein.dev.spring;

public interface Encryption
{
  String encode(String value);
  String decode(String value);
}

a simple implementation for Encryption

package de.schaeftlein.dev.spring;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

import javax.inject.Named;

@Named // service name is the name of the class
public class URLEncoderEncyrption implements Encryption
{

  @Override
  public String decode(String value)
  {
    try
    {
      return URLDecoder.decode(value, "UTF-8");
    }
    catch (UnsupportedEncodingException e)
    {
      return null; // never happen
    }
  }

  @Override
  public String encode(String value)
  {
    try
    {
      return URLEncoder.encode(value, "UTF-8");
    }
    catch (UnsupportedEncodingException e)
    {
      return null; // never happen
    }
  }

}

a more secure implementation for Encryption

package de.schaeftlein.dev.spring;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.inject.Named;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import com.sun.org.apache.xml.internal.security.utils.Base64;

@Named("secure") // named service bean
public class Base64Encyption implements Encryption
{
  private sun.misc.BASE64Encoder base64encoder;
  private SecretKey key;

  public Base64Encyption()
  {
    try
    {
      DESKeySpec keySpec = new DESKeySpec("Your secret Key phrase".getBytes("UTF8"));
      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
      key = keyFactory.generateSecret(keySpec);
      base64encoder = new BASE64Encoder();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  @Override
  public String decode(String input)
  {
    try
    {
      Cipher cipher = Cipher.getInstance("DES"); // cipher is not thread safe
      cipher.init(Cipher.DECRYPT_MODE, key);
      byte[] bOut = cipher.doFinal(Base64.decode(input.getBytes("UTF-8")));
      return new String(bOut, "UTF-8");
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return null;
  }

  @Override
  public String encode(String plainTextPassword)
  {
    try
    {
      byte[] cleartext = plainTextPassword.getBytes("UTF8");

      Cipher cipher = Cipher.getInstance("DES"); // cipher is not thread safe
      cipher.init(Cipher.ENCRYPT_MODE, key);
      return base64encoder.encode(cipher.doFinal(cleartext));
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return null;
  }

}

a small interface for a service

package de.schaeftlein.dev.spring;

public interface SecureUtil
{
  void compareEncryption(String input);
}

a implementation for our service

package de.schaeftlein.dev.spring;

import javax.inject.Inject;
import javax.inject.Named;

@Named("SecureUtil")
public class SecureUtilImpl implements SecureUtil
{
  @Inject // automatically set by DI framework
  @Named("secure") // get the namend bean
  private Encryption secureEncryption;

  @Inject // automatically set by DI framework
  @Named("URLEncoderEncyrption") // get the bean by its classname
  private Encryption unsecureEncryption;

  public void compareEncryption(String input){

    String encodedSecure = secureEncryption.encode(input);
    System.out.println("Secure encoded: "+encodedSecure);
    String encodeUnsecure = unsecureEncryption.encode(input);
    System.out.println("Unsecure encoded: "+encodeUnsecure);
    System.out.println("Secure decoded: "+secureEncryption.decode(encodedSecure));
    System.out.println("Unsecure decoded: "+unsecureEncryption.decode(encodeUnsecure));
  }
}

finally a main class for testing

package de.schaeftlein.dev.spring;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Main
{

  /**
   * main method
   */
  public static void main(String[] args)
  {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(Main.class.getPackage().getName()); // new way to get Application context without applicationContext.xml available
    SecureUtil util = ctx.getBean("SecureUtil", SecureUtil.class); // get bean with new generics method
    util.compareEncryption("an sample input string 1234567890");
  }

}

output of our Main class

19.11.2009 18:56:03 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@c1b531: startup date [Thu Nov 19 18:56:03 CET 2009]; root of context hierarchy
19.11.2009 18:56:03 org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor 
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
19.11.2009 18:56:03 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@a83b8a: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,secure,SecureUtil,URLEncoderEncyrption]; root of factory hierarchy
Secure encoded: QDQvd4uK14YNUQ4uoqhqsZEMDDxUqJAMyisvZr2wsA2GyMC5tSEIiw==
Unsecure encoded: an+sample+input+string+1234567890
Secure decoded: an sample input string 1234567890
Unsecure decoded: an sample input string 1234567890

Tags: , , ,

ralf on November 17th, 2009

A beta version of Chrome OS is available as VMX/VMDK image for vmware or virtualbox and live cd. Chrome OS is a OpenSuSe based operating system around the Google Chrome browser.

Steps to test VM image of chrome os beta

  1. Download VMDK image
  2. Extract tar.gz File to standard folder of vmware
  3. Start vmware server
  4. Choose from “Virtual machine” menu “add Virtual machine to inventory”
  5. Choose VMX file inside extracted image of chrome os
  6. Upgrade Virtual machine to newest “hardware” by choosing link on right side from the vm summary page
  7. Remove Network Connection from VM and Add new one with “Add Hardware” and type “Network Adapter” with “Nat” mode
  8. Boot VM and cornfirm warning about IDE geometry and scsi controller
  9. Click on “Make Goggle chrome default browser” and confirm dialog
  10. Click on computer button (down left side) and click under status on network connection
  11. Enter root password: root
  12. confirm warning about network manager with ok
  13. Choose under “Global Options” network setup method “traditional method with ifup”
  14. Go to “Overview” tab and click on “edit” button below
  15. click on “next” button
  16. go back to “global options” and change back to “user controlled with networkmanager”
  17. Reboot machine by clicking on computer and shutdown with type reboot
  18. After reboot you can surf with google chrome without any problem

chrome_os

Tags: , ,

Windows 7 Home Premium has no XP Mode Feature like in Pro or Ultimate Edition to run an Windows XP virtual machine seamless. Home Premium can be upgraded by Anytime Upgrade within Windows to Professional or Ultimate (90$* or 140$*). You need at least Professional Version for XP Mode. So i looked for alternatives. Under Windows XP was VMWare server 2.x my first choice without seamless mode. Seamless Mode made VM windows be available in host OS as “normal” windows without the rest of the VM OS. One Alternative is VMWare Workstation 7 with seamless mode (176€*). Paralells has currently an beta version available with Coherence (seamless) feature. Virtualbox as open source alternative has seamless mode too. You need only to install the guest additions of virtualbox, reboot after installation and call from menu “seamless mode”.

So i give Virtualbox a try and installed the current 3.0.10 version under Windows 7. VirtualBox can work with VMware VMDK Hard disks out of the box.

Steps to convert from VMware to Virtualbox:

  1. Start VMware image under VMware
  2. Uninstall VMware Tools inside VM
  3. Shutdown VM
  4. Open DOS command shell in VM folder
  5. set path variable to include VMWare server folder: set path=;%PATH%
  6. convert splitted VM hard disk to single file: vmware-vdiskmanager -r source_multiples.vmdk -t 2 single_file.vmdk (use ” to surround file name if file name contains spaces)
  7. copy new single_file.vmdk and single_file-flat.vmdk to \harddisks on host os with virtualbox
  8. Start VirtualBox under host OS
  9. Open in file menu “Virtual media manager”
  10. Go to “Hard Disks” tab
  11. Click on Add Button and choose single_file.vmdk
  12. Close dialog with OK button
  13. Click on “New” button to create a new VM
  14. Click on “Next” button
  15. Enter name for new VM and choose operation system including version (in my example Win_vista” as name, “Microsoft Windows” as OS and “Windows Vista” as version)
  16. Set memory to a suitable value (on my machine i prefer 512MB for good enough performance)
  17. On the next page choose “Use existing hard disk” and select from Drop down the old VMware hard disk image
  18. Click on Finish
  19. Open Settings of new VM to correct problems with different hard ware in VMware and VirtualBox
  20. Go to System => Motherboard and “enable IO APIC”
  21. a had an scsci lsi logic controller under VMware: Go to “Hard Disks” and “Enable Additional Controller” including selection of “SCSI (Lsilogic)”s
  22. Start new VM
  23. Install Virtualbox guest additions from vm window menu under “Devices”
  24. reboot vm
  25. Start for example a IE windows inside vm and call from “Machine” menu “seamless mode”

Currently that doesn’t seems to work with windows vista. Another VM in virtualbox with windows XP Professional works as expected in seamless mode.

Keep in mind that such a migration with Windows Vista as guest os needs another activation because of changed multiple hardware components.

Another possibility is to install the unofficial Virtual PC 6.1 for windows 7 from the knowledge base (32bit / 64bit). As described here you see in the windows 7 start menu the entries of the installed programs under the xp vm to start them directly in seamless mode. Comparing to the windows 7 XP mode their is the requirement for a separate windows xp license for a windows home or starter host os. Windows 7 professional or ultimate include such a license for a virtual windows xp on the same machine. Virtual PC needs a Virtualization hardware support like intel VT-X or AMD-V. The installation of Virtual PC fails if the processor and mainboard don’t fit to this requirement.

Startmenu entry of Virtual PC

Startmenue Virtual PC

Start installed Apps inside XP VM from Windows 7

Start Apps inside XP VM from Windows 7

Seamless started XP VM Application under Windows 7

Seamless started App

*Price are only snapshots from the manufacturer websites without any guarantee and only provided to compare the possibilities.

Tags: , ,

Upgrading ant was in the past no big deal. Just download the binary archive, extract it and adopt the ANT_HOME environment variable. ANT_HOME is set to the extracted folder and PATH contains a entry %ANT_HOME%\bin. So PATH does not need to change during an ant update. I’m recently updated from ANT 1.6.5 to 1.7.1. and was a bit suprised by the output of ant -version. It still shows 1.6.5 as version. I checked the environment variables but everything was fine. The problem is that ANT batch files look in different folders according to the manual. Prior to the ANT_HOME\lib folder will be the files in USER_HOME\.ant\lib be added to the classpath. This user home folder was on my machine still filled up with the jars from the 1.6.5 release. After deleting the contents show ant now the correct version. I understand the purpose of having additional libs available for own used tasks but the result behavior was annoying.

Either Vodafone and T-Mobile use hidden picture compressions and remove alt text inside web pages when you surf with a UMTS stick. The traffic goes through a transparent proxy with that “feature”. Pictures inside browsers have less quality. Most annoying for me is that if you browse on geocaching.com for Geocaches on a map. You see normally the name of the cache if your mouse goes over the cache icon on the map. With a mobile internet connection you see a hint that “Shift-R improves quality of that picture and SHIFT-A improves the quality of all picture on that page”. A solution for this is a firefox plugin called: “Modify Headers“. Go to the extras menu and open “Modify Headers” entry. Enter a new rule and in the first field (Name) “Cache-Control” and in the second field “no-cache” (Value). Save the rule and enable them. Restart the browser. Now reopen with firefox a page with pictures. Quality as with normal internet connections and no more annoying hints to improve quality. In geocaching.com maps will now the name of the cache presented as expected.

Tags: , , , ,