At the moment, I’m working on some Chrome Extensions.

I struggeled around, which type of Extension I should create. My main problem is, that I want to create an Extensions, which is delivered with our Web Application.
This brings me to the point, that some configurations have to be set on Runtime. But how should I do that, if the CRX-File was already packed.
So I decided to implement the Algorithmns I found in Languages like Ruby or Python in Java. Therfore I had to fight with extracting the Public Key from the PEM File.

First Steps I had done was, that I converted the PEM File with “openssl” to a DER File. With some SUN specific Classes, I could extract the Parameters I have need to create a Public Key.
Later I changed it to use Bouncy Castle, which allows to extract them, with out using Classes which are JRE specific. (with my normal way, it would not work on IBMs JRE for Example)

Gist, what has to be done, if you have the Public- and Private Key.
https://gist.github.com/1069587

The complete Project can be found on my github Repository manzke @ github

How to extract the PublicKey can be found in the Projects “crxmake-console” and “crxmake-console-bc

The easiest way is to:
- zip all your content (go into your WebApp-Directory and create a zip)
- lets create the PEM File for it (with for example chrome://extensions and choose “Load unpacked” or “Pack Extension”)
- call “java de.devsurf.chrome.extensions.CrxWriter yourapp.crx yourapp.zip yourapp.pem” (with “crxmake-console” you have to transform your pem first with “openssl pkcs8 -topk8 -nocrypt -in key.pem -inform PEM -out key.der -outform DER”)

Have fun. I will extend the Project with some Examples how to automatically generate a PEM File, JAX-RS Extension to pack it and create the CRX at runtime.

Windows Home Server 2011 with cool Features?

Veröffentlicht: April 17, 2011 in Windows

A lot of people are bashing Microsoft for removing the Drive Extender, because of:
- there is no automatic mirroring of their files
- they don’t have the possibility to great big all-in-one volumes

Today I’m migrating my old DriveExtender Folders to my new WHS 2011 and had a look at the “Server Manager”. In the “Server Manager” you find the Disk Management from Windows.
After some quick look, I found pretty cool Features:
- Stripset Volume
- Mirrored Volume
- Spanning Volume

With a Mirrored One, you have the same functionalities like with DriveExtender, but without the CPU expensive DE Application. (this was the first one, I deactivate, because my system was not able to do anything)

With a Stipset One, you get the possibilities, that the Files are spread over several Hard Drives, so you can take advantage of the power of multiple reads.

With a Spanned One, you get exactly the possibility the most of the People want. They want a big Volume, with the size of 3 HDD. (I can’t understand it – buy a bigger drive if you need to :))

So try to learn a little bit about Windows and you get a whole bunch of exciting features. If you don’t want to, buy a tool like DriveBender or whatever, which is a DriveExtender for WHS2011.

The last weeks, I waited for the News, that the Windows Home Server 2011 is available. (on MSDN/Technet)

After I found the news (thx to Twitter) I started some hours later the download and searched for some Tutorials, how to install it. There are a lot of them out there, but nothing of them really helped me out, because I stumbled into some stupid User Failures and Hardware Limitations.

Installing WHS 2011 on X312 DataVault:
- download the ISO for the WHS 2011
- create a bootable USB-Stick with the Help of a Microsoft Tool (http://me.lt/9v1PD)
- create the necessary config file (cfg.ini) for the headless installation and copy it to your USB-Stick
- remove all hard disks from your HP
- put the hard disks which should be the new OS drive into Slot 4 (because my system doesn’t boot from USB Stick, if there is a HDD in Slot 1 with nothing on it)
- place the USB Stick in the Bottom Rear Slot
- start the HP (if you have a USB Stick with a LED it should start blinking after a while)
- the Server Installation will be started and the Installation Files will be copied to the OS drive
- the server tries to restart (in my case it booted again from the usb stick and nothing happened after that)
- remove the usb stick
- restart you HP
-> the Headless Installation starts
- check you Router for a new Server with an IP
- point your browser to http://IP
- follow the Web Site for the Installation

Attention: I had the problem that the Installation abort during the initial Partition creation. The Problem is, that Windows is extending your “cfg.ini” with the line “Processed=true”. This is a little tweak to save the system, that it doesn’t reinstalls every time.
So if the Installation aborts, take the USB-Stick from your HP and remove the Line to start again.

“cfg.ini” File:
[WinPE]
InstallSKU=SERVERHOMEPREMIUM
ConfigDisk=1
CheckReqs=0
DefaultServerName=YOURSERVERNAME
[InitialConfiguration]
AcceptEula=true
DefaultServerName=YOURSERVERNAME
PlainTextPassword=Passw0rd
#at least 8 chars with Upper-Case Letters, Numbers, Lower-Case Letters and Special Characters like #
PasswordHint=Password Hint
Settings=All

Hope it helps somebody :)

