JAX-RS applications in OSGi – whiteboard style

August 20th, 2011

There are various ways to publish a JAX-RS application when running inside OSGi. Some use Blueprint or Spring, and I’m sure there are other methods. I’d like to show how you can publish JAX-RS applications using the whiteboard pattern.

Read the rest of this entry »

OSGi Bundle Utility 1.0 released

November 18th, 2010

Writing OSGi bundle manifests by hand is nothing anyone wants to do, although some entries will always need to be added explicitely. The most prominent of tools for automatically getting imports and exports right is Peter Kriens’ Bnd. However, I found Bnd difficult to manage and to get to work right with Apache Ant. I wanted something simpler because in most cases, you don’t need all the flexibility Bnd provides. Finally, I wanted the bundle descriptor to be written in XML. So, I wrote my own tool. It turned out to work quite well, and it was a good way for me to learn more about OSGi. I’ve finally taken some time to document it and make it available to anyone interested. Please note that it does not aim to handle all possible cases. The idea is to follow the 80:20 rule to ensure ease of use for most use cases.

So, if you produce OSGi bundles using Apache Ant and you’re not quite happy with Bnd or writing bundle metadata by hand, my OSGi Bundle Utility might be something for you. The utility is published under the Apache License v2.0. Source and Binary distributions and documentation is available here.

Hopefully, I’ve followed all the best practice and it is useful to some people. I’ve been using it for over a year now for dozens of bundles and for converting third-party JARs to OSGi bundles. Feedback is welcome!

10 Years in Open Source

October 24th, 2010

Sylvain Wallez indirectly reminded me that I, too, have my 10-year anniversary in the Open Source world this year. On October 24, 2000, my first post went to the fop-dev mailing list (Apache FOP developer list), 11 months after the Apache FOP project had started.

I had started a new job back then which began with a project that should format invoices from the health sector to PostScript and print them on large-scale printers including automatic packaging. And for that XSL-FO looked like the right technology, but FOP had to learn how to use fonts other than the base 14 set (Helvetica, Times, Courier, Symbol and ZapfDingbats). Finishing some work started by someone else, my first contribution was initial support for custom Type 1 fonts.

Today, I’m probably the FOP contributor with the longest service record in the project.

Mailing List Stats @MarkMail.org

I went through the hype phase (2001-2003) as well as the difficult time of the redesign after the famous 0.20.5 release which saw an almost complete exchange of the project team between 2003 and 2005. From 2005 on, we worked towards a stable FOP again that quickly surpassed the old 0.20.5 release for which soon there was almost no expertise around anymore. It’s unbelievable how many people still use 0.20.5 and say “we can’t upgrade”. Many of the problems they have are simply solved in the current release. Anyway, since this year’s 1.0 release, FOP finally doesn’t carry that undeserved taint of an 0.x software anymore. It was just a version number but not an indicator of FOP’s production readiness. The initial goal of a complete implementation of the XSL 1.0 standard was just unrealistic. There’s not even one commercial implementation on the market which achieved that goal. Many people came and went during all that time. FOP is what it is today through contributions from all of them.

Lately, AFP is a big topic where FOP took big leaps forward in the last 2-3 years. Color is also becoming more and more important as color printing gets cheaper and transpromo is gaining interest. Even in today’s world the number of pages printed still increases every year. Apache FOP is well positioned to cover the printed document as well as the electronic document. XSL is an established and accepted technology today. And Apache FOP is often the “entry drug” for people who start XSL. Many stay with it producing millions of pages each year. During the stagnation of the redesign phase, some FOP users turned to commercial implementations like RenderX or AntennaHouse. After 2005 I saw many switch back again after the major improvements because some of the commercial implementations couldn’t offer much more but had a higher TCO depending on the use case or because they offered unsatisfactory support and couldn’t influence the development direction enough. Apache FOP might face some difficult time ahead since the layout engine (the core) didn’t see considerable development lately. Some features like table markers, flow maps and auto-table layout would do FOP some good but it won’t be easy to implement.

Between 2000 and 2003, Apache FOP was part of my job and quickly became a hobby, too. I’ve developed Barcode4J (an open source barcode generator) during that time which plugs nicely into FOP. From 2004 to 2005, FOP was just a hobby as I worked part-time for a small company maintaining a model-driven application framework. In 2005 I went freelance offering commercial support, consulting and development services around Apache FOP. At times, FOP created up to 90% of my income. I did not get rich, of course, but the fun counts, too. It wasn’t always fun. Heated arguments over mostly non-features nibbled at my motivation which triggered me to reduce my involvement in FOP a bit. This year was dominated by two interesting projects that involved producing full-color PDFs, both Web-to-Print. One is Swiss Post’s DirectFactory, a web plattform where you can design and send postcards (or even chocolate wrappers now). The other was for a company that produces photo books, calendars and other gifts from within the browser. That finally got me back to a user role a bit. Before that I basically just hacked FOP without really using it myself. It’s interesting how the perspective shifts again when switching back to the user side. This is particularly important to me now that the EUR, GBP and USD are very weak against the CHF. My commercial support business gets increasingly more difficult because most of my clients are located outside Switzerland. And that means I have to shift my main focus to domestic clients but without leaving my past clients in a void.

