Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
JavaEE 8 on a diet with Payara Micro 5
1. Java EE8 on a Diet with
Payara Micro 5
Mert Çalışkan, Gaurav Gupta
JavaOne 2017
2. Mert Çalışkan
Payara Developer
Java EE / Spring Consultant
Author of PrimeFaces Cookbook
Author of Beginning Spring book
Part-time Lecturer
@mertcal
Gaurav Gupta
Payara Developer
NetBeans Dream Team
Jeddict Creator ( jeddict.github.io )
@jGauravGupta , @ImJeddict
12. ● Server Sent Events (SSE) is a mechanism that allows server to
asynchronously push data from the server to client once the client-server
connection is established by the client.
● It’s mostly like Long-Pooling but it’s not :) and it’s not WebSockets either.
● Implementations already provided it with JAX-RS 2.0 but there was no standard
API. With JAX-RS 2.1, API is created under javax.ws.rs.sse
JAX-RS 2.1
@mertcal
13. @Path("/temperature")
public class TemperatureResource {
private final OutboundSseEvent.Builder sseEventBuilder;
public TemperatureResource( @Context Sse sse) {
this.sseEventBuilder = sse.newEventBuilder();
}
@GET
@Path("/{city}")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void getCurrentTemperatureStream( @Context SseEventSink eventSink) {
while (true) {
eventSink.send( sseEventBuilder.data(temperature)
.mediaType(MediaType. APPLICATION_JSON_TYPE).build());
Thread. sleep(1000);
}
}
}
"text/event-stream"
1
2
3
4
JAX-RS 2.1
@mertcal
14. CDI 2.0 (JSR 365)
- SE Support - It’s possible to use CDI outside of Java EE
- Ordering of CDI events - @Priority helps ordering observers
void receive(@Observes @Priority(APPLICATION + 200) String greet) {
this.greet += greet + "2";
}
void receive2(@Observes @Priority(APPLICATION) String greet) {
this.greet = greet + "1";
}
For send(“Welcome”) output will be:
Welcome1Welcome2
@Inject
private Event<String> event;
public void send(String message) {
event.fire(message);
}
@mertcal
15. CompletableStage<MyEvent> eventSent = event.fireAsync( new MyEvent(),
NotificationOptions.ofExecutor(executor));
- Exception in async observer doesn’t break the observer invocation chain.
callMe(@Observes payload) callMe(@ObservesAsync payload)
event.fire(payload) Sync call Not Notified
event.fireAsync(payload) Not Notified Async call
- Long awaited Asynchronous Events Support
- Fire Sync → Observer Sync / Fire Async → Observer Async
CDI 2.0
@mertcal
16. ● Java 8 Date and Time API Support
@Past(message = "must be a past date")
private java.time.Year yearOfBirth;
● Type Annotations
private List<@NotNull @Email String> emails;
private String @NotNull @Email[] emails;
private Map<@Valid Employee, @Valid Address> addressMap = new HashMap<>();
@mertcal
Bean Validation 2 (JSR 380)
17. ● java.util.Optional Support
private Optional<@Past LocalDate> marriageAnniversary;
private Optional<@Size(max = 20) String> name;
● Repeating Annotations
@Max(value = 2000, groups = Default.class)
@Max(value = 5000, groups = GoldCustomer.class)
private long withdrawalAmount;
@mertcal
Bean Validation 2
19. JSON-B (JSR 367)
● Standard solution like JAXB
● Default mapping between classes and JSON
● Customizable
a. Compile time
■ Property naming @JsonbProperty
■ Property ignoring @JsonbTransient
■ Null handling @JsonbNillable
■ Property ordering @JsonbPropertyOrder
■ Date and Number Format @JsonbDateFormat/@JsonbNumberFormat
■ Adapter @JsonbTypeAdapter
b. Runtime configration
■ Configuration builder JsonbConfig
@jGauravGupta
22. JPA 2.2 (JSR 338)
● @Repeatable annotations
● Support Java 8 Date and Time API
● Ability to return stream of query result
● CDI Injection in AttributeConverters
@jGauravGupta
23. JPA 2.1
Container annotation required
@Entity
@NamedQueries({
@NamedQuery(name = "Speaker.findAll",
query = "SELECT s FROM Speaker s"),
@NamedQuery(name = "Speaker.findByName",
query = "SELECT s FROM Speaker s WHERE s.name = :name")
})
class Speaker {
@Convert(converter=LocalDateConverter.class)
private LocalDate dateOfBirth;
}
@jGauravGupta
AttributeConverter
implementation
24. JPA 2.2
Container annotation not required
@Entity
@NamedQueries({
@NamedQuery(name = "Speaker.findAll",
query = "SELECT s FROM Speaker s"),
@NamedQuery(name = "Speaker.findByName",
query = "SELECT s FROM Speaker s WHERE s.name = :name")
})
class Speaker {
@Convert(converter=LocalDateConverter.class)
private LocalDate dateOfBirth;
}
AttributeConverter not required @jGauravGupta
25. JPA 2.2
@Entity
@NamedQuery(name = "Speaker.findAll",
query = "SELECT s FROM Speaker s")
@NamedQuery(name = "Speaker.findByName",
query = "SELECT s FROM Speaker s WHERE s.name = :name")
class Speaker {
private LocalDate dateOfBirth;
}
@jGauravGupta
26. JPA 2.2
● Stream query results
Stream<Speaker> speakers =
em.createQuery(“SELECT s FROM Speaker”, Speaker.class)
.getResultStream();
@jGauravGupta
27. Security API 1.0 (JSR 375)
● Simplify the existing solution
● Enhance the portability
● New APIs
○ HTTPAuthenticationMechanism
○ IdentityStore
○ SecurityContext
@jGauravGupta
29. @ApplicationScoped
public class MyAuthMechanism implements HttpAuthenticationMechanism {
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request,
HttpServletResponse response, HttpMessageContext context) {
}
}
Security API 1.0
@jGauravGupta
30. @ApplicationScoped
public class MyAuthMechanism implements HttpAuthenticationMechanism {
@Inject
private IdentityStoreHandler identityStoreHandler;
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request,
HttpServletResponse response, HttpMessageContext context) {
………
identityStoreHandler.validate(credential);
………
}
}
Security API 1.0
@jGauravGupta
31. @ApplicationScoped
public class MyAuthMechanism implements HttpAuthenticationMechanism {
@Inject
private IdentityStoreHandler identityStoreHandler;
@Override
public AuthenticationStatus validateRequest (HttpServletRequest request,
HttpServletResponse response, HttpMessageContext context) {
………
identityStoreHandler.validate(credential);
………
}
}
Security API 1.0
@jGauravGupta
32. ● Application Server as Executable JAR
○ Small: ~70mb
● Deploy WAR files directly from command line
● Contains Java EE8 specification on board such as:
○ JAX-RS 2.1
○ Bean Validation 2.0
○ CDI 2.0
○ JPA 2.2
@mertcal
Payara Micro 5
33. ● Supports Automatic Clustering out of the box
○ Integrates with Hazelcast
○ Session replication with distributed caching
● JCA based Cloud Connectors
○ Amazon SQS
○ Kafka
○ MQTT
○ Azure Service Bus
● Eclipse MicroProfile Support w/ Config API
Payara Micro 5
@mertcal