Spring has left the Building!

Veröffentlicht: Oktober 7, 2010 in Automatic Binding for Guice, Java
Schlagworte: , , , ,

Hi,

my Name is Daniel Manzke and I’m one of the Co-Moderators of the Xing-Group for the Java User Group Berlin-Brandenburg (Germany). I’m also organizing Presentations for the Group. I’m using Java for 6-7 years and worked with Spring for 3-4 years. At the moment I’m working on the Automatic Binding of Beans, Modules, Configurations and AOP for Google Guice. #GAB

So enough about me, I justed want to tell you a short story and I want to know from you, if I’m so wrong.

Some weeks ago I wrote Adam Bien an Email and asked him if he would present all the new Stuff around Java EE 6. I really like the guy, because he is pragmatic and you can discuss with him, without the normal flame wars of Programmers. (you should visit one of his presentations!)
We agreed that the 25.01.2011 would be the perfect date and ImmobilienScout24 will allow us, to present in one of their rooms. (with Pizza and Drinks – Thanks!)

Disclaimer: This blog and my opinions have nothing to do with ImmobilienScout24 or Adam Bien. These are my personal opinions.

In a later mail Adam had the great Idea, that we could make a Side-by-Side presentation. We thought Spring would be a nice Partner. I really liked the idea to hack an Example Side-by-Side with Java EE and Spring. Why? Because Spring always wanted to replace EJBs and all the heavy Stuff of Java EE.

So I started to search a good Spring-Presenter who would like to do this hacking. And here begins the funny part!

One guy (I don’t want to blame anybody so I’ll call him Mr. S) Mr. S wrote me that he liked the idea, but this comparison of the two Stacks doesn’t make a sense for him.
He wrote me, that you can create the Presentation Example with Spring, CDI, EJB and without Java EE, because Spring is so flexible. “And you can use Xml, Annotations and all this stuff.”

Until here I could follow him a little bit, but than he begun to write me the real features and advantages of Spring.

Mr.S wrote, that we can’t compare the Stacks, we should instead show how easy it is to bring such an App into the GAE, how to integrate Caching, how to integrate Twitter and how to connect NoSQL-Databases. “Java EE has no rudiments for the needs of the Future”

At this point I started laughing for about one hour and had a lot of discussions with Friends.

Does Spring has left the Building? Are you using Spring anymore? What DI-Implementation would you choose if you would start a new Project?

For me it is clear, I’ll never use Spring again. (only if I have to) Spring is just to heavy and not lightweight anymore. They tried to implement everything and make everything better. Do they have reached their aim or do they have lost their focus?
There are needs for NoSQL and all the stuff, but not for my Customers. I don’t know if they know how to write NoSQL, but I know that they are not able to administrate it.

So there are a lot of scenarios where I’m happy that Java EE is on the best way, to get really lightweight and Adam will show us all the Core-Stuff.

I’m really glad to know, that he is not one of the Marketing Guys!

So let us discuss, if Spring is useful anymore. If Java EE is fit for the Future. I’m really interested in your thoughts!

So,

it was quite for some time now. (12 days :)) My vacations are over and I have to develop GAB (Automatic Binding for Guice) in my spare time, but no problem so far. This means my evenings will be longer. :)

