MicroProfile + Java EE 8 = Thinner WARs

openliberty already supports Java EE 8 and MicroProfile APIs at the same time.

Payara 5 follows the same approach: one server runtime comes fully loaded with Java EE 8 and MicroProfile 1.3 support. Even Payara Server 4 ships with Java EE 7 and MicroProfile 1.3.

With this (brilliant) move, I'm able to use MicroProfile features on stock application servers without changing the runtime in production. Unfortunately, your pom.xml will grow by 100% from one dependency to two:


<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-api</artifactId>
    <version>8.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.eclipse.microprofile</groupId>
    <artifactId>microprofile</artifactId>
    <version>1.3</version>
    <type>pom</type>
    <scope>provided</scope>
</dependency>

Hence these are only "provided" dependencies, they are not included in a WAR. I built a Java EE 8, MP 1.3 microservice on stage: http://devoxx.pl with Java EE 8 and MP 1.3 features. It came with 11 kB Thin WAR

See you at Java EE Microservices. Is Munich's airport too far? Learn from home: javaeemicro.services.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Private Fields Serialization with JSON-B and JAX-RS 2.1 / Java EE 8

JSON-B from Java EE 8 serializes public fields or properties as default. For private field serialization:


public class Workshop {

    private String name;
    private int duration;

    public Workshop(String name, int duration) {
        this.name = name;
        this.duration = duration;
    }

}    

you will have to implement a PropertyVisibilityStrategy (checkout Java EE 8: Serializing POJOs with JSON-B):


    public class PrivateVisibilityStrategy implements PropertyVisibilityStrategy {
    
        @Override
        public boolean isVisible(Field field) {
            return true;
        }
    
        @Override
        public boolean isVisible(Method method) {
            return false;
        }
    
    }

...pass your custom configuration to the JsonbBuilder and return the instance with a ContextResolver:


    import javax.json.bind.Jsonb;
    import javax.json.bind.JsonbBuilder;
    import javax.json.bind.JsonbConfig;
    import javax.ws.rs.ext.ContextResolver;
    import javax.ws.rs.ext.Provider;
    
    @Provider
    public class JSONConfigurator implements ContextResolver {
    
        @Override
        public Jsonb getContext(Class type) {
            JsonbConfig config = new JsonbConfig().
                    withPropertyVisibilityStrategy(new PrivateVisibilityStrategy());
            return JsonbBuilder.newBuilder().
                    withConfig(config).
                    build();
        }
    }

Now your POJO's private fields are going to be used for JSON-mapping:


@Path("workshops")
public class WorkshopsResource {

    @GET
    public Workshop workshop() {
        return new Workshop("Java EE 8", 42);
    }

}

Result: {"duration":42,"name":"Java EE 8"}

Tested with Payara 5.

See you at Java EE Workshops at MUC Airport, particularly at the Effective Java EE 8 workshop


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Consuming MicroProfile Metrics with Prometheus

In this (free) screencast I created a MicroProfile project with microprofile-essentials-archetype and exposed method runtime statistics and configured prometheus.io (from docklands) to consume the metrics directly:

Also checkout Exposing Business Metrics with MicroProfile.

See you at Java EE Microservices. Is Munich's airport too far? Learn from home: javaeemicro.services.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

From Versioning, Automation and CI to File Upload, MVC, Scopes and Centralized Logging -- 51st airhacks.tv

"Versioning, tagging, branching, automation, CI/CD, autodeployment in production, JAX-RS and file upload, MVC 1.0 vs. servlets and JSPs, Primefaces as module, @Singleton vs. @ApplicationScoped vs. @RequestScoped and JAX-RS, centralized logging, logging vs. metrics and the future of webassembly":

Any questions left? Ask now: https://gist.github.com/AdamBien/bfa3a444b6af3316e772f8eaf133f1cb and get the answers at the next airhacks.tv.

Audio-only version is also available from: airhacks.fm podcast via: RSS iTunes

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Exposing Business Metrics with MicroProfile 1.3

In this (free) screencast I created a MicroProfile project with microprofile-essentials-archetype and exposed method runtime statistics as well as "business" metrics.

See you at Java EE Microservices. Is Munich's airport too far? Learn from home: javaeemicro.services.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Building Java EE 8 Applications For Fun -- Interview With LottoRitter

Ulrich, please introduce yourself

I am a passionated software architect and developer with more than 17 years of experiences in different industries and in implementation of mission critical software, that is reliable, performant and highly available.
Currently, I change from employed to self-employed as Java Freelancer and start the first project in June.
You can find me on my Personal website, XING, LinkedIn and GitHub.

