Česky   |  Deutsch   |  English   |  Español   |  Français   |  Indonesia   |  日本語   |  한글   |  Polski   |  Português (BR)   |  Türkçe   |  中文   |  正體中文   |  Your Language  
PlanetNetbeans
Planet NetBeans is an aggregation of NetBeans related musings from all over the Blogosphere.
Adam Bien - October 16, 2017 04:26 AM
FDK, FN project, JSF, JSON or 43rd airhacks.tv is available

JavaONE 2017, FDK, fn project, EE4J, Java 18.3, and following topics were covered at the 43rd airhacks.tv:

Any questions left? Ask now: gist.github.com/AdamBien/a232908944dd0b3cad4d0b321fa6ee27 and see in at November, 6th, 6pm CET.

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 13, 2017 07:18 AM
JavaONE 2017: Bloat Removal With Microservices

Microservices are Thin WARs usually exposed via HTTP / JSON / WebSockets. By taking the architectural constraints into account allows us to remove a significant amount of bloat and indirections:

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.


Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 12, 2017 05:22 AM
Simplest Possible Java EE 8 Kickstarter

The 0.0.2 version of the javaee8-essentials-archetype:

mvn archetype:generate -DarchetypeGroupId=com.airhacks -DarchetypeArtifactId=javaee8-essentials-archetype -DarchetypeVersion=0.0.2

creates a ready to use 3.5kB Thin WAR project with configured JAX-RS runtime, a resource with a GET endpoint ("/ping"), GlassFish v5 Dockerfile and a shell script which executes the maven and Docker build image and eventually starts the image. The build-and-run cycle takes about ...5 seconds.

See it in action:

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 11, 2017 06:36 AM
Java EE 8: Convenient JsonArray Collector

Java EE 8 with JSON-P 1.1 introduces a java.util.stream.Collector implementation which converts a Collection<JsonObject> into a JsonArray instance:



import java.util.Arrays;
import java.util.List;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonArrayBuilder;
import javax.json.JsonObject;
import javax.json.stream.JsonCollectors;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;

public class JSONPTest {

    private List<JsonObject> list;
        
    @Before
    public void init() {
        this.list = Arrays.asList(next(), next());
    }

    public JsonObject next() {
        return Json.createObjectBuilder().
                add("number", System.currentTimeMillis()).
                build();
    }                
    
    @Test
    public void jsonArrayCollector() {
        JsonArray array = this.list.
                stream().
                collect(JsonCollectors.toJsonArray());
        assertThat(array.size(), is(list.size()));
    }
        

In Java EE 7 you would have to either write a custom collector or use a JsonArrayBuilder for the conversion:



        @Test
        public void toJsonArrayConversion() {
            JsonArrayBuilder builder = Json.createArrayBuilder();
            this.list.forEach(builder::add);
            JsonArray array = builder.build();
            assertThat(array.size(), is(list.size()));
        }    
See you at Java EE Workshops at Munich Airport, Terminal 2 and especially at Java EE 8 on Java 9. Is Munich's airport too far? Learn from home: airhacks.io.
Real World Java EE Workshops [Airport Munich]>

Java Evangelist John Yeary - October 10, 2017 01:42 PM
JAX-RS 2.0 Tip of the Day: Using MOXy and Forms Example on GlassFish 5.0

Glass Fish
I have been tasked with doing some JAX-RS coding during my day job. I wanted to update my skills for JAX-RS which is one of my favorite technologies. I specifically use Jersey which I find very well done and easy to use. As a number of you may know... I am a GlassFish fan too (one just needs to look at my banner). I decided to use my trusty NetBeans 8.2 install to write a quick example.

MOXy is enabled by default if you add the dependency to your Maven project.


This is a great feature, and I wanted to give it a spin instead of using Jackson, or Jettison. The usage was as simple as adding a @XmlRootElement annotation to the model class. The rest was handled automagically.

The entire project including a war file are available on Github: jaxrs-form-data-parameters.

A simple platform independent file is used to setup the application.


We set up web resource (service) to handle our requests.


That's it! You now have a JAX-RS Web Service. The project runs successfully on GlassFish 5.0 (.war file on GitHub).

NOTE: MOXy has some issues running on GlassFish 4.1, 4.1.1, and 4.2.

Adam Bien - October 10, 2017 05:57 AM
Java EE: Heavyweight or Lightweight? A Continuous Measurement Session from JavaONE

Are Java EE 7 "full profile" application servers lightweight or heavyweight compared to a "hello world" Java SE nano service? In this session we try to answer the question in a Continuous Measurement / Continuous Profiling style:

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 09, 2017 07:28 AM
JavaONE 2017 News, SSO, Serverside vs. Client, Testing JAX-RS, Logging, Versioning, Overengineering or 43rd airhacks.tv

Questions for the 43rd airhacks.tv:

  1. JavaONE 2017 News: keynotes, impressions, EE4J, project FN, Java 18.3
  2. Dynamic JMS listeners
  3. SSO, timeout and JWT
  4. Serverside rendering vs JavaScript UI
  5. openJDK vs. Oracle JDK in Docker
  6. User properties and Keycloak
  7. Testing JAX-RS with Keycloak
  8. 2 EARs one EJB jar problem
  9. Java EE and logging
  10. JSF conversations with architects
  11. Java EE versioning strategies
  12. User-friendly URIs in MVC / Ozark
  13. Optimistic and pessimistic locking
  14. Ideas for overengineering Pet Projects
  15. WildFly Datasource configuration in Docker
  16. @RequestScope with @Suspended
  17. Implementing a batch job
  18. POJO and JsonObject serialization in Java EE
  19. Qualifier instantiation in Java EE
  20. JPA-level security
  21. bind vs. self / this in JavaScript

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


Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 08, 2017 03:49 AM
Introducing the Java Function Developer Kit / fnproject.io

The opensource project fnproject.io is a "serverless", multi-language cloud-like environment which was introduced at JavaONE 2017.

In this 6 min screencast I create a Maven 3, dependency-less, plain Java SE project from scratch, create a Java class with a single method (aka "the function") and deploy it to the fnproject.io ("local cloud") using the Java Function Developer Kit (FDK) / Java runtime:

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.


Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 07, 2017 04:05 PM
JavaONE 2017: Java People Faces (JPF) 2017.10 -- LIghtening Interviews

A series of lightening interviews with "Java People" at JavaONE 2017 in San Francisco:

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.


Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 05, 2017 03:36 AM
Java EE 8: Serializing POJOs with JSON-B

Java EE 8 comes with JAXB-like, declarative JSON-binding JSON-B (JSR-367). In this screencast a POJO is serialized to JSON using custom PropertyVisibilityStrategy:

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.


Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 04, 2017 04:53 AM
Injecting Classes in Java SE with Java EE 8 and CDI 2.0

Java EE 8 (CDI 2.0) dependency works with plain Java SE:

See you at Java EE Workshops at Munich Airport, Terminal 2, particularly at Java EE 8 on Java 9


Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 03, 2017 04:43 AM
Persistent Collections, FDK, Serverless, EE4j, Kubernetes, Opensource -- or JavaONE 2017 Keynote

JavaONE keynote announcements / news:

  • Intel announced the availability of Persistent Collections for Java - datastructures persisted in non-volatile memory (=specific hardware).
  • Intel introduces Vector API Developer Program. Java gets new APIs for faster Vector operations without involving the JNI.
  • Everything Java EE related is going to be opensourced. Code name: EE4J. Full name: Eclipse Enterprise for Java @EclipseEE4J
  • Oracle invests (=manpower) in kubernetes / Java integration
  • A container native, serverless platform: fnProject was opensourced on stage: fn Project
  • Fn Java Functions Developer Kit (FDK) was announced: FDK
  • Java is going to be released every 6 months ("release train"). Next release is 18.3 (March, 2018)
  • Release 18.3 will contain the Local-Variable Type Inference (var list = new ArrayList<String&bt()) Project Amber is the language feature incubator project.
  • Oracle Java is going to be completely opensourced. There will be no differences between openJDK and Oracle JDK.

It was one of the best and most interesting JavaONE keynotes. Even the sponsor slot (Intel) was funny and came with developer-relevant information.

Any questions left? Ask here and checkout 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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 02, 2017 02:45 AM
Java 9: Nashorn Scripting / Automation Improvement

Nashorn's $EXEC built-in function was extended to support Java's System.out and System.err as parameters:


#!/usr/bin/jjs -fv
var cmd = "mvn clean install"
var System = Java.type("java.lang.System");
$EXEC(cmd, System.in, System.out, System.err);

The code above executes Maven and "streams" the output in real time into the console. With Java 9 Nashorn is even more useful for cross-platform automation of OS-level tasks.

Docklands Dockerfiles come with Nashorn script: build.js.

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - October 01, 2017 02:09 PM
Configuring WildFly/JBoss via CLI

The WildFly comes with a Command Line Interface which can be used for deployment as well configuration:

Checkout related posts: "Configuring WildFly via JMX" and "Transaction Monitoring with WildFly"

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.


Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 30, 2017 01:20 PM
Java 9: Executing fallbacks with Optional::or

Java 9 comes with an additional Optional.or method with the following functionality:

"If a value is present, returns an Optional describing the value, otherwise returns an Optional produced by the supplying function."

The method Optional::or is useful for the implementation of fallback logic. The example below return an Integer with the value 42:


import java.util.Optional;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;

public class OptionalTest {

    @Test
    public void or() {
        int message = this.answer().
                map(Integer::parseInt).
                or(this::defaultAnswer).
                get();
        assertThat(message, is(42));
    }

    public Optional<String> answer() {
        return Optional.ofNullable(null);
    }

    public Optional<Integer> defaultAnswer() {
        return Optional.of(42);
    }
}    

The method answer returns null, therefore the method map is not executed. The (fallback) or branch is executed instead and returns directly the 42 as integer.

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 29, 2017 04:32 AM
Asynchronous Browser Push with HTTP/2, Servlets 4.0 and Java EE 8

In this screencast I'm pushing proactively and asynchronously content to the browser with Servlet 4.0, Java EE 8 and HTTP/2:

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 28, 2017 06:46 AM
Java EE 8 Essentials Archetype (maven quickstart) released

The maven quickstart "wizard" for Thin WARs / zero dependencies, Java EE 8 projects is available:


mvn archetype:generate -DarchetypeGroupId=com.airhacks -DarchetypeArtifactId=javaee8-essentials-archetype -DarchetypeVersion=0.0.1

The archetype's source is available at: https://github.com/AdamBien/javaee8-essentials-archetype.

May your WARs be thin!

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 27, 2017 10:05 AM
JavaScript Server-Sent Events Client For Java EE 8 Backend

In this screencast I'm writing an ES 6 / JavaScript client which receives Server-Sent Events emitted by a Java EE 8 / GlassFish v5 application:

Interested in lean webapps? Checkout: WebStandards Igniter online workshop or WebApps Essentials workshop at MUC Airport.

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


Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 26, 2017 06:28 AM
Configuring WildFly via JMX

The WildFly application server can be easily (=without typos) configured using JMX tools like jconsole (used in this screencast) or jvisualvm with MBeans browser:

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


Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 25, 2017 04:38 AM
Docklands: GlassFish v5 (Java EE 8) Docker Image

The GlassFish v5 (Java EE 8) release image is available from docklands [Dockerfile].

To launch GlassFish v5 execute: docker run -p 8080:8080 -p 4848:4848 --name gf airhacks/glassfish:v5

GlassFish v5 image with Ping was updated as well and can be launched with: docker run -d -p 8080:8080 --name ping airhacks/glassfish-ping.

The following screencast demonstrates a Thin WAR deployment into Docker.

See you at Java EE Microservices. Is Munich's airport too far? Learn from home: javaeemicro.services.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 24, 2017 04:52 AM
Scheduler and Business Logic Separation

Splitting a scheduler:


@Startup
@Singleton
public class Reminder {

