Category Archives: java

16 Jun

ThoughtWorks on JSF

On their technology radar, ThoughtWorks describes JSF as a framework with which many people have problems. Moreover, they actually recommend to avoid this technology.

Although I cannot completely agree with ThoughtWorks, their summary is true to some extend. The JSF EG really must address this, or else JSF will cease to exist.

07 Jun

JDK 6 vs JDK 7 benchmark on Mac OS X 10.9

I recently switched my Maven JDK on my Mac from version 6 to 7 for a project at university. Later, when I built a fairly big Java 6 project with Maven for work, I noticed that it took considerably longer than in the last days. That is why I performed a little benchmark on this big project, and the results are striking.

Maven Build using JDK 6
Java version: 1.6.0_65, vendor: Apple Inc.
Total time: 1:25.398s
Final Memory: 66M/123M

Maven Build using JDK 7
Java version: 1.7.0_45, vendor: Oracle Corporation
Total time: 2:59.364s
Final Memory: 198M/673M

The build took more than double the time when using JDK 7, compared to using JDK 6. In addition, it consumed much more memory. Needless to say, I switched back to JDK 6 for building Java 6 projects on my Mac.

06 Jun

Bachelor thesis finalized at last: introducing Clean REST URLs

I am really very, very happy to announce that my bachelor thesis about the relative-resource-handler is now finally completed. In the end, I must admit that it took me quite a while to get the thesis to an official end, however, I am now even more excited about it.

Here is the final version of my thesis: Evaluation of State-of-the-Art resource handling in JavaServer Faces based web applications and development of an enhanced resource handler for JSF 2.

The thesis describes general problems in resource management of JSF based web applications, it presents common solutions and frameworks for resource handling (like Weblets), and finally, it introduces the relative-resource-handler. In addition, the thesis introduces the term “Clean REST URLs“, describing URLs, which are purely structural, which do not contain a query string, which instead contain only the path of the resource, and which are used to identify a resource the REST way. Clean REST URLs are used by the relative-resource-handler to deal with many problems that arise in the context of resource handling. More details about it can be found in the thesis PDF.

Some personal notes: I first started to work on my thesis in November, 2011, as announced in this blog post. After an initial burst of enthusiasm, I soon reduced my efforts, because of various other commitments (mostly my job at IRIAN, and other courses at university). Eventually, I continued work on the thesis in the fall of 2013, and now, after many hours of work, and many discussions with my scientific advisors (mostly Marcus Büttner), the thesis finally got accepted and graded (receiving the best possible grade, yay!). I can now officially end my bachelor studies at Vienna University of Technology, and enroll in the master programme. By the end of June, 2012, I was actually finished with my bachelor studies, however, I needed to complete my bachelor thesis to formally switch to the master programme. I therefore took the courses needed for my master programme in the context of yet another bachelor programme, which, fortunately, is possible at the Vienna University of Technology. This way I was able to complete most of my master courses, without being formally enrolled in the masters programme. Actually, as of today I am already very close to finishing my master studies, I have almost finished all required courses. I still need to write my master thesis though, which will most likely take another year.

04 Apr

Sequence Streams for Java 8

Since Java 8 was introduced last week, I started playing around with the new features it provides, e.g. lambda expressions, streams, …

After taking a closer look at the streaming API, I noticed that there was no out-of-the-box support for generating number sequences. Thus, I created this little project on GitHub: https://github.com/jakobk/sequence-streams.

Using the class Sequence, you can improve classic for-loops by making use of the new streaming API of Java 8. Consider the following example:

List<Person> persons = new ArrayList<Person>(100);
for (int i = 0; i < 100; i++) {
    persons.add(new Person(i));
}
// use persons ...

The same can be accomplished using Sequence in combination with the new streaming API:

List<Person> persons = Sequence.stream(0, 100)
    .mapToObj(Person::new).collect(Collectors.toList());
// use persons ...

The class Sequence provides various methods for generating all kinds of integer sequence streams, e.g. sequential or parallel streams, using different step sizes, counting up or counting down, etc.

After some further research, I found out that Tomasz Nurkiewicz created something similar to my Sequence class, however, much more powerful. His project LazySeq is also hosted on GitHub: https://github.com/nurkiewicz/LazySeq. Using LazySeq you can easily create various number sequences, including infinite ones. This is very similar to what already exists in clojure: lazy-seq.

10 Mrz

Generate DDL script of JPA persistence unit in Maven using hbm2ddl

