Mit ‘Java’ getaggte Beiträge

Creating Chrome Extensions without Chrome (with Java)

Veröffentlicht: Juli 7, 2011 in Java
Schlagwörter:, , , , , ,

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.

Advertisements

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 (mehr …)

I’m playing around with the Features of the latest Java Plugin for Browsers.
I just can say, you should really use the JavaScript one, to create Applet- or Webstart-Tags.

Due this new features I decided to deploy my applet with Java Webstart and created a JNLP file. Works like a charm.

But after I started my applet in Standalone Mode with my created Desktop-Icon, I couldn’t resize my applications. Normally you would call the Methode „setResizable“, but JApplet doesn’t provide one.

So here is the Solution I found for this problem without developing an Extra Class to launch my Applet as an Application.

Solution -> extend the JApplet.init() Method:

Window window = SwingUtilities.windowForComponent(this);
if (window instanceof JFrame){
JFrame frame = (JFrame)window;
if (!frame.isResizable()){
frame.setResizable(true);
}
}

If you are working with JAX-WS and ever wondered, why you get a com.sun.xml.internal.ws.server.UnsupportedMediaException, don’t wonder. The Server is trying to send you an Error Page. So have a look at your Application Server or Servlet Container.

Should UTF-8 be the Default Encoding for the Java?

Veröffentlicht: April 19, 2010 in Java
Schlagwörter:, ,

Vote if UTF-8 should be the Default Encoding and not the Platform specific one.

Lesetipps – Apache, Tomcat, Load Balancing, Cluster, SSL, …

Veröffentlicht: April 18, 2010 in Java
Schlagwörter:, ,

Guter Blog mit Infos,

wie man einen Apache und einen Tomcat konfiguriert, um Features wie Load Balancing, SSL und vieles mehr nutzen zu können.

http://opentutorial.blogspot.com/search/label/Administration