I’d like to note something interesting in that context: In all my freelancer time since 2005, I’ve never picked up the phone to look around for projects. I was lucky that they always found me, often even at the right times. A large part of it, I’m sure, is my presence on the Apache FOP Users Mailing List. By answering questions, people recognize a recurring name at some point. When some users run into a problem they can’t solve easily, they often turn to me for a higher service level than is possible on the users mailing list. That said, I believe there is room for a good developer to get challenging tasks as part of a commercial support service for Apache FOP, especially if he’s not afraid of the complicated topic of paper layout and he’s not located in Switzerland which is currently just too expensive due to the currency weaknesses. Such an additional resource would be good for FOP.

Last year, I’ve started to develop an output management server which uses Apache FOP as its main formatter. Although a minimal version is now live working nicely for the DirectFactory, it turned out to be too big an endeavour for a one-man show besides end-user projects and the FOP commercial support. So I’ll be investing in a smaller product first that hopefully will create a little multiplicator for me which commercial support services simply can’t provide. To wrap up this admittedly lengthy post, I need to say that Open Source is a very important topic for me. When done right, it is such an effective way to pool resources and to create high-quality software. Getting rich with it (not that I need to be) is difficult, so the right way is probably somewhere in between commercial and open source products. My wish is that more users of Open Source software think about contributing something back to the many products they use. There are various ways to do that. Too often, people treat OSS as freeware which it simply isn’t.

XSL Basic Training 27./28. September 2010 in Böblingen, Germany

May 27th, 2010

This is something mainly for german-speaking people who are interested
in learning about document production with XSLT and XSL-FO. I’ll be
giving a two-day training on the basics of XSLT and XSL-FO during the
27./28. September 2010. The workshop is hosted and organized by Compart
Deutschland GmbH in Böblingen, Germany. More information is available on
their website (in German):
http://www.compart.com/en/seminar-workshop/events/EX-W1030en-xml-xsl-xsl-fo

Two days are quite short for that amount of information so the workshop
is quite intensive, but the feedback from past workshops was very
positive.

BTW, I’m happy to give this training (available in German or English) at
a location of your choosing (preferably within Europe). Let me know if
you are interested.

OSGi Declarative Services: Configuring multiple instances of a component

April 22nd, 2010

Declarative Services are a nice way to create services in the OSGi environment, but there are some subtleties that are not always easy to get under control. Imagine you have a component that observes a directory and acts on the presence of new files (a “hotfolder”, much like the Apache Felix FileInstall bundle). You may have multiple such directories which you want to observe, which you want to configure. You could create a ManagedServiceFactory but there’s a simpler way with Declarative Services once you’ve figured out the subtleties.
Let’s first define a very simple service interface:

public interface Greeter {
    void sayHello();
}

Then let’s implement this interface:

public class GreeterImpl implements Greeter {

    private ComponentContext context;

    protected void activate(ComponentContext context) {
        this.context = context;
        System.out.println("Creating new greeter for " + getName()
                + ": " + context.getComponentInstance().toString());
    }

    protected void deactivate(ComponentContext context) {
        System.out.println("Deactivating greeter for " + getName()
                + ": " + context.getComponentInstance().toString());
        this.context = null;
    }

    public void sayHello() {
        System.out.println("Hello, I'm " + getName());
    }

    private String getName() {
        return (String)this.context.getProperties().get("name");
    }

}

Through the activate(ComponentContext) method, we’ll get the component’s configuration once an instance is activated.
Now, we need the component descriptor for our Greeter component (OSGI-INF/component.xml):

<?xml version="1.0" encoding="UTF-8"?>
<component name="demo.scr.componentfactory.greeter">
  <!-- No factory attribute here! -->
  <implementation class="demo.scr.componentfactory.impl.GreeterImpl"/>
  <service>
    <provide interface="demo.scr.componentfactory.Greeter"/>
  </service>
  <property name="service.description"
      value="A nice component that can say hello"/>
</component>

If you know a little bit about Declarative Services, you might at first expect a factory attribute on the component, since we’re going to create multiple instances, but it would really just wrong with the approach I’m showing here. The final missing clue to make this work with multiple configurations lies with the MetaType descriptor we need to build (OSGI-INF/metatype/metatype.xml):

<?xml version="1.0" encoding="UTF-8"?>
<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"
    localization="OSGI-INF/metatype/metatype">
  <metatype:OCD id="demo.scr.componentfactory.greeter"
      name="SCR Component Factory Demo">
    <metatype:AD id="name" type="String"
        name="%name.name" description="%name.desc"/>
  </metatype:OCD>
  <metatype:Designate pid="demo.scr.componentfactory.greeter"
      factoryPid="demo.scr.componentfactory.greeter">
    <metatype:Object ocdref="demo.scr.componentfactory.greeter"/>
  </metatype:Designate>