First good news: GAB is now listed as official 3rd-Party Extension for Google Guice!
Second good news: I release v0.7! :)

The blog was quite, but github was under fire :)

So what’s changed so far?

Summary:

  • Added Automatic Binding of AOP Interceptors
  • Added Automatic Binding Configurations for java.util.Properties
  • Added Automatic Binding Configurations Apache Commons Configurations
  • Added rocoto (Simple Configuration) to the Integrations
  • Improved JavaDoc, JUnit-Tests and Examples

Added Automatic Binding of AOP Interceptors

This Feature is one of the coolest things. :) You can use your existing AOP-Alliance compatible MethodInterceptors. Just annotate them with @Interceptor and they will be bound automatically.
But Guice needs some more Informations:

  • Which Classes should be monitored
  • Which Methods of this Class should be intercepted

Normally you would pass a Matcher-Object to the Guice-Binder. Due the fact that this should happen automatically, I introduced two Annotations, which will mark the Methods, which returns the Matcher-Object. @ClassMatcher and @MethodMatcher

@Interceptor
public class AnnotatedMethodInterceptor{
    @Invoke
    public Object invoke(MethodInvocation invocation) throws Throwable {
	return invocation.proceed();
    }

    @ClassMatcher
    public Matcher<? super Class<?>> getClassMatcher() {
	return Matchers.any();
    }

    @MethodMatcher
    public Matcher<? super Method> getMethodMatcher() {
	return Matchers.annotatedWith(Intercept.class);
    }
}

This Example is a complete Implementation of a MethodInterceptor. There are different ways you could go. Use your existing MethodInterceptors, which implement The MethodInterceptor Interface.
If you choose this way, you need to annotate at least two Methods for the Matchers.

The second way can be, that you extend my abstract GuiceMethodInterceptor Class, so you need no Annotations.

Or you are going the complete dynamic way, like the one displayed above. Just annotate the Matcher-Methods and the Method which should be invoked, if a monitored Method matches the Criterias.

Added Automatic Binding Configurations for java.util.Properties

GAB is now able, to bind your needed Configurations automatically. :)

You just need one annotation, which informs GAB, if you want a Named- and/or Lazy-Binding and where it find the Configuration File (Classpath, File, URL)

@Configuration(name="config", path="/configuration.properties", pathType=PathType.CLASSPATH)
public class Example{
    @Inject @Named("config")
    private Properties config;
...
}

Added Automatic Binding Configurations Apache Commons Configurations

Or are you more a Friend of Apache Commons Configurations?

@Configuration(name="config", bind=PropertyListConfiguration.class, path="http://devsurf.de/guice/configuration.plist", pathType=PathType.URL)
public class Example{
    @Inject @Named("config")
    private PropertyListConfiguration config;

...or...

    @Inject @Named("config")
    private Configuration config;
}

Added rocoto (Simple Configuration) to the Integrations

So you don’t want a Properties or Configuration-Object? You could use the rocoto-Extension (rocoto-googlecode and homepage). This allows you to direct inject your values into an Object. GAB will do the Rest for your. (Automatically Binding/Installation of rocoto-Features)

@Configuration(path="/configuration.properties", pathType=PathType.CLASSPATH)
public class ExampleImpl implements Example {
    @Inject @Named("message")
    private String message;
    
    @Override
    public String sayHello() {
	return "sayHello() - "+message;
    }
}

No boilerplates anymore! :)

Checkout the Examples

So I just can say, check out the Examples and JUnit-Test! You will find several Examples, how to use the different Modules.

Straight to v1.0

The Release of the v1.0 is not so far away. At the moment it is planned for the End of October. Why so long? I’ll make sure that it is not only tested on Windows. I’m going to create a Web Application for Remote Configurations. So you can keep the Customer specific Things out of your Applications. This one will be tested at least under Windows/Linux and Tomcat/Glassfish.

After finishing that, I’ll release! Promised! :)

