Adam Bien's Weblog

Thursday Aug 21, 2014

How To Deal With J2EE and Design Patterns

Patterns are clearly defined as:

"In software engineering, a design pattern is a general reusable solution to a commonly occurring problem within a given context in software design."
[http://en.wikipedia.org/wiki/Software_design_pattern].

If you encounter a design challenge, you are supposed to search in a catalog for the description, compare the Motivation (Forces) or Applicability. If they match, you can apply the ideas from the pattern to solve your problem. Patterns are not a genius solution to a problem, rather than a standardized compromise. Usually you are going to implement flavors of the design patterns without even knowing it.

In Java Enterprise community patterns seem to have their own live. They are going to be applied regardless their problem definition or context. The most misused pattern in the Java Enterprise community is the DTO. DTO was clearly defined as a solution for a distribution problem. DTO was meant to be a coarse-grained data container which efficiently transports data between processes (tiers). In J2EE DTO was absolutely necessary, CMP Entity Beans were not serializable. Martin Fowler also defines defines DTO as:

"An object that carries data between processes in order to reduce the number of method calls."
According to the definitions DTOs were never meant to carry data within a JVM...

Even more suspicious is the popularity of the DAO pattern. The solution statement starts as:

"The DAO implements the access mechanism required to work with the data source. The data source could be a persistent store like an RDBMS, an external service like a B2B exchange, a repository like an LDAP database, or a business service accessed via CORBA Internet Inter-ORB Protocol (IIOP) or low-level sockets."

DAO was always meant as a procedural encapsulation of inconvenient or not standardized data sources. An object oriented flavor, the Domain Store pattern uses DAO to access JDBC and provides an object oriented access to the store. Interestingly the Domain Store looks like a slightly modified version of the ...JPA Entity Manager.

Some projects are wrapping Entity Manager with an empty delegate and call it "DAO". Such an approach is actually the opposite of the origin intention...

Java EE 5 killed the majority of the J2EE Patterns. Their "Problem" and "Forces" descriptions do not apply any more. Java EE 6 and 7 killed the remaining patterns, only the Application Service is still useful.

If you take the pattern definitions seriously and look at some "enterprise" projects you are not going to understand the design. Patterns are going to be applied without having a problem and are considered as future "insurance": "...in case JPA disappears, I only have to change the implementation of the DAO..."

How to deal with patterns? Apply them if you encounter a problem. Java EE design is "bottom-up" rather than "top-down", as it was the case in the old J2EE world.

[See also an in-depth discussion in the "Real World Java EE Night Hacks--Dissecting the Business Tier" book, page 259 in, chapter "Data Access Object"]

We spend some time to eliminate J2EE and GoF patterns one by one with Java EE 7 and Java 8 during the Java EE Architectures "airhacks" workshops at MUC airport.


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Wednesday Aug 20, 2014

igniter.fx 1.9.2 released--The Java 8 Edition

A new version of igniter.fx -- the maven "wizard" which creates a sample Java FX MVP application is released.

The 1.9.2 edition demonstrates afterburner's 1.6.0 capabilities like asynchronous FXML loading and view-dependent object injection.


@FXML
Pane lightsBox;
//...
LightView view = new LightView((f) -> red);
view.getViewAsync(lightsBox.getChildren()::add);


A passed constructor parameter (an int in the example below) can be conveniently injected into the presenter. Each presenter instance receives its own value:

public class LightPresenter{

    @FXML
    Circle light;

    @Inject
    int red;


See the full code: DashboardPresenter.java

igniter.fx is open source: https://github.com/AdamBien/igniter.fx

To create a an igniter.fx 1.9.2 maven project execute the following command from the CLI:


mvn archetype:generate -Dfilter=com.airhacks:igniter

You can also clone the sample source code directly from: https://github.com/AdamBien/followme.fx.

followme screenshot

See you at Java EE Workshops at MUC Airport or on demand and in a location very near you: airhacks.io!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Friday Aug 15, 2014

Special Business Logic Treatment Considered Harmful in Java EE

Prior Java EE 5 (2006, see the whole history in: http://realworldpatterns.com) your application code had to realize J2EE interfaces and was forced to implement several infrastructural methods. The amount of plumbing was significant and the business logic was hard to understand.

With the introduction of annotations in JDK 1.5 and the introduction of Dependency Injection paired with Convention over Configuration in Java EE 5 your application code is only dependent on annotations which are comparable to the Marker Interface pattern. Java EE 6 went even further, so you can implement large portions of business logic without being even dependent on any Java EE annotations.

Also the main goal of the outdated http://www.corej2eepatterns.com was the separation of "clean" business logic and the "polluted" J2EE infrastructure. Now the majority of the J2EE patterns solves no more existing problems, mostly problems being already solved in the recent Java EE releases.

With Java EE 5+ any attempt to separate your business logic from Java EE infrastructure will result in empty delegates, parallel and identical object hierarchies, increased complexity and harder maintainability.

Stop plumbing, focus on business logic and added value to your customers :-)

See you at Java EE Workshops at MUC Airport or on demand and in a location very near you: airhacks.io!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Wednesday Aug 13, 2014

Every Ping Needs A Floyd - v0.0.1 Released

ping is a Java EE 7 application which provides app server health-checks exposed as REST services.

floyd is the corresponding Java FX client (a single, self-contained jar) which searches for ping services in the network and visualizes the health (CPU, Memory, Ping Time) conveniently.

ping screenshot

The first version is available for download.

After the download execute: java -jar floyd-app.jar with Java 8.

See you at Java EE Workshops at MUC Airport or on demand and in a location very near you: airhacks.io!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Friday Aug 08, 2014

afterburner.fx 1.6.0 released

The 1.6.0 release of the afterburner.fx, a 2.5 class MVP framework for JavaFX is available.

The main feature of this release is asynchronous loading of views and presenters:

  1. Support for lazy initialization and asynchronous view construction
  2. "per-instance" injection of parameters into a view

floyd was built with the new 1.6.0 features. floyd is the front end for ping.

See you at Java EE Workshops at MUC Airport particularly at JavaEE UI day!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Wednesday Aug 06, 2014

The Return Of JSPs In HTML 5?

In it's early days JSPs were misused for the realization of business logic. Any complex code enclosed in scriplets is hard to write, test and so maintain.

However: JSPs are perfectly suitable for delivery of HTML 5 documents:

  1. You have full control over HTML markup. There is no hidden code generation in place.
  2. No magic: JSPs become Servlets. Usually you can even look at the generated code in case something feels strange.
  3. After the initial invocation, JSPs are as performant as Servlets.
  4. JSPs just serve strings, so no components have to be hold in memory -- the memory requirements are low.
  5. IDE support, debugging and performance analytics for JSPs are superb.
  6. JSPs even support lambdas in EL.
  7. JSPs can be perfectly used in the "logic free" mode, just as a powerful templating language.
  8. You can introduce custom tags for the encapsulation of recurring functionality.
  9. CDI managed beans and so whole Java EE components can be easily exposed to JSPs

A simple POJO:


public class Greeting {

    private String title;
    private String content;

    public Greeting(String title, String content) {
        this.title = title;
        this.content = content;
    }
    public String getTitle() {
        return title;
    }
    public String getContent() {
        return content;
    }
}

Could be easily exposed by a CDI presenter / backing bean:

@Model
public class Index {

    public List<Greeting> getGreetings() {
        List<Greeting> greetings = new ArrayList<>();
        greetings.add(new Greeting("short", "hi"));
        greetings.add(new Greeting("casual", "hello"));
        greetings.add(new Greeting("formal", "welcome"));
        return greetings;
    }
}

...and conveniently rendered using a JSP:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<body>
    <h1>Hello JSP</h1>
    <ul>
        <c:forEach var="message" items="${index.greetings}">
    	    <li><c:out value="${message.title}"/> - <c:out value="${message.content}"/></li>
        </c:forEach>
    </ul>
</body>

See you at Java EE Workshops at MUC Airport or on demand and in a location very near you: airhacks.io!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Tuesday Aug 05, 2014

5th Airhacks Answers For Questions

Thanks for watching live (85 attendees), all the interactions, particularly from the IRC #airacks channel and twitter.

Any questions left? Then join the conversation at each first Monday of the month at 6 P.M. live. No registration or any other commitment required. All dates for 2014 are scheduled: http://www.ustream.tv/channel/adambien.

See also other screencasts at: http://tv.adam-bien.com or subscribe to http://www.youtube.com/user/bienadam.

See you at Java EE Workshops at MUC Airport or on demand and in a location very near you: airhacks.io!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Sunday Aug 03, 2014

RichFaces' 5 Future -- Stability over Innovation

RedHat will continue to support the RichFaces runtime, but stop investing in RichFaces 5:

"...With these trends in mind, we’ve decided that moving forward we will pursue a path of stability with our JSF approach, rather than a path of innovation. We will continue to track the JSF spec with our RichFaces components and address compatibility issues with new browsers. Applications currently running with RichFaces 4 can continue to do so with an assurance of stability. With this goal in mind we are focusing on delivering a RichFaces 4.5 release, rather than the previously planned RichFaces 5..." [RichFaces will pursue a path of stability over innovation, Brian Leathem, RichFaces Project Lead]

Any questions left? See you at: Java EE Web Frameworks or Java EE and HTML 5 :-)


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Friday Aug 01, 2014

Microservices, State, REST, Learning Java and Questions Overflow: 5th Airhacks Q & A

  1. Gateway pattern, stateful vs. stateless behavior and the “Extended” EntityManager (multiple questions)
  2. Boundaries intercommunication restrictions Java EE (two boundaries should not communicate with each other) Boundaries intercommunication restrictions Java EE Email question from: Sergio David
  3. How to learn Java SE/EE (email from *seti*)
  4. .NET vs. Java EE – after 5 years JAVA EE OR .NET - AN ALMOST UNBIASED OPINION Question from: Süleyman Vurucu
  5. What is the state of Java EE 7 (Adam S.)
  6. Cancel vs. Cancellation, and when “GET” and “POST” are not enough Frank
  7. @AdamBien please suggest some good resource for Java EE inside view like how container create stateless beans and so on #airhacks @ mesurajchhetry
  8. Layers, Tiers and interactions. Blog post dicusssion
  9. What are micro services? Carsten Czyszewski
  10. Is it possible to Implement microservices with JEE? Carsten Czyszewski
  11. Are there any improvements on implementing the good old design patterns with
    JEE 7 / Java 8? Carsten Czyszewski
  12. The difference between @Path and @Stateless + @Path Sam
  13. How do I run integration tests? mvn test does not trigger them, nor the mvn
    integration-test zemiak

The questions above are going to be answered during the next "Airhacks Q & A" http://airhacks.io live. You can subscribe to the channel and / or for the next event: http://www.ustream.tv/channel/adambien (both is optional, no registration required to watch this event live).

If you miss a question, write a comment on this post, tweet your question with the hashtag "#airhacks" or mention me https://twitter.com/AdamBien.

The best of all: you can ask the questions live, during the show using the chat: http://www.ustream.tv/channel/adambien, twitter (hashtag "#airhacks") or (the best option): using channel ##airhacks on http://freenode.net.

See you at Java EE Workshops at MUC Airport or on demand and in a location very near you: airhacks.io!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

Tuesday Jul 29, 2014

WLS 12c (12.1.3) and Java EE 7, Some Smoke

WLS 12c supports some Java EE 7 API like: JSON Processing (JSR 353), JAX-RS 2.0, JPA 2.1 http://docs.oracle.com/middleware/1213/wls/NOTES/index.html. Now it is time for a Smoke Test:

  1. Download size is reasonable: 198,7 MB for a generic ZIP. However: the download requires a login to OTN. This is an unnecessary barrier for developers.
  2. Installation is easy: setting a MW_HOME variable pointing to the extraction folder and executing the configure.sh
  3. NetBeans 8 integration worked out-of-the-box. Application was directly deployed from NetBeans with Maven 3. WLS is nicely integrated with NetBeans: you can start, stop and deploy your application directly from NetBeans. Also a useful feature: WLS and GlassFish are using different ports--you can run both servers at the same time.
  4. wls12c was installed on Java 8 (1.8.0-b132 / mac) without any problems
  5. Java EE 6 tests were passed

Interestingly: a basic JAX-RS service with JsonObject works perfectly on GlassFish v4, but fails on WLS 12.1.3:


@Stateless
@Path("alert")
public class AlertResource {

    @Inject
    FireState fireState;

    @GET
    public JsonObject get() {
        return Json.createObjectBuilder().
				add("Smoke?:", fireState.isSmoke()).
				build();
    }
}

<Error> <com.sun.jersey.spi.container.ContainerResponse> <BEA-000000> <Mapped exception to response: 500 (Internal Server Error) javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class org.glassfish.json.JsonObjectBuilderImpl$JsonObjectImpl, and Java type interface javax.json.JsonObject, and MIME media type application/octet-stream was not found.

Seems like the "Accept" header is ignored. The request was initiated by: curl -H "Accept: application/json" http://localhost:7001/server-smoke/resources/alert and browser link.

See you at Java EE Workshops at MUC Airport or on demand and in a location very near you: airhacks.io!


Special Events: Java 8 with Java EE 7: "More Power with Less Code", 13th October, 2014 and Java EE 7: "Testing and Code Quality", 14th October, 2014

A book about rethinking Java EE Patterns

realworldpatterns.com
...the last 150 posts
...the last 10 comments
Links
License