Build your own SIP trunk with Asterisk and mISDN

The mission: “save some bucks by using a free PBX using a cheap isdn card”. Don’t try! Buy something working in the first place. But if you have to, here is one example how it can be done. There are, for sure, many others!

The idea was to replace trixbox using an AVM Fritz!PCI card with something more up to date and not that buggy. FreePBX Distro kicked itself out because of the issues with mISDN. Elastix brought in mISDN support but still failed in configuring it. Since the setup was for only 3 users for now and the idea was to later buy something more professional (I really hope it comes to this point), I used Starface free. It has 4 users and 10 extensions for free. Yet the free version only allows using SIP providers. Also it was not possible to buy a Patton SmartNode 4120 at the moment, which I still hope to get somewhere in the future. So I needed to build our own SIP trunk since the provider used (M-NET) does not provide SIP trunks as a product.

Continue reading

Eclipse Draw2D Border Magic

While using Eclipse Draw2D I stumbled over some quite interesting behaviour on win32 using rectangles and scaling.

We have a scalable layer and added a rectangle. When the layer was actually scaling (so not 1.0) strange artifacts appeared on win32 platforms. Finally it turned out that it was a negative line size with the outline flag set to true. Which renders on Linux as if outline would be set to false. Yet interesting was that setting the lineSize to 0.0 (zero) while keeping the outline flag true causes a hairline to be drawn. So a line which is 1 pixel, independent of the scale factor.

Settings Screenshot
[code language=”Java”]
figure.setOutline ( false );
[code language=”Java”]
figure.setOutline ( true );

Which is the same as:
[code language=”Java”]
figure.setOutline ( true );
figure.setLineWidthFloat ( 1.0f );

[code language=”Java”]
figure.setOutline ( true );
figure.setLineWidthFloat ( 0.0f );

This is the actual hairline variant.

[code language=”Java”]
figure.setOutline ( true );
figure.setLineWidthFloat ( 2.0f );
[code language=”Java”]
figure.setOutline ( true );
figure.setLineWidthFloat ( -1.0f );

Note the small artefacts at on the sides. These are invisible if run under Linux.

The full code to create the canvas was:

[code language=”Java”]
ScalableLayeredPane pane = new ScalableLayeredPane();

Layer layer = new Layer();
layer.setLayoutManager(new StackLayout());

pane.add ( layer );

Figure figure = new Figure ();
figure.setLayoutManager(new XYLayout());

RectangleFigure r = new RectangleFigure();
figure.add(r, new Rectangle(10,10,20,20));
layer.add ( figure );


Setting the page size and orientation with ODFDOM for tables aka spreadsheets

Most tasks that seem to be quite easy tend to turn out as a desaster. Setting the page size and orientation with ODFDOM was such a thing. While styling with ODFDOM is powerfull and a horror at the same time. You actually never know where the attribute have to be placed or which attributes to use.

After I finished an export to “ods” (aka spreadsheet) it simply wanted to set the format to “A4 landscape”. Here is how to do that:

First create your spreadsheet and sheet ( you might already have done that):

[code language=”Java”]
OdfSpreadsheetDocument output = OdfSpreadsheetDocument.newSpreadsheetDocument ();
final OdfTable sheet = OdfTable.newTable ( output );

Now change the styles to “A4 landscape”:

First we need to get the “master page” named “Default”:
[code language=”Java”]
StyleMasterPageElement defaultPage = output.getOfficeMasterStyles ().getMasterPage ( "Default" );

The master page tells us the name of the page style:
[code language=”Java”]
String pageLayoutName = defaultPage.getStylePageLayoutNameAttribute ();

Which gives us the page layout object:
[code language=”Java”]
OdfStylePageLayout pageLayout = defaultPage.getAutomaticStyles ().getPageLayout ( pageLayoutName );

Finally we can set “A4 landscape”:
[code language=”Java”]
pageLayout.setProperty ( OdfPageLayoutProperties.PrintOrientation, "landscape" );
pageLayout.setProperty ( OdfPageLayoutProperties.PageHeight, "210.01mm" );
pageLayout.setProperty ( OdfPageLayoutProperties.PageWidth, "297mm" );
pageLayout.setProperty ( OdfPageLayoutProperties.NumFormat, "1" );