Btw: I tested the last release with the Google Guice 3.0-Branch. Works like a charm! Using only JSR330-Annotations leads to no heavy dependencies to Guice. (and if you want to remove all Source Code-Dependencies – checkout the JNDI-Example for Guice)

		<dependency>
			<groupId>de.devsurf.injection.guice.integrations</groupId>
			<artifactId>de.devsurf.injection.guice.integrations.guicyfruit</artifactId>
			<version>0.6.2-SNAPSHOT</version>
		</dependency>

This will add the JSR250Module of the GuicyFruit-Extension to your Classpath and the Scanner will find the Module, because it is marked with @GuiceModule.
So you can annotate your Classes with @PostConstruct, @PreDestroy and/or @Resource.

In my git-Repository you will also find an Example-Folder, where all Features are used. From automatic Binding of Classes, over automatic installation of Modules, to using JNDI and/or Multiple-Bindings.

I’ll show it in the next Example how to use it.

In our Example we have one Interface “Example” :) :

public interface Example {
    String sayHello(); //will be called in our Application
    void inform(); //will be called through @PostConstruct
}

Our Implementation is as easy and boring as you would expect it :) :

public class ExampleImpl implements Example {  
    @PostConstruct  
    public void inform(){  
	System.out.println("inform about post construction!");  
    }  
    
    @Override  
    public String sayHello() {  
	return "yeahhh!!!";  
    }  
}

and for completeness a Module, which will be installed automatically which will bind our Interfact to the Implementation:

@GuiceModule
public class ExampleModule extends AbstractModule {   
    @Override
    protected void configure() {  
	bind(Example.class).to(ExampleImpl.class);
    }
}

You see how difficult it is? :)

Oh and I forgot our Application. We will use the StartupModule, which only wants to know about the ClasspathScanner-Implementation and which Packages should be scanned.
After creating an Injector, we will retrieve an Instance of our DynamicModule, which is bound to the ScannerModule.
Last but not least, this Module can be used to create a new Injector.

public static void main(String[] args) throws IOException {  
	StartupModule startupModule = StartupModule.create(VirtualClasspathReader.class, ExampleApp.class.getPackage().getName(), JSR250Module.class.getPackage().getName());  
	Injector injector = Guice.createInjector(startupModule);  
  
	Module m = Modules.combine(startupModule, injector.getInstance(DynamicModule.class));  
	injector = Guice.createInjector(m); 

	System.out.println(injector.getInstance(Example.class).sayHello());  
}

Attention: At the Moment there is something I don’t understand. When I use my original Injector to create a ChildInjector, all Interface-to-Class-Bindings work like a charm. But I install a Module, which will bind a TypeListener or something else, they are not recognized.
I’m not sure if this is a Bug or a wanted behavior. So we are only able to use GuicyFruit, if we create a new Injector with the Help of the DynamicModule.

Guicefy JNDI

If you are working a lot with JNDI and/or JavaEE you often have to work with a Context. A good description about the Use Case can be found on the GuicyFruit Wiki. I’ll only describe how you can use it with my Extension.

First of all you will need a “jndi.properties” with the ContextFactory, our Class for the ClasspathScanner and which Packages should be scanned. (sounds familiar? :))

java.naming.factory.initial = ...integrations.guicyfruit.GuicyInitialContextFactory
guice.classpath.scanner = ...scanner.asm.VirtualClasspathReader
guice.classpath.packages = ...

After that you need to create a new Context and lookup your Instances with the help of it. The Rest is magic. :) (behind the scene there is the normal automatic binding and installation of modules/beans)

public static void main(String[] args) throws Exception {  
	InitialContext context = new InitialContext();  
	Example example = (Example) context.lookup(Example.class.getName());  
  	
	System.out.println(example.sayHello());  
}

On the road to Version 1.0 I have to invest a little bit in the rocoto-Integration and further Tests/Documentation.

The work on Automatic Injection/Binding for Guice is in heaviy progress. I added the possibility to use the JSR330 and/or Google Guice Annotations.

So you can create a Named-Binding due using the @Named-Annotation. Due the fact, that the Guice-Named Annotation is not able to annotate a Class, I only support the javax.inject.Named-Annotation.
If you annotate a Class with it, it will result in

