11 Dezember 2014

Which parts of Java EE belong to the application server?

Yesterday I was at the Developer Day of Swiss Railways.

Florian Seidl talked about future enterprise software architecture where he doubt that the application still plays a central role in Java EE.

A lot of people argue that it is a pain to relay on a out dated full blown Java EE application server and therefore use a Spring/Tomcat stack or simply use Spring on top of the application server.

It seems that there is a problem in how Java EE is defined. In my opinion it would make sense to divide all the Java EE specs in two parts.

One part should contain all the specs that are directly related to the application server and on the other side there should be the specs where the application code is built on top.

App server related topics are web containter, threading, JTA, JCA, JAAS, JMS etc.
Application related are i.e. JPA, CDI, EJB, JSF.

The idea behind the separation is that one could update the application related implementations without changing the application server version.

For example I don't see any reason for not using JPA 2.1 in a Java EE 5 application server.

Sure these lists are just a first guess and incomplete but I would be interested what you think.

06 Dezember 2014

Contract First Web Service with NetBeans

From time to time I have to implement some SOAP based web services. Usually these web services are used for application integration so the contract first approach is used where one creates the WSDL  document first.

To create the server stub from the WSDL document I found out that using Maven in combination with NetBeans is the most straight forward approach.

Just choose "New File" from the menu:

After clicking on Next you need to enter the name of the service to create and provide the WSDL document:

Now just hit finish and have a look at what the wizard has generated.

First the web service server stub:

package ch.simas.demo.ws;

import javax.ejb.Stateless;
import javax.jws.WebService;

@WebService(serviceName = "CalculatorService", portName = "ICalculator", endpointInterface = "org.example.ICalculator", targetNamespace = "http://Example.org", wsdlLocation = "META-INF/wsdl/calculator.wsdl")
public class CalculatorService {

    public java.lang.Integer add(java.lang.Integer a, java.lang.Integer b) {
        //TODO implement this method
        throw new UnsupportedOperationException("Not implemented yet.");

    public java.lang.Integer subtract(java.lang.Integer a, java.lang.Integer b) {
        //TODO implement this method
        throw new UnsupportedOperationException("Not implemented yet.");

That's not very impressive but let's have a look at the pom.xml

  <configuration>                          <sourceDestDir>${project.build.directory}/generated-sources/jaxws-wsimport</sourceDestDir>

As you can see all the necessary configuration for the jaxws-maven-plugin is done!

In my opinion NetBeans has far the best integration of Maven and you don't have to configure both your IDE and Maven because NetBeans relays on the configuration in the pom.xml.

28 Juli 2014

Include XML Schema Reference in XML to get IDE Code Completion

One thing that I find very often is the missing XML schema reference in XML files.
The advantage of including the reference is code completion in your IDE because with the xml schema the IDE knows about the structure of the XML document.

<?xml version="1.0" encoding="UTF-8"?>
    xsi:schemaLocation='http://xmlns.jcp.org/xml/ns/javaee http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/jobXML_1_0.xsd'>

    <batch:step id="step1">
            <batch:reader ref="Reader" />
            <batch:processor ref="Processor" />
            <batch:writer ref="Writer" />

An even worse pratice is using XML without a schema. But more about that in another post...

24 Juli 2014

Another reason for using NetBeans: JPQL code completion

Beside the superb support of Maven and JavaScript NetBeans has another very useful feature for developers using JPA. 
JPQL code completion inside a String when creating JPA queries:

Hint for Eclipse/JBoss Tools users: This works not only in @NameQuery!

14 Juli 2014

GlassFish 4 REST Resource and Status Code 500

If you get a error 500 without any additional information. when developing a REST service you probably have a class as parameter or return value that has no default constructor!

04 Juli 2014

Git behind Proxy

I had problems using Git behind a proxy. The solution took me some time so here is how I solved the problem:

First I had to set HTTP_PROXY and HTTPS_PROXY.

Then I encountered a problem with the SSL certificate. So I  had to set GIT_SSL_NO_VERIFY=1

That's all.

15 Mai 2014

Application Server Advantage #1: JBoss AS 7 and RHQ

Can you do that without an application server?

15 April 2014

JTAF - Track and Field ready on OpenShift

JTAF a track and field event management solution is ready as SaaS (Software-as-a-Service) in the OpenShift cloud: http://jtaf-simas.rhcloud.com/jtaf/

JTAF is open source and available on GitHub: https://github.com/simasch/jtaf

It uses Java EE 6 with REST services in the back end. The front end is entirely developed using JavaScript and HTML5. JTAF does yet not use any JavaScript frameworks to keep it as lean as possible.

31 März 2014

Toughts about Application Configuration

Some thoughts about application configuration (in German):


Migrating from GlassFish to ?

There is an interesting report form Markus Eisele, Simon Maple, Hildeberto
Mendonca, Oleg Shelajev and Oliver White available on RebelLabs about Migrating from GlassFish to JBoss or TomEE.

Check it out: http://zeroturnaround.com/rebellabs/abandon-fish-migrating-from-glassfish-to-jboss-or-tomee/#!/

10 März 2014

Use JNDI to Configure your Java EE App

There are a lot of people talking about Java EE configuration these days. But often they forget about JNDI (Java Naming and Directory Interface).

Configuration using JNDI has the advantage that you can use dependency injection. i.e.

@Resource(mappedName = "java:global/mystring")
private String mystring;

The configuration for example in JBosss EAP or Wildfly is pretty simple made in the standalone.xml (or domain.xml) file:

<subsystem xmlns="urn:jboss:domain:naming:1.4">
    <simple name="java:global/mystring" 
            value="My String" 

As you can see the type can be defined. If you need more complex objects simply use ObjectFactory http://docs.oracle.com/javase/7/docs/api/javax/naming/spi/ObjectFactory.html

Read more about JNDI in WildFly: https://docs.jboss.org/author/display/WFLY8/JNDI+Reference
and more about ObjectFactory: http://middlewaremagic.com/jboss/?p=1690

05 März 2014

When to Use a Library (or Framework)

Lukas Eder just posted a note about when to use a framework: http://blog.jooq.org/2014/03/05/when-to-use-a-framework/

I totally agree! And I think it is not only limited to big frameworks like JPA/Hibernate.
Often developers spend a lot of time evaluating a library that solves their problems. But sometimes it would be easier to write a few lines of code to solve the problem.

If you do it your self there are two advantages 1) you better understand the problem because you solved it on your own and 2) your solution is exactly what you need. There are no dependencies to a big framework or library that may have their own dependencies etc.

For sure my idea does not scale. If your problem is O/R-mapping it doesn't make sense to create your own Hibernate. But if you just need some small utilities - why not think about...

04 März 2014

Java EE Configuration

Currently I am working for a IT department as a middleware engineer. Defining processes and setup JBoss EAP.

Application configuration is a very important thing and I found an interesting post from Nicolas de Loof.
Check it out: http://blog.loof.fr/2013/10/configuration-management-jsr.html