Recently, I was facing the task of generating the DDL script of a JPA domain model in a Maven build. Of course, there is Hibernate’s hbm2ddl to actually perform the DDL generation, however, I did not know any Maven plugin capable of invoking hbm2ddl. After some research, I found out that this is achievable via an Ant task (i.e. use the Ant plugin for Maven), or via the hibernate3-maven-plugin. I decided to go with the hibernate3-maven-plugin, although all it does is to create a respective Ant task and invoke Ant on this task. Here is my Maven configuration for generating the DDL of my persistence unit during the Maven build:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>3.0</version>
    <executions>
        <execution>
            <id>generate-ddl</id>
            <goals>
                <goal>hbm2ddl</goal>
            </goals>
            <phase>process-classes</phase>
        </execution>
    </executions>
    <configuration>
        <hibernatetool>
            <jpaconfiguration persistenceunit="my-persistence-unit"/>
            <classpath>
                <path location="${project.build.directory}/classes" />
            </classpath>
            <hbm2ddl
                    export="false"
                    update="false"
                    drop="false"
                    create="true"
                    outputfilename="my-persistence-unit.ddl"
                    delimiter=";"
                    format="true"
                    haltonerror="true" />
        </hibernatetool>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
    </dependencies>
</plugin>

This configuration invokes hbm2ddl with the correct classpath and parameters during Maven’s process-classes phase, and creates the file target/sql/hibernate3/my-persistence-unit.ddl containing all DDL scripts of the configured JPA persistence unit.

17 Mai

“CDI für Rich Clients” in Eclipse Magazin

I am very happy to announce that the current issue (4.2012) of the german Eclipse Magazin (http://eclipse-magazin.de) includes my article “CDI für Richt Clients”, which is about the integration of Apache OpenWebBeans into Eclipse RCP.

After publishing my blog entry Apache OpenWebBeans meets Eclipse RCP, I was contacted by Claudia Fröhling asking if I wanted to write about this topic for the Eclipse Magazin. I was very glad to get this offer and, of course, agreed to write the article. Authoring such an article was a quite new experience for me, and I really enjoyed it. Hopefully it will not be the last one.

You can obtain a copy of the current Eclipse Magazin here or you can download the iPad app of the magazine.

09 Mrz

Apache OpenWebBeans meets Eclipse RCP

Last year I had to do a project at university using Eclipse RCP. Frankly, the Eclipse framework kinda sucked. Thus I tried to pimp Eclipse RCP a little bit, which means I wanted to use OWB and CODI.

After some time I figured out how to combine OWB and Eclipse RCP thanks to the excellent plugin system of OWB. Now I finally found some time to put the relevant classes online. You can find the project at apache-extras: http://code.google.com/a/apache-extras.org/p/openwebbeans-eclipse-rcp/

Please note: Although this is a maven project, I was not able to really build it with maven, b/c I couldn’t find a way to get all the relevant eclipse jars into a maven repo. If you want to use it, the best way is to copy the source files directly into your Eclipse RCP project.

If anyone is interested in getting this stuff running in his/her Eclipse RCP project, just ping me and I can help you with the pitfalls.

22 Nov

JSF value expression injection vulnerability

A few days ago this issue was reported to Mojarra: http://java.net/jira/browse/JAVASERVERFACES-2247.

It basically states that it is possible in JSF 2 to perform ValueExpression injection when includeViewParams is set to true on a navigation case.

To illustrate this in a better way, I created an example project at apache-extras, which shows the vulnerability: http://code.google.com/a/apache-extras.org/p/jsf-includeviewparams-security-hole-example/

Use the following steps to run the example:

  1. svn checkout http://svn.codespot.com/a/apache-extras.org/jsf-includeviewparams-security-hole-example/trunk/
  2. mvn clean jetty:run-exploded -PjettyConfig
  3. go to http://localhost:8080/include-view-params-security and follow the instructions

This vulnerability exists, because JSF treats the value of a view parameter as a ValueExpression when performing a navigation case with includeViewParams=true. For further details, see the issues at Mojarra and MyFaces: http://java.net/jira/browse/JAVASERVERFACES-2247 and https://issues.apache.org/jira/browse/MYFACES-3405

Until this is fixed you should avoid using includeViewParams=true!

08 Nov

Bachelor thesis about relative resource handler

I am very happy to announce that I will write my bachelor thesis at the research group for industrial software (INSO) at Vienna University of Technology. The thesis will be about my work on the relative resource handler for JSF 2 [1].

Together with Marcus Büttner and Mark Struberg I will adapt the relative resource handler for the administration software of the Vienna University of Technology, TISS [2]. For this task the relative resource handler will include some new features apart from supporting relative paths between resources, like e.g. supporting external resource locations. Check out the issue tracker for all enhancements [3]. Also, we already created a wiki page [4] for a list of all requirements.

Stay tuned!

[1] http://code.google.com/a/apache-extras.org/p/relative-resource-handler/
[2] https://tiss.tuwien.ac.at/
[3] http://code.google.com/a/apache-extras.org/p/relative-resource-handler/issues/list
[4] http://code.google.com/a/apache-extras.org/p/relative-resource-handler/wiki/Requirements