binder.bind(interface).annotatedWith(Names.named(annotation.name())).to(annotatedClass)

To declare a Singleton you can use the @Singleton of the JSR330 and/or the Google Guice-Annotation.

binder.bind(interface).to(annotatedClass).in(Scopes.SINGLETON)
/* for named resources */
binder.bind(interface).annotatedWith(Names.named(annotation.name())).to(annotatedClass).in(Scopes.SINGLETON)

After I submitted this feature, I want to release a new Version. So I added the Maven Release Plugin and tried to do “mvn release:prepare” and “mvn release:perform”.
What a big mistake. :)

My Environment?

  • Windows 7
  • Github Account
  • git 1.7.x + msysgit
  • Maven 2.2.x

I faced several problems. First of all I didn’t recognize, that I don’t had the distribution section, due the fact that the most Maven Repository are only working if you have a project there, I decided to use the Sonatype Repository.
I just can recommend to every github User which needs one, get your account there!
You create a Account, create a JIRA ticket and after one Day you can upload to OSS. The big advantage is, you can stage your releases. So release your version and if your think your are done, bring it from a Stage-Level to a Release and it wil be synched to Maven Central.

Have a look at the Usage Guide

After adding a “settings.xml” to my “~\.m2″ Folder, I also decided to encrypt it, because you have to store your Sonatype-Account Settings there.

How-to do it? Maven Encrypt Password

What I also can recommend is, that you create a Root-Project, which inherits from the Sonatype-POM. You need this step, because they already configured the plugins, which you need for you. Parent POM Settings

After this step you need to configure GPG. For releasing to Maven Central you have to sign your Releases and Snapshots. For me the easiest way was, to remove all gpg*.exe Files from my Git-Installation.
I installed a newer Version: gpg4win.
Nevertheless the easiest way (whatevery gpg you use) you should create a certificate and import it with gpg –import mycertificate.asc.
The problem with the Git gpg was, that it search for my certificates in ~\.gnupg. But I don’t have this directory. You can overwrite the directory with passing -Dgpg.homedir= when using mvn release:*.

All the problems I had are related to the Unix-Environment for Windows. Due the fact, that it uses Unix-Folder Path, but partly working with Windows-Paths Style, I had a lot of problems.

  • Not finding POMs (your pom is outside of the repository
  • StringIndexOutOfBoundsException when using the Release Plugin Version 2.0

How could I overcome these issues?
I’m working with git-bash, but the first thing I do is, type cmd. So you have your whole Environment, but working in Windows-Style.
If I’m working with git, I’m using the Bash-Style not the Windows one.
You also need the git-bash because I didn’t get it up and running to use the ssh-agent under Windows. But if you are starting the git-bash this will work, because it ask you while startup about your Passphrase. How-to start SSH-Agent

EDIT: The problems with Windows, Maven, msysgit is how you start your git-bash. Start your bash with the Help of the Windows Command. Doing it this way, the Letter is “F:” (or whatever :)). Starting directly the git-bash it is “f:”.

EDIT 2: When using the Command Line + Git-Bash, you should change to your local drive with “F:”. The major point is the Uppercase of the Letter!!! Without it, the Maven-Release-Plugin 2.0 will fail.

Some Tips&Tricks:

  • Use -DautoVersionSubmodules=true if you have multiple Modules, but want just one Version Number

I hope my comments, can help you a little bit, while working with Maven, git/Github and Windows.

If you have questions, don’t hesitate to ask me. :)

On Monday I released my “Automatic Injection for Guice“, which should help to automatically create Bean bindings and install Guice Modules.
This is done, due using Implementations of Classpath Scanners. At the moment there is my own pure Implementation, which uses ASM to inspect the classes. You can also choose between the Reflections-API or a Guice Extensions which was created by Sonatype.

Reflections has the biggest advantage at the moment, because it scans the classpath in parallel if you have multiple Cores/CPUs. One Problem I figured out is, that the Binder of Guice is not threadsafe. So if you are want to use it in parallel, make sure that you synchronize it.