    @Inject
    CoffeeBrewer brewer;

    @Schedule(minute = "*/30", hour = "*")
    public void remind() {
        this.brewer.brew();
    }
}    

...and the business logic:


@Stateless
public class CoffeeBrewer {

    public void brew() {
        this.boil();
        this.grind();
        this.deliver();
        this.pay();
    }

    void boil() {}
    void grind() {}
    void deliver() { }
    void pay() {}
}        

...into separate classes (dedicated boundary and control) allows the application server to inject proxies. Proxying comes with following benefits:

  1. Fine grained transaction management: business logic (CoffeeBrewer) can use declarative transactions as usual
  2. Monitoring: application server will expose monitoring statistics for both classes
  3. Interception: individual interceptors can be use on both: the scheduler as well as the business logic
  4. Less noise: dynamic/flexible Schedulers require additional configuration logic. With scheduler / business logic separation, the business logic class remains unaffected and clean.
  5. Easier unit testing: there is no scheduling code in the business logic

...and the downside? You have to write one more class...

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 22, 2017 08:26 AM
Transaction Monitoring with WildFly

The WildFly Java EE application server comes with extensive monitoring capabilities. In this screencast I'm monitoring the number of commits and rollbacks of a deployed Java EE application:

See you at: Tuning and troubleshooting Java EE 7 applications


Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 21, 2017 04:59 AM
Java 8: Catching Integer Overflows

In Java the addition: Integer.MAX_VALUE + Integer.MAX_VALUE results in -2 without complaining. The following unit test passes:

    
        @Test
        public void addWithOverflow() {
            int result = Integer.MAX_VALUE + Integer.MAX_VALUE;
            assertThat(result, is(-2));
        }
    

Java 8 allows you to catch the overflows as ArithmeticException instances by using the Math.addExact (multiplyExact, subtractExact etc.) method.

The following test also passes:

    
        @Rule
        public ExpectedException expected = ExpectedException.none();
    
        @Test
        public void addWithOverflowAndCatch() {
            expected.expect(ArithmeticException.class);
            expected.expectMessage(containsString("integer overflow"));
            Math.addExact(Integer.MAX_VALUE, Integer.MAX_VALUE);
        }    

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 18, 2017 07:17 AM
WebStandards Igniter On-Demand Workshop

80+ episodes of continuous HTML 5, CSS 3, JavaScript (ES 6/7) coding workshop is available: webstandards.training. Only vanilla WebStandards, without any external frameworks or dependencies, were used.

Are you already building, or still migrating? Learn once, apply anywhere :-):

See you also at: WebStandards Igniter Workshop at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 14, 2017 04:51 AM
42nd airhacks.tv is available -- The Answer to all questions included

The airhacks.tv 42nd episode with "The Answer to all questions" is available:

Any questions left? Ask now or suggest a topic: https://gist.github.com/AdamBien/ec94900a3efd5d621bf4f00cc8a0dbac.

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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 11, 2017 05:54 AM
Early Autumn Java (EE) / Web Events

See you soon at:


Real World Java EE Workshops [Airport Munich]>

NetBeans – Michael's blog - September 10, 2017 08:19 PM
Using WebSockets with Java EE, part 2.3

Technical aspects of the WebSocket protocol WebSockets in a Java EE 7 application JSF 2.3 and WebSocket As mentioned before, I divided part two into a couple of sub parts. Today I’ll finish with WebSockets in a Java EE 7. If we want the user to choose a different chat room which is operated on […]

Adam Bien - September 10, 2017 10:03 AM
A Java EE 7+ Alternative To EJB Timers