I developed the project http://www.lottoritter.de with Christopher Schmidt. He is born in Hamburg/Germany and he is very fascinated by software development. He started with PHP/HTML/CSS in his early years, but later on he focused on JavaSE and JavaEE. He has many years of experience in software development, especially in Java projects.
Christoper can be found on XING, Twitter and GitHub.

What are you building with Java EE?

Christopher and me were building an OpenSource-JavaEE 8 project http://www.lottoritter.de. On this platform, you can "play German Lotto" for fun. You don't spend any money (and unfortunately you cannot win any money :-)). You register via eMail or OAuth (Google, Facebook, Instagram) and then you can 'buy' tickets with a dummy credit card for Lotto 6aus49, EuroJackpot, GlücksSpirale and Keno. The drawings of the lottery are fetched via background processes.
You can found the source code here: https://github.com/Lottoritter/lottoritter-platform/

Why you started the project?

We started the project to prove, that you can build cool projects with JavaEE. For the frontend, we use JSF and JavaScript for the ticket-engine. We were developing for 4 month in spare time for the complete platform. So everyone can see, that JavaEE is highly productive. And it was a lot of fun, because we could focus mainly on the business features. Infrastructure like Application Server (we use Payara) and Database (MongoDB Atlas) just works and don't need much administration. The productive environment runs on a small private server in a docker container.

Can you share with us some geeky numbers like e.g. TX per seconds, heap sizes, thinnest WARs etc -- whatever Java EE devs might find interesting.

We did not make marketing, because this has more of a fun project without any profit thinking (we do not have any advertising or web-trackers or whatever). The project is straightforward, so we have no "Microservice"-architecture, but a simple WAR for deploying on the application server. That's it. So we don't have high load or many concurrent transaction with which we can 'boast' about.
For us, it was more interesting to share the code, so that others can reference to it and see, how easy it is to structure the code (thanks to your BCE-package pattern ;-)) and get a project up and running.

How big is your WAR?

It is 26MB all inclusive (Java, additional libraries, HTML, images and so on). But 80% of the size are consumed by third-party-libraries such as OAuth, Primefaces, Database-Driver and their transitive dependencies. The size of the written Java code is around 1 MB (15k real lines of code).

Are you happy with Java EE so far? Is Java EE productive?

Yes, I am extremely happy. The "component" model with EJB and CDI in combination with the Boundary-Control-Entity (BCE) package structure let you write clear business code. Ok, there are framework-classes like a Webfilter and the identity stores for the Java security API (Soteria) and something else like that, but 90% of the code is business related. So it is really productive. As I said before, we implemented this within 4 month in spare time.
Furthermore, it es very easy to introduce CI and to integrate everything to Amazon AWS Elastic Container Service or other platforms.
Perhaps JavaEE is not fancy, but the most business cases in general don't need fancy things. The goal is "make the project run". And it is not a good idea to make things unnecessary complicated. Java and the JavaEE APIs provide you with 90% of what you need to build the features of any general project. I like the smooth integration of the JavaEE-APIs, which is even better in Java EE 8 (see Soteria which is an incredible step forward in making Java security much easier to implement).

Which application servers, tools or IDEs are you using?

I use IntelliJ IDEA for sure ;-). The application runs on Payara 5, because it 'extends' from Glassfish, which is the reference implementation of JavaEE, but Payara is updated frequently and so, it has always the current working versions of the JavaEE-API implementation libraries.
MongoDB as database, because the document centric approach fits much better to the domain-driven-design/model and it makes implementation much simpler. In addition with MongoDB-Morphia as object-document-mapper, it is so easy to write clean code.
It is a standard Maven project, so the project can be build with the 'build pipeline' like mvn clean install && docker build ... && docker run ....

You are using the Boundary Control Entity pattern to structure your applications. What were your experiences, challenges and findings so far?

Yes, I heard of this pattern for the first time in one of your screencasts about 5 years ago. It was so stupid simple, and that's why I really like this pattern. I can structure the code for business aspects, so it is easy to get along with the code. Furthermore, you can design your code exactly like the real world. Lottoritter for example has tickets, shoppingcart, drawings, players and so on, and these business entities are exactly modelled/structured in the code and you find exactly these named packages
The only 'challenge' is, where to put classes with cross-cutting functionality. But with a bit of clear thinking, you always find a proper solution (in my opinion ;-)).

How important are standards for you? Does your application depend on application server specific APIs?