In the last stage, my extension added the GuiceModule- and AutoBind-Feature by default. Due the fact, that this can have bad behaviors you can now overwrite it. The “bad” behaviors can result of multiple bindings. If you for example have an automatic installed Guice-Module which binds your class and if the class is annotated with @AutoBind, which would lead to another binding.

The default StartupModule still uses both Features. Create it like that:

StartupModule.create(VirtualClasspathReader.class, "de.devsurf", "net.java.dev.webdav.jaxrs")

StartupModule is an abstract Class, which should be used, if you want to overwrite the used Features. It therefore declares an abstract method “bindAnnotationListeners”.
To bind multiple Implementations we are using the Multibindings Extension for Guice.

So if you only want the automatic Module installation, just bind the GuiceModuleListener:

public class ExampleStartupModule extends StartupModule {
    public ExampleStartupModule(Class<? extends ClasspathScanner> scanner, String... packages) {
        super(scanner, packages);
    }

    @Override
    protected void bindAnnotationListeners() {
        Multibinder<AnnotationListener> listeners = Multibinder.newSetBinder(binder(), AnnotationListener.class);
        listeners.addBinding().to(GuiceModule.GuiceModuleListener.class);
        //listeners.addBinding().to(AutoBind.AutoBindListener.class); //used for Automatic Bean Binding
    }
}

I extended the Examples which can be found on Github Automatic Guice Injection.

Still to go:

  • Maven Release
  • JUnit Tests
  • GIN Release (if possible :)) – Research has to be done.

Today I wanted to share a new Proof-of-Concept of mine.

I’m working for an ECM company, which often faces to create new Integration for customers or in other products. Some months ago I created a http-based Interfaces for a customer. To give it a general touch, I decided to make it highly configurable, so it can be used for more projects.

This led me to the Command- and Chain of Responsibility-Pattern. I created a mechanism to configure the steps, which are taken when a new document should be archived. These Plugins (Java Classes) are annotated, so I can find them at runtime.

You ask yourself now, what does it have to do with Google Guice?

I started the project without Dependency Injection and used Reflections (http://code.google.com/p/reflections/), to scan my Classpath for my plugins. Due the fact that I have vacations and have to look after my son (15 months), I started to investigate a little bit to learn GWT and Guice.

I really like the idea of the Guice ESL to bind all my stuff, but for a project like mine where I need configurable bindings, this doesn’t fit. So I started to search for Classpath Scanners for Guice and found a project created by Sonatype.

This project did exactly what I want. It scans my classpath and informs me about Classes and its annotations. The problem was that just for scanning the footprint was to much and there were some design decisions which I don’t like.

So I created the “Guice Automatic Injection”-Project, with a small Classpath Scanner which uses ASM to load and inspect classes. I also created some interfaces, so I can use Reflections or Sonatype as a Scanner, too.

After a lot of experiments, I found my way how to do it. I created some listeners.

Number 1: Installs all Google Guice Modules, which are annotated with @GuiceModule Den Rest des Beitrags lesen »

Installing Hudson under Ubuntu with apt-get

Veröffentlicht: Juli 30, 2010 in Java, Ubuntu
Schlagworte: , ,

Nice description how easy it is to install hudson under Ubuntu:

http://pkg.hudson-labs.org/debian/

The biggest advantage is the automatic update with apt.

Ok after playing around it’s easier to download the WAR-File and deploy it in my Tomcat6. ;) After that you will get a nice AccessControlException, which blocks the access to a Class because of the Security Manager. This can be disabled with editing the “/etc/default/tomcat6″.

Solution was found here: http://testinfected.blogspot.com/2009/01/hudson-gets-accesscontrolexception-when.html

After you did this you should add the -DHUDSON_HOME=… in /etc/default/tomcat6 and do a chown, because the tomcat is running under the user tomcat6 and will not have enough rights, to create files there.

Also found some of the hints here: http://adelio.org/hudson-installieren-tomcat-ubuntu-9-10/