In addition to EJB timers (Simplest Possible EJB 3.1 Timer), with Java EE 7+ you can directly inject ManagedScheduledExecutorService, a subclass of ScheduledExecutorService available in stock Java SE:

    
        import java.time.LocalTime;
        import java.util.concurrent.TimeUnit;
        import javax.annotation.PostConstruct;
        import javax.annotation.Resource;
        import javax.ejb.Singleton;
        import javax.ejb.Startup;
        import javax.enterprise.concurrent.ManagedScheduledExecutorService;
        
        @Startup
        @Singleton
        public class Scheduler {
        
            static final long INITIAL_DELAY = 0;
            static final long PERIOD = 2;
        
            @Resource
            ManagedScheduledExecutorService scheduler;
        
            @PostConstruct
            public void init() {
                this.scheduler.scheduleAtFixedRate(this::invokePeriodically, 
                        INITIAL_DELAY, PERIOD, 
                        TimeUnit.SECONDS);
            }
        
            public void invokePeriodically() {
                System.out.println("Don't use sout in prod " + LocalTime.now());
            }
        
        }
    
Immediately after deployment, you should find the following output (likely with different timestamp :-):
    
        Info:   Don't use sout in prod 11:31:39.093
        Info:   Don't use sout in prod 11:31:41.097
        Info:   Don't use sout in prod 11:31:43.096
    
(ManagedScheduledExecutorService replaced EJB 3.1 timers in a project as a workaround to appserver configuration issues in production) 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.
Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 07, 2017 03:58 PM
Microservices' Impact On App Design, Lightweight Java EE and Java EE-stic HTML 5 ...or my JavaOne 2017 sessions


Session ID: CON5252
Session Title: Microservices and Cloud-Driven Code Simplification
Room: Moscone West - Room 2003 Date: 10/03/17
Start Time: 09:30:00 AM
End Time: 10:15:00 AM

Session ID: CON5567
Session Title: The Java EE-stic (=No Dependencies) Way to Develop HTML5 Applications
Room: Moscone West - Room 2006 Date: 10/04/17
Start Time: 09:30:00 AM
End Time: 10:15:00 AM

Session ID: CON5578
Session Title: Java EE: Heavyweight or Lightweight—Mythbusters
Room: Moscone West - Room 2020 Date: 10/04/17
Start Time: 08:30:00 AM
End Time: 09:15:00 AM

I'm also invited to the panel:

Session Title: Powerful Lessons from Top Java EE Experts
Room: Moscone West - Room 2002: Java User Group Track 
Date: 10/01/17
Start Time: 04:00:00 PM
End Time: 04:45:00 PM

Thanks and see you soon at JavaOne 2017, airhacks.com or airhacks.io


Real World Java EE Workshops [Airport Munich]>

Adam Bien - September 04, 2017 10:14 AM
42- the answer, Fork Join, Pixel Perfect JSF, Building React and Angular, Scanning JAX-RS, Async CDI Events, Monolith or Topics For 42nd airhacks.tv

Topics for the 42nd airhacks.tv:

  1. 42 airhacks.tv - the answer to all questions
  2. ForkJoin support in Java EE 8
  3. Java FX in the browser
  4. Code coverage in system tests
  5. Opensource Java EE
  6. Auto-scanning JAX-RS resources
  7. Java and the job market
  8. @Stateless as an interceptor?
  9. Asynchronous CDI Events
  10. Empty POST or PUT
  11. @Stateful EJBs and usecases for the Gateway pattern
  12. Will CDI replace EJB in the future?
  13. Java EE 7 server recommendations
  14. GlassFish clustering / workshop
  15. JSF and pixel perfect applications
  16. Impact of react and angular on the delivery pipeline
  17. How to build JS frontends with Java EE backends
  18. Using multithreaded JAX RS 2.0 in Java SE
  19. Incrementally splitting a monolith: protocols, security processes

See full topics gist.

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


Real World Java EE Workshops [Airport Munich]>