</metatype:MetaData>

Note especially the “Designate” Element which has both a “pid” and a “factoryPid” attribute. The important part is the “factoryPid” attribute which will enable the desired “factory” functionality.
If you want, a properties file with the translations (OSGI-INF/metatype/metatype.properties):

name.name=Name
name.desc=The name. D'oh!

Just for completeness and illustration, here’s the effective bundle manifest:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DemoScrComponentFactory
Bundle-SymbolicName: demo.scr.componentfactory
Bundle-Version: 1.0.0
Export-Package: demo.scr.componentfactory
Import-Package: org.osgi.framework,
 org.osgi.service.cm,
 org.osgi.service.component,
Service-Component: OSGI-INF/component.xml

If you deploy the resulting bundle in Felix, for example, you should see our new component in the dropdown list of factory configurations on the configuration page of Felix’s WebConsole.
Besides the UI in the WebConsole, you can also use Apache Felix FileInstall’s configuration feature. Just create a properties file (ex. “demo.scr.componentfactory.greeter-C3PO.cfg”) in the directory observed by FileInstall:

name=C3PO, human cyborg relations

Just use the component’s PID followed by a dash and a name of your choosing. You can create as many configuration files as you like. For each one, SCR will create a service for you.

Update, 2010-05-19:
There may be a little problem with the above. If there are no configurations in ConfigurationAdmin, one component instance will still always be activated which may have unwanted side-effects if your component depends on certain values in the configuration. If you experience that, you can switch to the version 1.1 of Declarative Services and use the configuration policy to control this. The following example will require at least one configuration in the ConfigurationAdmin before the component is activated:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
    name="demo.scr.componentfactory.greeter"
    configuration-policy="require">
[..]
</scr:component>

ATM hanging at startup

November 9th, 2009

Seen in Lucerne last Saturday (2009-11-07). It was still like this when I came by again 8 hours later in the evening. I don’t think any comment is necessary. ;-)

ATM running Windows 2000 hangs on startup

Thanks to Jürgen for pointing this out to me!

DocBook is fun!

June 4th, 2009

I’m currently writing a basic XSL training course which I’ll give the first time later this month. I decided to write the training materials using DocBook 5. Lots of XML examples, lots of SVG illustrations painted in Inkscape. I used the DocBook editing capability of my OxygenXML editor. Finally, I’ve customized the DocBook XSL stylesheets a bit, added syntax highlighting using XSLTHL and used Apache FOP (SVN Trunk) to create the PDF.

I must say: it was simply fun to work with this setup. DocBook is well documented. The documentation always had an option for all of my wishes. No wasted time, no crashes, no despair (I pity those who do this with MS Word). I can only recommend to do any larger documentation work like this.

Specifying Classpaths

December 4th, 2008

Java is great. Really. But there are sometimes subtleties that need to be kept in mind as I had to find out in the last few days once more. After looking in all the wrong places, that is. I’m talking about specifying a classpath. Multiple entries on the classpath are delimited by a separator but that separator is not always the same:

  • JVM Classpath on Windows (semicolon): “-cp my1.jar;my2.jar”
  • JVM Classpath on Unix (colon): “-cp my1.jar:my2.jar”
  • Class-Path entry in a JAR manifest (space): “Class-Path: my1.jar my2.jar”
  • OSGi’s Bundle-Classpath entry in a bundle manifest (comma): “Bundle-Classpath: .,META-INF/lib/my1.jar,META-INF/lib/my2.jar”

I’m sure someone will eventually come up with yet another separator for classpath entries.

IBM and Sun launch ODF Toolkit

November 5th, 2008

With pleasure I learned today that IBM and Sun together launched http://odftoolkit.org/. It is at least partly seeded with code from Sun’s OpenOffice (namely the ODF Toolkit project). Initial components include ODFDOM (a low-level ODF API) and an ODF validator. Another very pleasant surprise is the publication of the source code under the liberal Apache License V2.0. Congratulations to the people involved!

This will make especially ODFDOM interesting for Apache FOP.  One of the missing puzzle pieces in FOP surely is an ODF output plug-in to replace the RTF format in the long run. Somehow I’ve got the feeling that we won’t have to wait all too long for that… ;-)

So Mars is now called PDFXML

September 17th, 2008

Matthew Hardy announced a new prerelease of the PDFXML Plug-in für Adobe Acrobat 9. PDFXML used to be called Mars and is a XML-friendly representation of PDF (borrowing heavily on SVG). Now only the project itself is still called Mars. I wonder if this is an indicator that Adobe will put more energy into promoting this new format in the future. I’ve already blogged about it some time ago.