When Enterprise Java Micro Profile meets Angular

Antonio Goncalves
Antonio GoncalvesCTO at AllCraft
#devoxxfr #ngjava @sebastienpertus @agoncal
Enterprise Java MicroProfile
TypeScript and Angular
Sebastien Pertus
Antonio Goncalves
#devoxxfr #ngjava @sebastienpertus @agoncal
Agenda
• Enterprise Java MicroProfile
• TypeScript
• Docker
• Angular 2
• Break
• Exposing & consuming REST APIs with Angular 2
• Tips and tricks:
• APIs, Swagger, Cors, Hateoas, Etag, JWT, Scaling
Ask questions
#devoxxfr #ngjava @sebastienpertus @agoncal
Sebastien Pertus
• Microsoft Technical Evangelist
• OSS Lover
• Full Stack developer
• Node.JS & .Net Core advocate
• SQL Server man
• Develops on Windows (yeah yeah)
#devoxxfr #ngjava @sebastienpertus @agoncal
Antonio Goncalves
• Java Champion
• Loves back-end
• Hates front-end
• Develops on Mac
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
The Conference App
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
The Conference App
https://github.com/agoncal/agoncal-
application-conference
#devoxxfr #ngjava @sebastienpertus @agoncal
Optimizing Enterprise Java
for a Microservices Architecture
#devoxxfr #ngjava @sebastienpertus @agoncal
Fundamental Shifts in Computing
Cloud
Microservices
Reduce time to market
Address unpredictable loads
Pay as you go
Containerization
Deliver new features more quickly
Smaller, more agile teams
Deliver business features as discrete services
Scale services independently
#devoxxfr #ngjava @sebastienpertus @agoncal
• Began as a of independent discussions
• Many “microservices” efforts exist in Java EE
• WildFly Swarm
• WebSphere Liberty
• Payara
• TomEE
• New features to address microservices architectures
• Java EE already being used for microservices…
• ...but we can do better
MicroProfile Background
#devoxxfr #ngjava @sebastienpertus @agoncal
Release Schedule
Sep 2016
MicroProfile
1.0
Q4 2016 2017 2017
Move to
Foundation
MicroProfile
1.1
MicroProfile
1.2
JAX-RS
CDI
JSON-P
#devoxxfr #ngjava @sebastienpertus @agoncal
MicroProfile 1.1 Underway
Security: JWT Token Exchange
Health Check
Configuration
Fault Tolerance
Second Quarter
2017!
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
WildFly Swarm
• Based on good old JBoss AS
• « Rightsize your services »
• Bundles several fractions
• Java EE
• Netflix OSS (Ribbon, Hystrix, RxJava)
• Spring
• Logstash
• Swagger
• ...
#devoxxfr #ngjava @sebastienpertus @agoncal
Setting up Swarm and MicroProfile
<profile>
<id>swarm</id>
<dependencies><dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>microprofile</artifactId>
</dependency></dependencies>
<build>
<plugins><plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
</plugin></plugins>
</build>
</profile>
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Skinny War
Fat Jar
#devoxxfr #ngjava @sebastienpertus @agoncal
TypeScript:
JavaScript that
Scales
#devoxxfr #ngjava @sebastienpertus @agoncal
BRENDAN EICH ANDERS HEJLSBERG
Do you know those guys ?
Javascript creator
CTO / CEO Mozilla Foundation
Brave Software CEO
C# creator
Technical Fellow @ Microsoft
TypeScript creator and lead team
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
ES6 / EcmaScript 2015 / ES2015
ES6 is the most
important update
of JavaScript
Brendan Eich : - “We want to go faster. “
- “Every year, a new spec that will be shipped in nighty versions of moderns browsers”
#devoxxfr #ngjava @sebastienpertus @agoncal
Ecmascript evolution
ES 8
ES 7
(ES 2016)
ES 6
(ES 2015)
ES 5
ES 3 Core features
1997 ~~ 1999
new functions
strict mode, json
2009
class, promises, generators, arrow
functions, new syntax and
concepts …
2015
Exponential (**), array.includes,
2016
#devoxxfr #ngjava @sebastienpertus @agoncal
Rise of the transpilers: Typescript 2.0
#devoxxfr #ngjava @sebastienpertus @agoncal
TRANSPILER COMPILER
Transpiler vs Compiler
is a specific term for taking source code written in one
language and transforming into another language that
has a similar level of abstraction
TypeScript (subclass of JavaScript) to JavaScript
is the general term for taking source code written in one
language and transforming into another
C# to IL
Java to ByteCode
"CoffeeScript is to Ruby as TypeScript is to Java/C#/C++." - Luke Hoban
Reference : Steve Fenton – 2012 - https://www.stevefenton.co.uk/2012/11/compiling-vs-transpiling
#devoxxfr #ngjava @sebastienpertus @agoncal
A statically typed superset of
JavaScript
that compiles to plain JavaScript.
Oh wait … that transpiles 
B R O W S E R
H O S T
O S
#devoxxfr #ngjava @sebastienpertus @agoncal
Open Source
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
The feature gap
#devoxxfr #ngjava @sebastienpertus @agoncal
TypeScript IDE
#devoxxfr #ngjava @sebastienpertus @agoncal
One year, four releases
1.5
1.6
1.7
1.8
#devoxxfr #ngjava @sebastienpertus @agoncal
TypeScript 2.0
• Control flow based type analysis
• Non-nullable types
• Async/await downlevel support
• Readonly properties
• Private and protected Constructor
• Type “never”
#devoxxfr #ngjava @sebastienpertus @agoncal
TypeScript 2.1, 2.2
• New JS language service in Visual Studio
• Better and more refactoring support
• Extensions methods
• Mixin classes
• Better .jsx react native support
#devoxxfr #ngjava @sebastienpertus @agoncal
Nullable types
number
string
boolean
#devoxxfr #ngjava @sebastienpertus @agoncal
Non-nullable types
number
string
boolean
#devoxxfr #ngjava @sebastienpertus @agoncal
Non-nullable types
number
string
boolean
undefined null
#devoxxfr #ngjava @sebastienpertus @agoncal
Non-nullable types
string
undefined null
string | null | undefined
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Non Nullables Types
Control Flow
Async / await
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Docker
• « Build, Ship, Run »
• Containers, containers, containers
• Docker to run containers
• Docker-compose to compose several containers
• WildFly containers
• JRE container
#devoxxfr #ngjava @sebastienpertus @agoncal
Dockerfile Skinny War
FROM jboss/wildfly:10.1.0.Final
EXPOSE 8080
# Setting the Wildfly Admin console (user/pwd admin/admin)
RUN $JBOSS_HOME/bin/add-user.sh admin admin --silent
CMD $JBOSS_HOME/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0
COPY venue.war $JBOSS_HOME/standalone/deployments/
#devoxxfr #ngjava @sebastienpertus @agoncal
Dockerfile Far Jar
FROM openjdk:8-jre-alpine
EXPOSE 8080
COPY venue-swarm.jar /opt/venue-swarm.jar
ENTRYPOINT ["java", "-jar", "/opt/venue-swarm.jar"]
#devoxxfr #ngjava @sebastienpertus @agoncal
Dockerfile Angular Distribution
FROM nginx
EXPOSE 80
COPY ./dist /usr/share/nginx/html
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Skinny War Image
Fat Jar Image
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Angular : In a nutshell
Modules
Components
Services
#devoxxfr #ngjava @sebastienpertus @agoncal
Angular Component
#devoxxfr #ngjava @sebastienpertus @agoncal
Angular Module
#devoxxfr #ngjava @sebastienpertus @agoncal
Angular Dependency Injection
#devoxxfr #ngjava @sebastienpertus @agoncal
Angular & Webpack
#devoxxfr #ngjava @sebastienpertus @agoncal
ES7 THEN ES8 PROPOSAL ALREADY IMPLEMENTED IN TS
Decorators
Pattern that allow us to extend /
modify the behavior of a class /
function / propery
As you can see ….
It’s used A LOT in Angular 2
#devoxxfr #ngjava @sebastienpertus @agoncal
Decorators
class Person {
public lastName: string;
public firstName: string;
constructor(ln: string, fn: string) {
this.lastName = ln;
this.firstName = fn;
}
@log(false)
public getFullName(fnFirst: boolean = true) {
if (fnFirst)
return this.firstName + " " + this.lastName;
else
return this.lastName + " " + this.firstName;
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Decorators
function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
var desc = {
value: function (...args: any[]) {
// get the params
var params = args.map(arg => JSON.stringify(arg)).join();
// get the result
var result = descriptor.value.apply(this, args);
var resultString = JSON.stringify(result);
console.log(`function ${propertyKey} invoked. Params: ${params}. Result:
${resultString}`);
return result;
}
}
return desc;
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Angular CLI
Angular Command Line Interface
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Angular CLI
- Component
- Service
#devoxxfr #ngjava @sebastienpertus @agoncal
Agenda
• Enterprise Java MicroProfile
• TypeScript
• Docker
• Angular 2
• Break
• Exposing & consuming REST APIs with Angular 2
• Tips and tricks:
• APIs, Swagger, Cors, Hateoas, Etag, JWT, Scaling
Ask questions
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Exposing REST Endpoints
#devoxxfr #ngjava @sebastienpertus @agoncal
Conference Micro Services
#devoxxfr #ngjava @sebastienpertus @agoncal
Exposing « beautiful » APIs
• JSon:API
• OData
• Jsend
• HAL
• CPHL
• SIREN
• Google’s JSon Style Guide
• Do it your own
#devoxxfr #ngjava @sebastienpertus @agoncal
« Kind of » JSon:API
GET http://host/schedule/api/sessions
GET http://host/schedule/api/sessions?page=2
GET http://host/schedule/api/sessions?sort=title
GET http://host/schedule/api/sessions?sort=-title,date
POST http://host/schedule/api/sessions
GET http://host/schedule/api/sessions/abcd
REMOVE http://host/schedule/api/sessions/abcd
GET http://host/speaker/api/speakers/abcd
GET http://host/speaker/api/speakers/abcd?expand=false
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Swagger
• Simple yet powerful representation of your RESTful API
• API documentation
• What do you call?
• What are the parameters?
• What are the status code?
• Contract written in JSon (or Yaml)
• Donated to the Open API Initiative
#devoxxfr #ngjava @sebastienpertus @agoncal
Swagger’s ecosystem
#devoxxfr #ngjava @sebastienpertus @agoncal
Swagger APIs
@Path("/speakers")
@Api(description = "Speakers REST Endpoint")
public class SpeakerEndpoint {
@POST
@ApiOperation(value = "Adds a new speaker to the conference")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Invalid input")})
public Response add(@NotNull Speaker speaker) { ... }
@GET @Path("/{id}")
@ApiOperation(value = "Finds a speaker by ID")
public Response retrieve(@PathParam("id") String id) { ... }
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Swagger Maven Plugin
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<configuration>
<apiSources><apiSource>
<locations>org.agoncal.conference.venue.rest</locations>
<schemes>http,https</schemes>
<host>localhost:8080</host>
<basePath>/api</basePath>
<info>
<title>Room</title>
<version>1.0.0</version>
<description>Rooms of the venue</description>
</info>
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Swagger TypeScript for Angular generation
public add(room: models.Room): Observable<{}> {
return this.http.request(path, requestOptions)
.map((response: Response) => { … });
}
public retrieve(id: string, extraHttpRequestParams?: any): Observable<models.Room> {
return this.http.request(path, requestOptions)
.map((response: Response) => { … });
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Generate Angular from Swagger
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Proxy
#devoxxfr #ngjava @sebastienpertus @agoncal
CORS
• Cross-Origin Resource Sharing
• Specification (https://www.w3.org/TR/cors/)
• Access across domain-boundaries
• JavaScript and web programming has grown
• But the same-origin policy still remains
• Prevents JavaScript from making requests across domain
boundaries
#devoxxfr #ngjava @sebastienpertus @agoncal
HTTP Header
Access-Control-Allow-Origin
Access-Control-Allow-Credentials
Access-Control-Expose-Headers
Access-Control-Max-Age
Access-Control-Allow-Methods
Access-Control-Allow-Headers
Access-Control-Request-Method
Access-Control-Request-Headers
#devoxxfr #ngjava @sebastienpertus @agoncal
CORS
@Provider
public class CORSFilter implements ContainerResponseFilter {
public void filter(ContainerRequestContext request,
ContainerResponseContext response) throws IOException {
response.getHeaders().add("Access-Control-Allow-Origin", "*");
response.getHeaders().add("Access-Control-Allow-Headers",
"origin, content-type, accept, authorization, Etag");
response.getHeaders().add("Access-Control-Allow-Credentials",
"true");
response.getHeaders().add("Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS, HEAD");
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
HateOAS
• « Hypermedia as the engine of application state »
• At its core is the concept of « hypermedia »
• Or in other words: the idea of links
• Client application goes from one state to the next by following a link
• Runtime contract
• Nothing in Java EE, maybe in MicroProfile
• JAX-RS has a Link API
#devoxxfr #ngjava @sebastienpertus @agoncal
Links
links: {
self: "http://host/schedule/api/sessions?page=1",
first: "http://host/schedule/api/sessions?page=1",
last: "http://host/schedule/api/sessions?page=14",
next: "http://host/schedule/api/sessions?page=2",
monday: "http://host/schedule/api/sessions/monday",
tuesday: "http://host/schedule/api/sessions/tuesday"
},
data: [ {
links: {
self: "http://host/schedule/api/sessions/uni_room9_tuesd"
},
id: "uni_room9_tuesday_8_9h30_12h30",
title: ”Java EE and Angular 2",
#devoxxfr #ngjava @sebastienpertus @agoncal
http://www.iana.org/assignments/link-relations/link-relations.xml
#devoxxfr #ngjava @sebastienpertus @agoncal
Links
@XmlType(name = "links")
public abstract class LinkableResource implements Identifiable {
private Map<String, URI> links;
public void addSelfLink(URI uri) {
addLink(SELF, uri);
}
public void addCollectionLink(URI uri) {
addLink(COLLECTION, uri);
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Links
if (body.links) {
this.links = {};
for (let key in body.links) {
this.links[key] = body.links[key] !== undefined ? body.links[key] : null;
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
HateOAS
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Caching
• HTTP has temporary storage (caching)
• Reduce bandwidth usage
• Reduce server load
• Reduce perceived lag
• ETags, or entity-tags: "conditional" requests.
• Checksum
• If-None-Match
#devoxxfr #ngjava @sebastienpertus @agoncal
Etag Generation
@GET @Path("/{id}")
public Response retrieve(@PathParam("id") String id,
@Context Request request) {
Talk talk = talkRepository.findById(id);
EntityTag etag = new EntityTag(talk.hashCode());
Response.ResponseBuilder preconditions =
request.evaluatePreconditions(etag);
if (preconditions == null) {
preconditions = Response.ok(talk).tag(etag);
}
return preconditions.build();
}
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
ETag & caching
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
JSon Web Token
• Lightweigh token
• Contains « some » data (claims)
• Base64
• Encrypted
• Passed in the HTTP Header
• Sent at each request
• Not in Java EE nor Microprofile (yet)
• Many librairies
#devoxxfr #ngjava @sebastienpertus @agoncal
A Token
Bearer
eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZ29uY2FsIiwiaXNzIjoi
aHR0cDovL2NvbmZlcmVuY2UuZG9ja2VyLmxvY2FsaG9zd
Do5MC9jb25mZXJlbmNlLWF0dGVuZGVlL2FwaS9hdHRlbm
RlZXMvbG9naW4iLCJpYXQiOjE0Nzc0OTk3NTUsImV4cCI6
MTQ3NzUwMDY1NX0.aL0a_q5wC3cesBKhkXChg30zr3W
WOsYhFhpJ0lQ479LtLjrPvTQiDH0N_YnFuARuEuy299S4u
O0yXGmX0tSs-Q
#devoxxfr #ngjava @sebastienpertus @agoncal
A Token
Bearer
eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZ29uY2FsIiwiaXNzIjoi
aHR0cDovL2NvbmZlcmVuY2UuZG9ja2VyLmxvY2FsaG9zd
Do5MC9jb25mZXJlbmNlLWF0dGVuZGVlL2FwaS9hdHRlbm
RlZXMvbG9naW4iLCJpYXQiOjE0Nzc0OTk3NTUsImV4cCI6
MTQ3NzUwMDY1NX0.aL0a_q5wC3cesBKhkXChg30zr3W
WOsYhFhpJ0lQ479LtLjrPvTQiDH0N_YnFuARuEuy299S4u
O0yXGmX0tSs-Q
#devoxxfr #ngjava @sebastienpertus @agoncal
A Token
HEADER: { "alg": "HS512" }
PAYLOAD:{
"sub": "agoncal",
"iss": "http://host/attendee/api/login",
"iat": 1477499755,
"exp": 1477500655
}
VERIFY SIGNATURE HMACSHA256(...)
#devoxxfr #ngjava @sebastienpertus @agoncal
JWT Generation
@Path("/attendees")
public class AttendeeEndpoint {
@POST @Path("/login")
@Consumes(APPLICATION_FORM_URLENCODED)
public Response auth(@FormParam("login") String login,
@FormParam("password") String password) {
// Authentication, security exception and so on...
return Response.ok().header(AUTHORIZATION, "Bearer " +
issueToken(login)).build();
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Filter to Check the Token
@JWTTokenNeeded
@Provider @Priority(Priorities.AUTHENTICATION)
public class JWTTokenNeededFilter implements ContainerRequestFilter{
public void filter(ContainerRequestContext ctx) {
String auth = ctx.getHeaderString(HttpHeaders.AUTHORIZATION);
if (auth == null || !authorizationHeader.startsWith("Bearer")) {
throw new NotAuthorizedException("No Bearer");
}
String token = auth.substring("Bearer".length()).trim();
Jwts.parser().setSigningKey(key).parseClaimsJws(token);
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Check the Token
@Path("/ratings")
public class RatingEndpoint {
@JWTTokenNeeded
@POST
public Response rate(...) {
}
@GET
public Response retrieve(...) {
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
JWT Consumption
return this.http
.post(this.basePath, body, requestOptions)
.map((response: Response) => {
if (response.status !== 200) {
return undefined;
}
this.jwt = response.headers.get('authorization');
if (!this.jwt)
return undefined;
return this.jwt;
})
.catch((error: any) => {
return undefined
});
#devoxxfr #ngjava @sebastienpertus @agoncal
@Injectable()
export class AuthGuardService implements CanActivate {
constructor(private authService: AuthService, private router: Router) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean
{
let url: string = state.url;
return this.checkLogin(url);
}
checkLogin(url: string): boolean {
if (this.authService.isLoggedIn) {
return true;
}
this.router.navigate(['/login'], { queryParams: { redirectTo: url } });
return false;
}
}
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Passing a token around
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Scaling
• Stateless architecture
• No cookie
• No HTTP session
• No local cache
• Stateless scales better than statefull
• Clients can round robin
• Dynamic proxy
• Meet Traeffik
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Proxy
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Traeffik
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Going in production with Angular
• By default, Angular (in dev mode) is about … 4 mb !
• Angular cli and webpack will:
• Uglify your JavaScript code
• Create a standalone bundle file
• Gzip compress
• Apply a tree shaking to delete unused code (it’s not dead code, btw !)
• Could use AOT compilation
#devoxxfr #ngjava @sebastienpertus @agoncal
JIT vs AOT Compilation
Source Code
JIT Compilation
Code Generation
VM execution
Source Code
AOT Compilation
Code Generation
VM execution
BUILD
RUN
#devoxxfr #ngjava @sebastienpertus @agoncal
With AOT, AN Angular project could be 60 – 70 % less code
http://slides.com/wassimchegham/demystifying-ahead-of-time-compilation-in-angular-2-aot-jit#/32
#devoxxfr #ngjava @sebastienpertus @agoncal
Demo Time !
Angular Production ready
#devoxxfr #ngjava @sebastienpertus @agoncal
Conclusion
• MicroProfile 1.1 will bring more MicroServices features
• Configuration
• Security: JWT Token Exchange
• Health Check
• Fault Tolerance
• More to come
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Conclusion
• Angular 4
• Native Script
• TypeScript 2.x
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
#devoxxfr #ngjava @sebastienpertus @agoncal
Enterprise Java MicroProfile
TypeScript and Angular
Sebastien Pertus
Antonio Goncalves
https://github.com/agoncal/agoncal-application-conference
1 of 119

Recommended

To inject or not to inject: CDI is the question by
To inject or not to inject: CDI is the questionTo inject or not to inject: CDI is the question
To inject or not to inject: CDI is the questionAntonio Goncalves
7K views81 slides
Are app servers still fascinating by
Are app servers still fascinatingAre app servers still fascinating
Are app servers still fascinatingAntonio Goncalves
1.9K views68 slides
What's new in Java EE 6 by
What's new in Java EE 6What's new in Java EE 6
What's new in Java EE 6Antonio Goncalves
4.5K views81 slides
Come and Play! with Java EE 7 by
Come and Play! with Java EE 7Come and Play! with Java EE 7
Come and Play! with Java EE 7Antonio Goncalves
6.5K views26 slides
CDI: How do I ? by
CDI: How do I ?CDI: How do I ?
CDI: How do I ?Antonio Goncalves
8.8K views154 slides
Just enough app server by
Just enough app serverJust enough app server
Just enough app serverAntonio Goncalves
27.4K views60 slides

More Related Content

What's hot

Intro to Unit Testing in AngularJS by
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJSJim Lynch
934 views53 slides
Unit Testing and Coverage for AngularJS by
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJSKnoldus Inc.
4.8K views22 slides
Test-Driven Development of AngularJS Applications by
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS ApplicationsFITC
9.3K views169 slides
We Are All Testers Now: The Testing Pyramid and Front-End Development by
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentAll Things Open
375 views60 slides
RSpec 3.0: Under the Covers by
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the CoversBrian Gesiak
10.1K views75 slides
Real World Dependency Injection - phpday by
Real World Dependency Injection - phpdayReal World Dependency Injection - phpday
Real World Dependency Injection - phpdayStephan Hochdörfer
3.3K views69 slides

What's hot(20)

Intro to Unit Testing in AngularJS by Jim Lynch
Intro to Unit Testing in AngularJSIntro to Unit Testing in AngularJS
Intro to Unit Testing in AngularJS
Jim Lynch934 views
Unit Testing and Coverage for AngularJS by Knoldus Inc.
Unit Testing and Coverage for AngularJSUnit Testing and Coverage for AngularJS
Unit Testing and Coverage for AngularJS
Knoldus Inc.4.8K views
Test-Driven Development of AngularJS Applications by FITC
Test-Driven Development of AngularJS ApplicationsTest-Driven Development of AngularJS Applications
Test-Driven Development of AngularJS Applications
FITC9.3K views
We Are All Testers Now: The Testing Pyramid and Front-End Development by All Things Open
We Are All Testers Now: The Testing Pyramid and Front-End DevelopmentWe Are All Testers Now: The Testing Pyramid and Front-End Development
We Are All Testers Now: The Testing Pyramid and Front-End Development
All Things Open375 views
RSpec 3.0: Under the Covers by Brian Gesiak
RSpec 3.0: Under the CoversRSpec 3.0: Under the Covers
RSpec 3.0: Under the Covers
Brian Gesiak10.1K views
Angularjs - Unit testing introduction by Nir Kaufman
Angularjs - Unit testing introductionAngularjs - Unit testing introduction
Angularjs - Unit testing introduction
Nir Kaufman9.7K views
JavaScript Test-Driven Development with Jasmine 2.0 and Karma by Christopher Bartling
JavaScript Test-Driven Development with Jasmine 2.0 and Karma JavaScript Test-Driven Development with Jasmine 2.0 and Karma
JavaScript Test-Driven Development with Jasmine 2.0 and Karma
Java EE 6 CDI Integrates with Spring & JSF by Jiayun Zhou
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSF
Jiayun Zhou3.9K views
Bytecode manipulation with Javassist and ASM by ashleypuls
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
ashleypuls7K views
React Native One Day by Troy Miles
React Native One DayReact Native One Day
React Native One Day
Troy Miles910 views
Async task, threads, pools, and executors oh my! by Stacy Devino
Async task, threads, pools, and executors oh my!Async task, threads, pools, and executors oh my!
Async task, threads, pools, and executors oh my!
Stacy Devino2.3K views
Working Effectively With Legacy Code by scidept
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
scidept1.9K views
Node.js vs Play Framework (with Japanese subtitles) by Yevgeniy Brikman
Node.js vs Play Framework (with Japanese subtitles)Node.js vs Play Framework (with Japanese subtitles)
Node.js vs Play Framework (with Japanese subtitles)
Yevgeniy Brikman42.5K views
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016) by Kelly Shuster
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Internal Android Library Management (DroidCon SF 2016, Droidcon Italy 2016)
Kelly Shuster14.3K views
Advanced Dagger talk from 360andev by Mike Nakhimovich
Advanced Dagger talk from 360andevAdvanced Dagger talk from 360andev
Advanced Dagger talk from 360andev
Mike Nakhimovich3.3K views

Similar to When Enterprise Java Micro Profile meets Angular

Java EE, Micro-services, Typescript and Angular 4.x by
Java EE, Micro-services, Typescript and Angular 4.xJava EE, Micro-services, Typescript and Angular 4.x
Java EE, Micro-services, Typescript and Angular 4.xSébastien Pertus
1K views118 slides
Devoxx France 2018 GraphQL vs Traditional REST API by
Devoxx France 2018 GraphQL vs Traditional REST APIDevoxx France 2018 GraphQL vs Traditional REST API
Devoxx France 2018 GraphQL vs Traditional REST APIVladimir Dejanovic
254 views88 slides
The Ultimate Getting Started with Angular Workshop - Devoxx France 2017 by
The Ultimate Getting Started with Angular Workshop - Devoxx France 2017The Ultimate Getting Started with Angular Workshop - Devoxx France 2017
The Ultimate Getting Started with Angular Workshop - Devoxx France 2017Matt Raible
211 views62 slides
10 Useful Asciidoctor Tips by
10 Useful Asciidoctor Tips10 Useful Asciidoctor Tips
10 Useful Asciidoctor TipsAndres Almiray
8.3K views13 slides
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017 by
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017Matt Raible
346 views62 slides
DOC-20230427-WA0010..pptx by
DOC-20230427-WA0010..pptxDOC-20230427-WA0010..pptx
DOC-20230427-WA0010..pptxkumarkaushal17
5 views31 slides

Similar to When Enterprise Java Micro Profile meets Angular(20)

Java EE, Micro-services, Typescript and Angular 4.x by Sébastien Pertus
Java EE, Micro-services, Typescript and Angular 4.xJava EE, Micro-services, Typescript and Angular 4.x
Java EE, Micro-services, Typescript and Angular 4.x
Devoxx France 2018 GraphQL vs Traditional REST API by Vladimir Dejanovic
Devoxx France 2018 GraphQL vs Traditional REST APIDevoxx France 2018 GraphQL vs Traditional REST API
Devoxx France 2018 GraphQL vs Traditional REST API
Vladimir Dejanovic254 views
The Ultimate Getting Started with Angular Workshop - Devoxx France 2017 by Matt Raible
The Ultimate Getting Started with Angular Workshop - Devoxx France 2017The Ultimate Getting Started with Angular Workshop - Devoxx France 2017
The Ultimate Getting Started with Angular Workshop - Devoxx France 2017
Matt Raible211 views
10 Useful Asciidoctor Tips by Andres Almiray
10 Useful Asciidoctor Tips10 Useful Asciidoctor Tips
10 Useful Asciidoctor Tips
Andres Almiray8.3K views
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017 by Matt Raible
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
Matt Raible346 views
JavaScript 2.0 in Dreamweaver CS4 by alexsaves
JavaScript 2.0 in Dreamweaver CS4JavaScript 2.0 in Dreamweaver CS4
JavaScript 2.0 in Dreamweaver CS4
alexsaves2K views
2018 (codeone) Graal VM and MicroProfile a polyglot microservices solution [d... by César Hernández
2018 (codeone) Graal VM and MicroProfile a polyglot microservices solution [d...2018 (codeone) Graal VM and MicroProfile a polyglot microservices solution [d...
2018 (codeone) Graal VM and MicroProfile a polyglot microservices solution [d...
César Hernández204 views
GraalVM and MicroProfile - A Polyglot Microservices Solution by Roberto Cortez
GraalVM and MicroProfile - A Polyglot Microservices SolutionGraalVM and MicroProfile - A Polyglot Microservices Solution
GraalVM and MicroProfile - A Polyglot Microservices Solution
Roberto Cortez986 views
What’s new in Google Dart - Seth Ladd by jaxconf
What’s new in Google Dart - Seth LaddWhat’s new in Google Dart - Seth Ladd
What’s new in Google Dart - Seth Ladd
jaxconf972 views
Why you should be using the shiny new C# 6.0 features now! by Eric Phan
Why you should be using the shiny new C# 6.0 features now!Why you should be using the shiny new C# 6.0 features now!
Why you should be using the shiny new C# 6.0 features now!
Eric Phan298 views
The advantage of developing with TypeScript by Corley S.r.l.
The advantage of developing with TypeScript The advantage of developing with TypeScript
The advantage of developing with TypeScript
Corley S.r.l.1.3K views
DevOps tools for everyone - Vagrant, Puppet and Webmin by postrational
DevOps tools for everyone - Vagrant, Puppet and WebminDevOps tools for everyone - Vagrant, Puppet and Webmin
DevOps tools for everyone - Vagrant, Puppet and Webmin
postrational57K views
Don't Repeat Yourself, Repeat Others by John Nunemaker
Don't Repeat Yourself, Repeat OthersDon't Repeat Yourself, Repeat Others
Don't Repeat Yourself, Repeat Others
John Nunemaker19.5K views
An introduction to Angular2 by Apptension
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
Apptension749 views

Recently uploaded

Top-5-production-devconMunich-2023-v2.pptx by
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptxTier1 app
9 views42 slides
tecnologia18.docx by
tecnologia18.docxtecnologia18.docx
tecnologia18.docxnosi6702
6 views5 slides
Bootstrapping vs Venture Capital.pptx by
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptxZeljko Svedic
16 views17 slides
Transport Management System - Shipment & Container Tracking by
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container TrackingFreightoscope
6 views3 slides
aATP - New Correlation Confirmation Feature.pptx by
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptxEsatEsenek1
222 views6 slides
Chat GPTs by
Chat GPTsChat GPTs
Chat GPTsGene Leybzon
13 views36 slides

Recently uploaded(20)

Top-5-production-devconMunich-2023-v2.pptx by Tier1 app
Top-5-production-devconMunich-2023-v2.pptxTop-5-production-devconMunich-2023-v2.pptx
Top-5-production-devconMunich-2023-v2.pptx
Tier1 app9 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67026 views
Bootstrapping vs Venture Capital.pptx by Zeljko Svedic
Bootstrapping vs Venture Capital.pptxBootstrapping vs Venture Capital.pptx
Bootstrapping vs Venture Capital.pptx
Zeljko Svedic16 views
Transport Management System - Shipment & Container Tracking by Freightoscope
Transport Management System - Shipment & Container TrackingTransport Management System - Shipment & Container Tracking
Transport Management System - Shipment & Container Tracking
Freightoscope 6 views
aATP - New Correlation Confirmation Feature.pptx by EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1222 views
How to build dyanmic dashboards and ensure they always work by Wiiisdom
How to build dyanmic dashboards and ensure they always workHow to build dyanmic dashboards and ensure they always work
How to build dyanmic dashboards and ensure they always work
Wiiisdom16 views
FOSSLight Community Day 2023-11-30 by Shane Coughlan
FOSSLight Community Day 2023-11-30FOSSLight Community Day 2023-11-30
FOSSLight Community Day 2023-11-30
Shane Coughlan8 views
predicting-m3-devopsconMunich-2023-v2.pptx by Tier1 app
predicting-m3-devopsconMunich-2023-v2.pptxpredicting-m3-devopsconMunich-2023-v2.pptx
predicting-m3-devopsconMunich-2023-v2.pptx
Tier1 app14 views
Mobile App Development Company by Richestsoft
Mobile App Development CompanyMobile App Development Company
Mobile App Development Company
Richestsoft 5 views
Quality Engineer: A Day in the Life by John Valentino
Quality Engineer: A Day in the LifeQuality Engineer: A Day in the Life
Quality Engineer: A Day in the Life
John Valentino10 views
Automated Testing of Microsoft Power BI Reports by RTTS
Automated Testing of Microsoft Power BI ReportsAutomated Testing of Microsoft Power BI Reports
Automated Testing of Microsoft Power BI Reports
RTTS11 views
Supercharging your Python Development Environment with VS Code and Dev Contai... by Dawn Wages
Supercharging your Python Development Environment with VS Code and Dev Contai...Supercharging your Python Development Environment with VS Code and Dev Contai...
Supercharging your Python Development Environment with VS Code and Dev Contai...
Dawn Wages5 views
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile... by Stefan Wolpers
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
How To Make Your Plans Suck Less — Maarten Dalmijn at the 57th Hands-on Agile...
Stefan Wolpers44 views
Streamlining Your Business Operations with Enterprise Application Integration... by Flexsin
Streamlining Your Business Operations with Enterprise Application Integration...Streamlining Your Business Operations with Enterprise Application Integration...
Streamlining Your Business Operations with Enterprise Application Integration...
Flexsin 5 views

When Enterprise Java Micro Profile meets Angular

  • 1. #devoxxfr #ngjava @sebastienpertus @agoncal Enterprise Java MicroProfile TypeScript and Angular Sebastien Pertus Antonio Goncalves
  • 2. #devoxxfr #ngjava @sebastienpertus @agoncal Agenda • Enterprise Java MicroProfile • TypeScript • Docker • Angular 2 • Break • Exposing & consuming REST APIs with Angular 2 • Tips and tricks: • APIs, Swagger, Cors, Hateoas, Etag, JWT, Scaling Ask questions
  • 3. #devoxxfr #ngjava @sebastienpertus @agoncal Sebastien Pertus • Microsoft Technical Evangelist • OSS Lover • Full Stack developer • Node.JS & .Net Core advocate • SQL Server man • Develops on Windows (yeah yeah)
  • 4. #devoxxfr #ngjava @sebastienpertus @agoncal Antonio Goncalves • Java Champion • Loves back-end • Hates front-end • Develops on Mac
  • 7. #devoxxfr #ngjava @sebastienpertus @agoncal The Conference App
  • 8. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! The Conference App https://github.com/agoncal/agoncal- application-conference
  • 9. #devoxxfr #ngjava @sebastienpertus @agoncal Optimizing Enterprise Java for a Microservices Architecture
  • 10. #devoxxfr #ngjava @sebastienpertus @agoncal Fundamental Shifts in Computing Cloud Microservices Reduce time to market Address unpredictable loads Pay as you go Containerization Deliver new features more quickly Smaller, more agile teams Deliver business features as discrete services Scale services independently
  • 11. #devoxxfr #ngjava @sebastienpertus @agoncal • Began as a of independent discussions • Many “microservices” efforts exist in Java EE • WildFly Swarm • WebSphere Liberty • Payara • TomEE • New features to address microservices architectures • Java EE already being used for microservices… • ...but we can do better MicroProfile Background
  • 12. #devoxxfr #ngjava @sebastienpertus @agoncal Release Schedule Sep 2016 MicroProfile 1.0 Q4 2016 2017 2017 Move to Foundation MicroProfile 1.1 MicroProfile 1.2 JAX-RS CDI JSON-P
  • 13. #devoxxfr #ngjava @sebastienpertus @agoncal MicroProfile 1.1 Underway Security: JWT Token Exchange Health Check Configuration Fault Tolerance Second Quarter 2017!
  • 15. #devoxxfr #ngjava @sebastienpertus @agoncal WildFly Swarm • Based on good old JBoss AS • « Rightsize your services » • Bundles several fractions • Java EE • Netflix OSS (Ribbon, Hystrix, RxJava) • Spring • Logstash • Swagger • ...
  • 16. #devoxxfr #ngjava @sebastienpertus @agoncal Setting up Swarm and MicroProfile <profile> <id>swarm</id> <dependencies><dependency> <groupId>org.wildfly.swarm</groupId> <artifactId>microprofile</artifactId> </dependency></dependencies> <build> <plugins><plugin> <groupId>org.wildfly.swarm</groupId> <artifactId>wildfly-swarm-plugin</artifactId> </plugin></plugins> </build> </profile>
  • 17. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Skinny War Fat Jar
  • 18. #devoxxfr #ngjava @sebastienpertus @agoncal TypeScript: JavaScript that Scales
  • 19. #devoxxfr #ngjava @sebastienpertus @agoncal BRENDAN EICH ANDERS HEJLSBERG Do you know those guys ? Javascript creator CTO / CEO Mozilla Foundation Brave Software CEO C# creator Technical Fellow @ Microsoft TypeScript creator and lead team
  • 21. #devoxxfr #ngjava @sebastienpertus @agoncal ES6 / EcmaScript 2015 / ES2015 ES6 is the most important update of JavaScript Brendan Eich : - “We want to go faster. “ - “Every year, a new spec that will be shipped in nighty versions of moderns browsers”
  • 22. #devoxxfr #ngjava @sebastienpertus @agoncal Ecmascript evolution ES 8 ES 7 (ES 2016) ES 6 (ES 2015) ES 5 ES 3 Core features 1997 ~~ 1999 new functions strict mode, json 2009 class, promises, generators, arrow functions, new syntax and concepts … 2015 Exponential (**), array.includes, 2016
  • 23. #devoxxfr #ngjava @sebastienpertus @agoncal Rise of the transpilers: Typescript 2.0
  • 24. #devoxxfr #ngjava @sebastienpertus @agoncal TRANSPILER COMPILER Transpiler vs Compiler is a specific term for taking source code written in one language and transforming into another language that has a similar level of abstraction TypeScript (subclass of JavaScript) to JavaScript is the general term for taking source code written in one language and transforming into another C# to IL Java to ByteCode "CoffeeScript is to Ruby as TypeScript is to Java/C#/C++." - Luke Hoban Reference : Steve Fenton – 2012 - https://www.stevefenton.co.uk/2012/11/compiling-vs-transpiling
  • 25. #devoxxfr #ngjava @sebastienpertus @agoncal A statically typed superset of JavaScript that compiles to plain JavaScript. Oh wait … that transpiles 
  • 26. B R O W S E R H O S T O S
  • 27. #devoxxfr #ngjava @sebastienpertus @agoncal Open Source
  • 29. #devoxxfr #ngjava @sebastienpertus @agoncal The feature gap
  • 30. #devoxxfr #ngjava @sebastienpertus @agoncal TypeScript IDE
  • 31. #devoxxfr #ngjava @sebastienpertus @agoncal One year, four releases 1.5 1.6 1.7 1.8
  • 32. #devoxxfr #ngjava @sebastienpertus @agoncal TypeScript 2.0 • Control flow based type analysis • Non-nullable types • Async/await downlevel support • Readonly properties • Private and protected Constructor • Type “never”
  • 33. #devoxxfr #ngjava @sebastienpertus @agoncal TypeScript 2.1, 2.2 • New JS language service in Visual Studio • Better and more refactoring support • Extensions methods • Mixin classes • Better .jsx react native support
  • 34. #devoxxfr #ngjava @sebastienpertus @agoncal Nullable types number string boolean
  • 35. #devoxxfr #ngjava @sebastienpertus @agoncal Non-nullable types number string boolean
  • 36. #devoxxfr #ngjava @sebastienpertus @agoncal Non-nullable types number string boolean undefined null
  • 37. #devoxxfr #ngjava @sebastienpertus @agoncal Non-nullable types string undefined null string | null | undefined
  • 38. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Non Nullables Types Control Flow Async / await
  • 40. #devoxxfr #ngjava @sebastienpertus @agoncal Docker • « Build, Ship, Run » • Containers, containers, containers • Docker to run containers • Docker-compose to compose several containers • WildFly containers • JRE container
  • 41. #devoxxfr #ngjava @sebastienpertus @agoncal Dockerfile Skinny War FROM jboss/wildfly:10.1.0.Final EXPOSE 8080 # Setting the Wildfly Admin console (user/pwd admin/admin) RUN $JBOSS_HOME/bin/add-user.sh admin admin --silent CMD $JBOSS_HOME/bin/standalone.sh -b 0.0.0.0 -bmanagement 0.0.0.0 COPY venue.war $JBOSS_HOME/standalone/deployments/
  • 42. #devoxxfr #ngjava @sebastienpertus @agoncal Dockerfile Far Jar FROM openjdk:8-jre-alpine EXPOSE 8080 COPY venue-swarm.jar /opt/venue-swarm.jar ENTRYPOINT ["java", "-jar", "/opt/venue-swarm.jar"]
  • 43. #devoxxfr #ngjava @sebastienpertus @agoncal Dockerfile Angular Distribution FROM nginx EXPOSE 80 COPY ./dist /usr/share/nginx/html
  • 44. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Skinny War Image Fat Jar Image
  • 47. #devoxxfr #ngjava @sebastienpertus @agoncal Angular : In a nutshell Modules Components Services
  • 48. #devoxxfr #ngjava @sebastienpertus @agoncal Angular Component
  • 49. #devoxxfr #ngjava @sebastienpertus @agoncal Angular Module
  • 50. #devoxxfr #ngjava @sebastienpertus @agoncal Angular Dependency Injection
  • 51. #devoxxfr #ngjava @sebastienpertus @agoncal Angular & Webpack
  • 52. #devoxxfr #ngjava @sebastienpertus @agoncal ES7 THEN ES8 PROPOSAL ALREADY IMPLEMENTED IN TS Decorators Pattern that allow us to extend / modify the behavior of a class / function / propery As you can see …. It’s used A LOT in Angular 2
  • 53. #devoxxfr #ngjava @sebastienpertus @agoncal Decorators class Person { public lastName: string; public firstName: string; constructor(ln: string, fn: string) { this.lastName = ln; this.firstName = fn; } @log(false) public getFullName(fnFirst: boolean = true) { if (fnFirst) return this.firstName + " " + this.lastName; else return this.lastName + " " + this.firstName; } }
  • 54. #devoxxfr #ngjava @sebastienpertus @agoncal Decorators function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { var desc = { value: function (...args: any[]) { // get the params var params = args.map(arg => JSON.stringify(arg)).join(); // get the result var result = descriptor.value.apply(this, args); var resultString = JSON.stringify(result); console.log(`function ${propertyKey} invoked. Params: ${params}. Result: ${resultString}`); return result; } } return desc; }
  • 55. #devoxxfr #ngjava @sebastienpertus @agoncal Angular CLI Angular Command Line Interface
  • 56. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Angular CLI - Component - Service
  • 57. #devoxxfr #ngjava @sebastienpertus @agoncal Agenda • Enterprise Java MicroProfile • TypeScript • Docker • Angular 2 • Break • Exposing & consuming REST APIs with Angular 2 • Tips and tricks: • APIs, Swagger, Cors, Hateoas, Etag, JWT, Scaling Ask questions
  • 59. #devoxxfr #ngjava @sebastienpertus @agoncal Exposing REST Endpoints
  • 60. #devoxxfr #ngjava @sebastienpertus @agoncal Conference Micro Services
  • 61. #devoxxfr #ngjava @sebastienpertus @agoncal Exposing « beautiful » APIs • JSon:API • OData • Jsend • HAL • CPHL • SIREN • Google’s JSon Style Guide • Do it your own
  • 62. #devoxxfr #ngjava @sebastienpertus @agoncal « Kind of » JSon:API GET http://host/schedule/api/sessions GET http://host/schedule/api/sessions?page=2 GET http://host/schedule/api/sessions?sort=title GET http://host/schedule/api/sessions?sort=-title,date POST http://host/schedule/api/sessions GET http://host/schedule/api/sessions/abcd REMOVE http://host/schedule/api/sessions/abcd GET http://host/speaker/api/speakers/abcd GET http://host/speaker/api/speakers/abcd?expand=false
  • 64. #devoxxfr #ngjava @sebastienpertus @agoncal Swagger • Simple yet powerful representation of your RESTful API • API documentation • What do you call? • What are the parameters? • What are the status code? • Contract written in JSon (or Yaml) • Donated to the Open API Initiative
  • 65. #devoxxfr #ngjava @sebastienpertus @agoncal Swagger’s ecosystem
  • 66. #devoxxfr #ngjava @sebastienpertus @agoncal Swagger APIs @Path("/speakers") @Api(description = "Speakers REST Endpoint") public class SpeakerEndpoint { @POST @ApiOperation(value = "Adds a new speaker to the conference") @ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid input")}) public Response add(@NotNull Speaker speaker) { ... } @GET @Path("/{id}") @ApiOperation(value = "Finds a speaker by ID") public Response retrieve(@PathParam("id") String id) { ... } }
  • 67. #devoxxfr #ngjava @sebastienpertus @agoncal Swagger Maven Plugin <plugin> <groupId>com.github.kongchen</groupId> <artifactId>swagger-maven-plugin</artifactId> <configuration> <apiSources><apiSource> <locations>org.agoncal.conference.venue.rest</locations> <schemes>http,https</schemes> <host>localhost:8080</host> <basePath>/api</basePath> <info> <title>Room</title> <version>1.0.0</version> <description>Rooms of the venue</description> </info>
  • 69. #devoxxfr #ngjava @sebastienpertus @agoncal Swagger TypeScript for Angular generation public add(room: models.Room): Observable<{}> { return this.http.request(path, requestOptions) .map((response: Response) => { … }); } public retrieve(id: string, extraHttpRequestParams?: any): Observable<models.Room> { return this.http.request(path, requestOptions) .map((response: Response) => { … }); }
  • 70. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Generate Angular from Swagger
  • 73. #devoxxfr #ngjava @sebastienpertus @agoncal CORS • Cross-Origin Resource Sharing • Specification (https://www.w3.org/TR/cors/) • Access across domain-boundaries • JavaScript and web programming has grown • But the same-origin policy still remains • Prevents JavaScript from making requests across domain boundaries
  • 74. #devoxxfr #ngjava @sebastienpertus @agoncal HTTP Header Access-Control-Allow-Origin Access-Control-Allow-Credentials Access-Control-Expose-Headers Access-Control-Max-Age Access-Control-Allow-Methods Access-Control-Allow-Headers Access-Control-Request-Method Access-Control-Request-Headers
  • 75. #devoxxfr #ngjava @sebastienpertus @agoncal CORS @Provider public class CORSFilter implements ContainerResponseFilter { public void filter(ContainerRequestContext request, ContainerResponseContext response) throws IOException { response.getHeaders().add("Access-Control-Allow-Origin", "*"); response.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization, Etag"); response.getHeaders().add("Access-Control-Allow-Credentials", "true"); response.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD"); } }
  • 76. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time !
  • 78. #devoxxfr #ngjava @sebastienpertus @agoncal HateOAS • « Hypermedia as the engine of application state » • At its core is the concept of « hypermedia » • Or in other words: the idea of links • Client application goes from one state to the next by following a link • Runtime contract • Nothing in Java EE, maybe in MicroProfile • JAX-RS has a Link API
  • 79. #devoxxfr #ngjava @sebastienpertus @agoncal Links links: { self: "http://host/schedule/api/sessions?page=1", first: "http://host/schedule/api/sessions?page=1", last: "http://host/schedule/api/sessions?page=14", next: "http://host/schedule/api/sessions?page=2", monday: "http://host/schedule/api/sessions/monday", tuesday: "http://host/schedule/api/sessions/tuesday" }, data: [ { links: { self: "http://host/schedule/api/sessions/uni_room9_tuesd" }, id: "uni_room9_tuesday_8_9h30_12h30", title: ”Java EE and Angular 2",
  • 80. #devoxxfr #ngjava @sebastienpertus @agoncal http://www.iana.org/assignments/link-relations/link-relations.xml
  • 81. #devoxxfr #ngjava @sebastienpertus @agoncal Links @XmlType(name = "links") public abstract class LinkableResource implements Identifiable { private Map<String, URI> links; public void addSelfLink(URI uri) { addLink(SELF, uri); } public void addCollectionLink(URI uri) { addLink(COLLECTION, uri); } }
  • 82. #devoxxfr #ngjava @sebastienpertus @agoncal Links if (body.links) { this.links = {}; for (let key in body.links) { this.links[key] = body.links[key] !== undefined ? body.links[key] : null; } }
  • 83. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! HateOAS
  • 85. #devoxxfr #ngjava @sebastienpertus @agoncal Caching • HTTP has temporary storage (caching) • Reduce bandwidth usage • Reduce server load • Reduce perceived lag • ETags, or entity-tags: "conditional" requests. • Checksum • If-None-Match
  • 86. #devoxxfr #ngjava @sebastienpertus @agoncal Etag Generation @GET @Path("/{id}") public Response retrieve(@PathParam("id") String id, @Context Request request) { Talk talk = talkRepository.findById(id); EntityTag etag = new EntityTag(talk.hashCode()); Response.ResponseBuilder preconditions = request.evaluatePreconditions(etag); if (preconditions == null) { preconditions = Response.ok(talk).tag(etag); } return preconditions.build(); }
  • 88. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! ETag & caching
  • 90. #devoxxfr #ngjava @sebastienpertus @agoncal JSon Web Token • Lightweigh token • Contains « some » data (claims) • Base64 • Encrypted • Passed in the HTTP Header • Sent at each request • Not in Java EE nor Microprofile (yet) • Many librairies
  • 91. #devoxxfr #ngjava @sebastienpertus @agoncal A Token Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZ29uY2FsIiwiaXNzIjoi aHR0cDovL2NvbmZlcmVuY2UuZG9ja2VyLmxvY2FsaG9zd Do5MC9jb25mZXJlbmNlLWF0dGVuZGVlL2FwaS9hdHRlbm RlZXMvbG9naW4iLCJpYXQiOjE0Nzc0OTk3NTUsImV4cCI6 MTQ3NzUwMDY1NX0.aL0a_q5wC3cesBKhkXChg30zr3W WOsYhFhpJ0lQ479LtLjrPvTQiDH0N_YnFuARuEuy299S4u O0yXGmX0tSs-Q
  • 92. #devoxxfr #ngjava @sebastienpertus @agoncal A Token Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZ29uY2FsIiwiaXNzIjoi aHR0cDovL2NvbmZlcmVuY2UuZG9ja2VyLmxvY2FsaG9zd Do5MC9jb25mZXJlbmNlLWF0dGVuZGVlL2FwaS9hdHRlbm RlZXMvbG9naW4iLCJpYXQiOjE0Nzc0OTk3NTUsImV4cCI6 MTQ3NzUwMDY1NX0.aL0a_q5wC3cesBKhkXChg30zr3W WOsYhFhpJ0lQ479LtLjrPvTQiDH0N_YnFuARuEuy299S4u O0yXGmX0tSs-Q
  • 93. #devoxxfr #ngjava @sebastienpertus @agoncal A Token HEADER: { "alg": "HS512" } PAYLOAD:{ "sub": "agoncal", "iss": "http://host/attendee/api/login", "iat": 1477499755, "exp": 1477500655 } VERIFY SIGNATURE HMACSHA256(...)
  • 94. #devoxxfr #ngjava @sebastienpertus @agoncal JWT Generation @Path("/attendees") public class AttendeeEndpoint { @POST @Path("/login") @Consumes(APPLICATION_FORM_URLENCODED) public Response auth(@FormParam("login") String login, @FormParam("password") String password) { // Authentication, security exception and so on... return Response.ok().header(AUTHORIZATION, "Bearer " + issueToken(login)).build(); } }
  • 95. #devoxxfr #ngjava @sebastienpertus @agoncal Filter to Check the Token @JWTTokenNeeded @Provider @Priority(Priorities.AUTHENTICATION) public class JWTTokenNeededFilter implements ContainerRequestFilter{ public void filter(ContainerRequestContext ctx) { String auth = ctx.getHeaderString(HttpHeaders.AUTHORIZATION); if (auth == null || !authorizationHeader.startsWith("Bearer")) { throw new NotAuthorizedException("No Bearer"); } String token = auth.substring("Bearer".length()).trim(); Jwts.parser().setSigningKey(key).parseClaimsJws(token); } }
  • 96. #devoxxfr #ngjava @sebastienpertus @agoncal Check the Token @Path("/ratings") public class RatingEndpoint { @JWTTokenNeeded @POST public Response rate(...) { } @GET public Response retrieve(...) { } }
  • 97. #devoxxfr #ngjava @sebastienpertus @agoncal JWT Consumption return this.http .post(this.basePath, body, requestOptions) .map((response: Response) => { if (response.status !== 200) { return undefined; } this.jwt = response.headers.get('authorization'); if (!this.jwt) return undefined; return this.jwt; }) .catch((error: any) => { return undefined });
  • 98. #devoxxfr #ngjava @sebastienpertus @agoncal @Injectable() export class AuthGuardService implements CanActivate { constructor(private authService: AuthService, private router: Router) { } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { let url: string = state.url; return this.checkLogin(url); } checkLogin(url: string): boolean { if (this.authService.isLoggedIn) { return true; } this.router.navigate(['/login'], { queryParams: { redirectTo: url } }); return false; } }
  • 99. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Passing a token around
  • 101. #devoxxfr #ngjava @sebastienpertus @agoncal Scaling • Stateless architecture • No cookie • No HTTP session • No local cache • Stateless scales better than statefull • Clients can round robin • Dynamic proxy • Meet Traeffik
  • 104. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Traeffik
  • 106. #devoxxfr #ngjava @sebastienpertus @agoncal Going in production with Angular • By default, Angular (in dev mode) is about … 4 mb ! • Angular cli and webpack will: • Uglify your JavaScript code • Create a standalone bundle file • Gzip compress • Apply a tree shaking to delete unused code (it’s not dead code, btw !) • Could use AOT compilation
  • 107. #devoxxfr #ngjava @sebastienpertus @agoncal JIT vs AOT Compilation Source Code JIT Compilation Code Generation VM execution Source Code AOT Compilation Code Generation VM execution BUILD RUN
  • 108. #devoxxfr #ngjava @sebastienpertus @agoncal With AOT, AN Angular project could be 60 – 70 % less code http://slides.com/wassimchegham/demystifying-ahead-of-time-compilation-in-angular-2-aot-jit#/32
  • 109. #devoxxfr #ngjava @sebastienpertus @agoncal Demo Time ! Angular Production ready
  • 110. #devoxxfr #ngjava @sebastienpertus @agoncal Conclusion • MicroProfile 1.1 will bring more MicroServices features • Configuration • Security: JWT Token Exchange • Health Check • Fault Tolerance • More to come
  • 112. #devoxxfr #ngjava @sebastienpertus @agoncal Conclusion • Angular 4 • Native Script • TypeScript 2.x
  • 119. #devoxxfr #ngjava @sebastienpertus @agoncal Enterprise Java MicroProfile TypeScript and Angular Sebastien Pertus Antonio Goncalves https://github.com/agoncal/agoncal-application-conference

Editor's Notes

  1. While the industry was delivering Java EE 7 and planning Java EE 8, some fundamental shifts were occurring during this time. The first was the growth of cloud computing. Driven by Amazon early on, the primary benefit was the ability to deliver features to market more quickly by offloading the infrastructure to a 3rd party, combined with the ability to scale up and down as needed and paying for only the compute power that is utilized. More recently, containerization is becoming much more popular thanks to Docker. While there are many benefits to containers, the most interesting is that it brings the value proposition of Java’s WORA (Write Once Run Anywhere) to the cloud. Applications/services packaged in docker containers can run in any cloud that supports containers. Developers saw these changes infrastructure changes occuring in the cloud, and for disruptive organizations like NetFlix for example, began to re-architect their services with the cloud in mind. The goal was to deliver features into production more quickly, and the means to do so was to break up “slow moving monoliths” to fine grained and fast moving services that individually solve a specific business domain problems. This is known as microservices today.
  2. This is a calendar that is mean to define important milestones and intent. MicroProfile was released in September of 2016 and is currently being moved into the Eclipse Foundation. After that the intent is to have multiple releases per year.
  3. MicroProfile 1.1 is underway, and scheduled for the 2nd quarter of 2017. The community has decided to focus this release on Configuration, Security (JWT Token Exchange), Health Check, and Fault Tolerance. Configuration: Separates (externalizes) a microservice from its configuration. Health Check: Specifies a REST endpoint with service health information. Enables cloud infrastructure to detect the health of a service. If a service is unhealthy, a cloud runtime can restart (or fail and re-create) a service instance Fault Tolerance: APIs that cover popular microservice programming patterns, including Fallback, Circuit Breakers, and Bulkheads
  4. Quand vous compilez du TypeScript, vous transformez votre code en JavaScript. Comme TypeScript est trés proche de JavaScript (ES6+), vous pouvez dire que vous Transpillez.