All four properties seem to be required. Also the width and height have to be rotatate according to “landscape”.

Extending OpenWRT

We recently switched from IPfire to OpenWRT in our office. Not only because we let OpenWRT run on an ALIX board (which also IPfire could do), but mostly due to the fact that if you want to extend the system you really can do it. Development of IPfire seems to be quite difficutly, not only technically.

On the other hand OpenWRT quickly provides help if you want to contribute. Also too the “noob” questions you will post in the beginning ;-)

My initial idea was to create a small plugin for OpenWRT which allows one to configure “pptpd” and VPN users using the web interface LUCI. While OpenWRTs configuration system (called UCI) handles the configuraton model in the background, LuCI brings this models to a Lua driven web user interface. UCI and LuCI play well together, you only need to know how it works together.

Continue reading

Working with ODFDOM

While working a little bit with ODFDOM to automatically generate some documentation I found some tasks rather difficult to accomplish due to the fact that they were hardly documented. There is a lot of ODF documentation, but how to use it with ODFDOM is another story.

So first a list of documentation I found:

Adding a new paragraph with a pre-defined style

To create a new paragraph with a style I used the following static function:
[code language=”Java”]
public static OdfTextParagraph newStyledParagraph ( final OdfTextDocument odt, final String style, final String content ) throws Exception
final OdfTextParagraph p;
if ( content != null ) {
p = odt.newParagraph ( content );
} else {
p = odt.newParagraph ();
p.setStyleName ( style );
return p;

Adding fields (like title and subtitle)

The following snippet will create a new paragraph

[code language=”Java”]
OdfTextParagraph p;
p = OdfHelper.newStyledParagraph ( odt, "Title", null );
p.newTextTitleElement ();

p = OdfHelper.newStyledParagraph ( odt, "Subtitle", null );
p.newTextSubjectElement ();

Creating a new parapgraph style

The next snippet creates a new a new style called “Source Text” dereived from “Text Boby”. The setFontFamily method is a helper to set all font properties at once.

[code language=”Java”]
protected void setFontFamily ( final OdfStyleBase style, final String value )
style.setProperty ( OdfTextProperties.FontFamily, value );
style.setProperty ( OdfTextProperties.FontFamilyAsian, value );
style.setProperty ( OdfTextProperties.FontFamilyComplex, value );

private void createStyles ( final OdfTextDocument odt )
final OdfOfficeStyles styles = odt.getOrCreateDocumentStyles ();

final OdfStyle style = styles.newStyle ( "Source Text", OdfStyleFamily.Paragraph );
style.setStyleParentStyleNameAttribute ( "Text Body" );
style.setProperty ( OdfParagraphProperties.Margin, "1cm" );
style.setProperty ( OdfParagraphProperties.BackgroundColor, "#DDDDDD" );
setFontFamily ( style, "Courier New" );

Copy content from one to another ODF File

While most of the document I made was created some static part a the beginning was needed. Instead of creating it manually I created a new ODT File in LibreOffice and imported the content to the generated document.

The following snipped does that:
[code language=”Java”]
private void createStaticContent ( final OdfTextDocument odt, final File file ) throws Exception
// check if file is readable and is a file
if ( !file.canRead () || !file.isFile () )

// Load the document to import

final OdfTextDocument staticOdt = OdfTextDocument.loadDocument ( file );

// Create a new text section which will receive the content. This is optional.
// You could also load the content directly on the root of the document

final TextSectionElement section = new TextSectionElement ( odt.getContentDom () );
odt.getContentRoot ().appendChild ( section );
section.setTextProtectedAttribute ( true );
section.setTextNameAttribute ( "Static Content" ); //$NON-NLS-1$

// iterate over all nodes
final NodeList childNodes = staticOdt.getContentRoot ().getChildNodes ();
for ( int i = 0; i < childNodes.getLength (); i++ )
// clone node from source
final Node newNode = childNodes.item ( i ).cloneNode ( true );
// import to target DOM
final Node adoptedNode = odt.getContentDom ().adoptNode ( newNode );
// append to section
section.appendChild ( adoptedNode );
Since only content is imported the styles of the target document will be used for the content that was imported.

Bye bye Lotus Notes

We used it for some time. It was nice. But now our ways seem to …

well, let me just say: PNG, 64bit Linux, Windows 7, …

I was migrating E-Mails from Notes to Courier IMAP using “imapsync” when I stumbled over two strange problems…

Continue reading

JPA, EJB and Spring

Today I stumbled over a rather interesting issue in combination with JBoss, Hibernate, Spring, JPA and EJB.

First of all, we have mixed environment of EJB3 and Spring 3 using JPA2. All in JBoss 6 AS, with default Hibernate 3.6 as JPA provider. Now for a long time everything works fine until we re-organize the dependencies of our modules. Starting with that we got some strange JPA behavior like “class is not an entity” and some rather weird getter issues.

Altogether it looked like some classloader issue. But it took some time to find that one.

In the beginning there was a JPA persistence unit called “someModel”. The problem with spring was, that it needs to be imported using the “jee:jndi-lookup” tag, which requires a JNDI name. That one was provided by JBoss itself using the “” property in the “persistence.xml” file. This triggers JBoss/Hibernate to bind the persistence unit with that specified name. Of course the name was “persistence/someModel”.

Now everything grew, EJB was added in order to gain modularity. And now that the dependencies and the start order was changed, the same persistence unit was used multiple times in multiple EJBs beside the spring application. While EJB seems not to have any problems finding its persistence unit, spring needs a bit more information and requires the already discusses “jee:jndi-lookup” tag in order to find its persistence unit.

As it turned out, the multiple persistence units all registered with the same name, leaving spring with the first (or last) registration, but not necessarily the correct registration. So spring accesses “some” persistence unit with that name and possible used the wrong classloader.

The solution was quite and and lot cleaner than using the “” property. But, less intuitive I have to say.

In the “web.xml” of the servlet that starts the application context a reference has to be added to the persistence unit:

[sourcecode language=”xml”]

This will register the local (in the EAR file hosting the WAR) peristence unit “someModel” in the local JNDI space as “persistence/someModel” and you are done. Spring will can still import it as “persistence/someModel”.

Struggling with Acceleo 3.0 after Eclipse 3.7 upgrade

While the upgrade from Eclipse 3.6.2 to 3.7 went without nearly any trouble the upgrade of the Acceleo plugins to the versions provided with Eclipse Indigo was “a little bit more” problematic.

Starting the generator after the upgrade simply brought up:

Exception in thread "Main Thread" org.eclipse.acceleo.engine.AcceleoEvaluationException: The type of the first parameter of the main template named 'myTemplate' is a proxy.
    at org.eclipse.acceleo.engine.service.AcceleoService.doGenerate(
    at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.generate(
    at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.doGenerate(

The main template did not accept the model anymore. Although everything was registered and working with the previous version.

Googling a bit I found out that Acceleo provides a different serialization model which stores models in binary form instead of XMI. Since all my models I flipped the switch in the project settings:

Acceleo Project Settings

Which worked at first until I stumbled over the next problem a few hours later:

org.eclipse.acceleo.engine.AcceleoEvaluationException: Invalid loop iteration at line 18 in Module myModule for block for (myObject.null). Last recorded value of self was com.thfour.config.model.model.impl.MyObjectImpl@81b69bf (....).
    at subModule.subModule(null)(subModule.mtl:18)
    at subModule.subModule(null)(subModule.mtl:6)
    at subModule.subModule(null)(subModule.mtl:4)
    at module.module(MyObject)(module.mtl:0)
    at module.module(MyObject)(module.mtl:7)

After some debugging it seemed as if the main module could not pass a model object to a template that is located in another bundle. We have structured our model generator to have a common part and a project specific bundle. At first it looked like as it this stopped working by an unknown reason.

After some testing, flipping switches, debugging, restructuring I found out that the solution was rather simple. The same switch (Binary, XMI) has to be set to the common generator module as well. All modules must agree to a model format (either binary or XMI).

While I can understand this for the generator that is launched, I cannot understand this for submodules that provide common generating templates and should not even care about the serialization form. But it is as it is ;-)

Fancy tooltips in Eclipse

Tooltips are quick way to add information to a widget that received the users attention. While one can argue about the pros and cons of tooltips this post focuses on the style of tooltips once you decided to use them.

Continue reading