Standards are extremely important for me. They are clearly defined and you can trust on them. It is well documented, you can read the official specification-documents and the documentation for the corresponding implementation. I don't like surprises in software-projects and I want to be sure, that 'technical' things work as described. So standards let me sleep a bit better ;-).
There are no dependencies on application specific APIs. So, as soon as other application servers fully support JavaEE 8 in the future, then this project could be run on other servers as well without changes.
I don't want to waste time dealing with technical problems, but I want to implement valuable business features, for customers and as well as for my personal projects.

Did you had the chance to chat with other attendees during the airhacks.com? If yes, what was the most interesting project / problem / situation in the workshops?

I attended the JavaEE Bootstrap and Effective JavaEE days in March 2013. These two days were really cool. It was interesting to listen to others, who have the same problems at work. Mainly, the acceptance for JavaEE was a main topic. Most managers/decision makers have the J2EE-patterns in mind, with local- and remote-interfaces and all the XML-stuff. But these days are over for years. It is interesting, that even in 2018 (for example, if you talk to Spring developers), they also think of JavaEE as how it was to the J2EE epoch. Many people don't know, that JavaEE has evolved to a real lightweight enterprise application platform.

Which Java EE APIs are you using in your products?

EJB (@Stateless) and CDI are the JavaEE APIs, which I cannot miss. They are the building blocks of the whole application. You recorded a Youtube-Video some years ago about the metrics, which are exposed by every application server since years. So I get these information for free when using EJBs.
In addition, I use JAXB (for JSON to JavaObject conversion between backend and the Javascript-Ticket-engine), JAX-RS for sure ;-), Java Security API (Soteria), which is so smart and useful now (in earlier days, Java Application server security was always very difficult and proprietary to setup).

Ulrich, thank you for the interview!


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Versioning, Tagging, Automation, CI, Logging, MVC 1.0, or 51st airhacks.tv

Topics and questions: https://gist.github.com/AdamBien/dc00f6b83c2430c91533486e72fb4d54 for the 51st airhacks.tv

  • Versioning (internal, production, etc.)
  • Tagging automation
  • To branch or not to branch
  • Using autodeploy for production?
  • Uploading a file with JAX-RS
  • MVC 1.0 thoughts
  • Primefaces as WildFly module or WildFly swarm
  • @Singleton vs. @Stateless
  • Java EE and centralized logging
  • Are separate stacks for logging and monitoring a best practce?
  • Automatically emitting metrics via JAX-RS

Ask questions during the show via twitter mentioning me: http://twitter.com/AdamBien (@AdamBien) or using the hashtag: #airhacks. You can join the Q&A session live each first Monday of month, 6 P.M at airhacks.tv or http://www.ustream.tv/channel/adambien

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

WildFly and JBoss -- A Conversation with Jason Greene, Chief Architect, JBoss EAP

A conversation with Jason Greene @jtgreene about HotJava on Sparc, increasing productivity, Tomcat, OrionServer, JBoss, Jigsaw W3C's Server, JavaServer Web Development Kit, flat network assumptions, SOAP and XML vs. IIOP, grpc, thrift, DTO bloat, Infinispan, Marc Fleury, POJO Cache, JBoss Cache, caching and concurrency, clustering, JBoss/WildFly clustering under the hood, using Infinispan as JMS provider, WildFly 13 provisioning infrastructure, WildFly as a platform, pruning CORBA, the danger of profiles, dying SOAP, WildFly 12 and Java EE 8, Hibernate 6 query optimization, quarterly WildFly releases, EAP release cadence, community enterprise and supported WildFly, EAP for developers, Java EE productivity and the declarative model, Java EE concurrency model, WildFly's killer features, undertow and wildfly.

Subscribe to airhacks.fm podcast via: RSS iTunes

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Simplistic Router With WebStandards

In this screencast I'm using the standard onhashchange event listener to replace a section with content loaded from an external file. It is a simplistic router:

This screencast is bonus material from: webstandards.training. You might also like: webcomponents.training.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

From Jakarta EE Profiles over Exception Handling To Swing Migrations -- 50th airhacks.tv

"Jakarta EE Profiles and News, Exception Handling, TransactionSynchronizationRegistry, UUID progation and XA, equals, hashcode and JPA, remote CDI, websockets testing, Code Coverage, Swing Migration and Thin WARs with Hibernate" or 50th airhacks.tv is available:

Any questions left? Ask now: https://gist.github.com/AdamBien/dc00f6b83c2430c91533486e72fb4d54 and get the answers at the next airhacks.tv.

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW MUC Airport Workshop: Migrating Java Client (Swing / Java FX) to Web Standards

Airport MUC workshops: Web (SPA, PWAs, Offline, Desktop, Mobile) Applications Essentials and Effective Web Applications. No migrations. #usetheplatform

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License