SlideShare a Scribd company logo
ARCHITECTURE

Dienstag, 11. Februar 14
FROM PRESENTATION TO
SERVICE LAYER

Dienstag, 11. Februar 14
OLD STYLE PRESENTATION LAYER
Server

Browser

GET /index.html HTTP/1.1

200/OK (HTML)
GET /contacts-table.html HTTP/1.1

render
markup

200/OK (HTML)
POST /servlet/contacts HTTP/1.1

200/OK (HTML)

Dienstag, 11. Februar 14

render
markup
DATA CENTRIC SERVICE LAYER
Browser

Server

GET /index.html HTTP/1.1

200/OK (HTML)

GET /api/contacts HTTP/1.1
render
markup

200/OK (JSON)

PUT /api/contacts/12 HTTP/1.1
render
markup

Dienstag, 11. Februar 14

200/OK (JSON)
WHERE ARE WE HEADING TO ?
Browser

Server

GET /index.html HTTP/1.1

200/OK (HTML)
GET /contacts-table.html HTTP/1.1

200/OK (HTML)

ts !
cke
o

ws://future.now/ws

S

eb
W

render
markup

Dienstag, 11. Februar 14

PUT /api/contacts/12 HTTP/1.1

200/OK (JSON)

render
markup
REST AND CRUD

Dienstag, 11. Februar 14
JAX-RS
@GET
@Produces("application/json")
public Collection<ToDo> getAll() throws ServiceException {
...
}
@GET
@Path("/{uuid}")
@Produces("application/json")
public ToDo get(@PathParam("uuid")String id) throws
ServiceException {
...
}
@PUT
@Consumes("application/json")
@Produces("application/json")
public ToDo createToDo(ToDo toDo) throws ServiceException {
...
}
Dienstag, 11. Februar 14
CORS
CROSS ORIGIN RESOURCE SHARING

Dienstag, 11. Februar 14
PREFLIGHT REQUEST
curl -X OPTIONS --verbose --insecure https://localhost:8181/baas/api/todo
> OPTIONS /baas/api/todo HTTP/1.1
...
< HTTP/1.1 200 OK
< X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2
Java/Apple Inc./1.6)
< Server: GlassFish Server Open Source Edition 3.1.2.2
< Allow: OPTIONS,GET,HEAD,PUT
< Last-modified: Do, 15 Aug 2013 00:26:54 MESZ
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE
< Access-Control-Allow-Headers: content-type,authorization,x-requested-with
< Access-Control-Max-Age: 1728000
< Content-Type: application/vnd.sun.wadl+xml
< Content-Length: 1642
< Date: Wed, 14 Aug 2013 22:44:55 GMT
<
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
...
</application>

Dienstag, 11. Februar 14
CORS
Browser

Server of origin

Service provider

GET /index.html HTTP/1.1

200/OK (HTML)

!
est
qu

pr

ht re
eflig

OPTIONS /api/contacts HTTP/1.1

200/OK (WADL)

GET /api/contacts HTTP/1.1
render
markup

Dienstag, 11. Februar 14

200/OK (JSON)
SETTING CORS HEADERS
JEE WebFilter (Glassfish 4.0)
@WebFilter(filterName = "CorsFilter", urlPatterns = {"/*"})
public class CorsFilter implements Filter {
private void doBeforeProcessing(ServletRequest request, ServletResponse response)
throws IOException, ServletException {
final HttpServletResponse httpResponse = (HttpServletResponse)response;
httpResponse.addHeader("Access-Control-Allow-Origin", "*");
httpResponse.addHeader("Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS");
httpResponse.addHeader("Access-Control-Allow-Headers",
"x-requested-with, accept, origin, authorization");
httpResponse.addHeader("Access-Control-Max-Age", "1728000");

}

}
... // netbeans default Filter pattern

Dienstag, 11. Februar 14
CORS
curl -X OPTIONS --verbose --insecure https://localhost:8181/baas/api/todo
< HTTP/1.1 200 OK
< X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2
Java/Apple Inc./1.6)
< Server: GlassFish Server Open Source Edition 3.1.2.2
< Allow: OPTIONS,GET,HEAD,PUT
< Last-modified: Do, 15 Aug 2013 00:26:54 MESZ
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE
< Access-Control-Allow-Headers: content-type,authorization,x-requested-with
< Access-Control-Max-Age: 1728000
< Content-Type: application/vnd.sun.wadl+xml
< Content-Length: 1642
< Date: Wed, 14 Aug 2013 22:44:55 GMT
<
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
...
</application>

Dienstag, 11. Februar 14
WADL
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
<resources base="https://localhost:8181/baas/api/">
<resource path="todo">
<method id="createToDo" name="PUT">
<request>
<representation mediaType="application/json"/>
</request>
<response>
<representation mediaType="application/json"/>
</response>
</method>
...
</resource>
</resources>
</application>

Dienstag, 11. Februar 14
AUTHENTICATION

Dienstag, 11. Februar 14
WEB.XML
<security-constraint>
<display-name>REST API</display-name>
<web-resource-collection>
<web-resource-name>web-api</web-resource-name>
<url-pattern>/api/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>PUT</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
<user-data-constraint>
S
<transport-guarantee>CONFIDENTIAL</transport-guarantee> HTTP
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method> uth
a
<realm-name>file</realm-name>basic
</login-config>
<security-role>
<role-name>user</role-name>
</security-role>
Dienstag, 11. Februar 14
HTTPS AND BASIC AUTH
• + easy to implement
• - password is sent on every request
• (- browser stores credentials for session)
• (- browser may store creds permanently)
• corporate proxies
• not for really sensitive data
Dienstag, 11. Februar 14
BASIC AUTHENTICATION
curl -X GET --verbose --insecure https://localhost:8181/baas/api/todo
> GET /baas/api/todo HTTP/1.1
...
<
<
<
<
<
<
<
<
<
<
<

HTTP/1.1 401 Unauthorized
X-Powered-By: Servlet/3.0 JSP/2.2 [...]
Server: GlassFish Server Open Source Edition 3.1.2.2
Pragma: No-cache
Cache-Control: no-cache
Expires: Thu, 01 Jan 1970 01:00:00 CET
WWW-Authenticate: Basic realm="file"
Content-Type: text/html
Content-Length: 1073
Date: Wed, 14 Aug 2013 23:33:48 GMT

Dienstag, 11. Februar 14
BASIC AUTHENTICATION

curl -X GET --verbose --insecure -u marc:geheim https://localhost:8181/baas/api/todo
>
>
>
>
>
>

GET /baas/api/todo HTTP/1.1
Authorization: Basic bWFyYzpnZWhlaW0=
User-Agent: ...
Host: localhost:8181
Accept: */*

< HTTP/1.1 200 OK

Dienstag, 11. Februar 14
EXERCISES

ecture/baas-gf
~/ws/05-Archit
~/ws/05-Architecture/jquery-rest
Dienstag, 11. Februar 14
HTTPS AND FORM AUTH
• auth method form in web.xml
• credential sent only once (+)
• SSO (+)
• corporate proxies (-)
Dienstag, 11. Februar 14
SETTING CORS HEADERS
Jersey (eg. Jersey/Tomcat)
public class CrossOriginResourceSharingFilter
implements ContainerResponseFilter {
@Override
public ContainerResponse filter(
ContainerRequest request, ContainerResponse response) {

}

}

Dienstag, 11. Februar 14

response.getHttpHeaders().putSingle(
"Access-Control-Allow-Origin", "*");
response.getHttpHeaders().putSingle(
"Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE");
response.getHttpHeaders().putSingle(
"Access-Control-Allow-Headers",
"content-type,authorization,x-requested-with");
response.getHttpHeaders().putSingle(
"Access-Control-Max-Age",
"3600");
return response;

More Related Content

PDF
Play Framework
ODP
Implementing Early Hints in Chrome - Approaches and Challenges
PPTX
Node.js Socket.IO
PPT
Making the secure communication between Server and Client with https protocol
PPT
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
PPTX
The Atmosphere Framework
PDF
Config websocket on apache
PPTX
Building WebSocket and Server Side Events Applications using Atmosphere
Play Framework
Implementing Early Hints in Chrome - Approaches and Challenges
Node.js Socket.IO
Making the secure communication between Server and Client with https protocol
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
The Atmosphere Framework
Config websocket on apache
Building WebSocket and Server Side Events Applications using Atmosphere

What's hot (20)

PDF
WSO2 Italia Open Break Session #2 - Microgateway
PPTX
Websockets on the JVM: Atmosphere to the rescue!
KEY
Dancing with websocket
PDF
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
PPTX
Web sockets
PPTX
Cache is king
PPTX
Cache is the king
PPTX
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
DOCX
Configuring Outbound SSL connection to invoke secured REST
PDF
WebSockets - Today, in the Past, in Future and in Production.
PDF
Building Real-Time Applications with Android and WebSockets
PPT
Presentation (PPT)
KEY
Node worshop Realtime - Socket.io
PPTX
Solving anything in VCL
PPTX
Android and REST
PDF
Getting Started with WebSockets and Server-Sent Events
PDF
Getting Started with WebSocket and Server-Sent Events in Java
PPTX
Spring + WebSocket integration
PDF
Service worker: discover the next web game changer
PDF
Pandora FMS: Sun One webserver
WSO2 Italia Open Break Session #2 - Microgateway
Websockets on the JVM: Atmosphere to the rescue!
Dancing with websocket
JDD 2017: Nginx + Lua = OpenResty (Marcin Stożek)
Web sockets
Cache is king
Cache is the king
Web rtc, Media stream, Peer connection, Setting up STUN and TURN on Linux and...
Configuring Outbound SSL connection to invoke secured REST
WebSockets - Today, in the Past, in Future and in Production.
Building Real-Time Applications with Android and WebSockets
Presentation (PPT)
Node worshop Realtime - Socket.io
Solving anything in VCL
Android and REST
Getting Started with WebSockets and Server-Sent Events
Getting Started with WebSocket and Server-Sent Events in Java
Spring + WebSocket integration
Service worker: discover the next web game changer
Pandora FMS: Sun One webserver
Ad

Viewers also liked (14)

ODP
p2p
PDF
Hadoop map reduce data flow
PDF
Map reduce
PPTX
Statistical Significance | Statistics
PPTX
FTP Client and Server | Computer Science
PPTX
Ad hoc networks
PPT
Networking
PPTX
Client server architecture
PDF
Lecture 5 6 .ad hoc network
PPT
Density Function | Statistics
PPTX
Client server architecture
PPTX
Ad-Hoc Networks
PPTX
Mobile Ad hoc Networks
PPTX
Introduction to computer network
p2p
Hadoop map reduce data flow
Map reduce
Statistical Significance | Statistics
FTP Client and Server | Computer Science
Ad hoc networks
Networking
Client server architecture
Lecture 5 6 .ad hoc network
Density Function | Statistics
Client server architecture
Ad-Hoc Networks
Mobile Ad hoc Networks
Introduction to computer network
Ad

Similar to Modern web application network architecture (14)

PDF
Pragmatic REST aka praxisnahes Schnittstellendesign
PDF
Consumer-centric API Design
PDF
Agile RESTful Web Development
PDF
Android App Development 06 : Network &amp; Web Services
PDF
Rest api titouan benoit
KEY
I got 99 problems, but ReST ain't one
PDF
Jersey
PDF
Consumer-Centric API Design
PDF
Doing REST Right
PDF
Building RESTful applications using Spring MVC
PDF
RefCard RESTful API Design
PPTX
PPTX
RESTful Web Services
PPTX
RESTful modules in zf2
Pragmatic REST aka praxisnahes Schnittstellendesign
Consumer-centric API Design
Agile RESTful Web Development
Android App Development 06 : Network &amp; Web Services
Rest api titouan benoit
I got 99 problems, but ReST ain't one
Jersey
Consumer-Centric API Design
Doing REST Right
Building RESTful applications using Spring MVC
RefCard RESTful API Design
RESTful Web Services
RESTful modules in zf2

More from Marc Bächinger (9)

PDF
Introduction to web components
PDF
High-Quality JavaScript
PDF
HTML5 unplugged
PDF
JavaScript toolchain
PDF
JQuery primer
PDF
With your bare hands
PDF
Architecting non-trivial browser applications (Jazoon 2012)
ODP
Jax-rs-js Tutorial
PPTX
Html5 communication
Introduction to web components
High-Quality JavaScript
HTML5 unplugged
JavaScript toolchain
JQuery primer
With your bare hands
Architecting non-trivial browser applications (Jazoon 2012)
Jax-rs-js Tutorial
Html5 communication

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Mushroom cultivation and it's methods.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Encapsulation theory and applications.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Tartificialntelligence_presentation.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
August Patch Tuesday
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Encapsulation_ Review paper, used for researhc scholars
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Mushroom cultivation and it's methods.pdf
TLE Review Electricity (Electricity).pptx
Programs and apps: productivity, graphics, security and other tools
A comparative analysis of optical character recognition models for extracting...
Encapsulation theory and applications.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectroscopy.pptx food analysis technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Tartificialntelligence_presentation.pptx
Network Security Unit 5.pdf for BCA BBA.
August Patch Tuesday
OMC Textile Division Presentation 2021.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
cloud_computing_Infrastucture_as_cloud_p
Encapsulation_ Review paper, used for researhc scholars

Modern web application network architecture

  • 2. FROM PRESENTATION TO SERVICE LAYER Dienstag, 11. Februar 14
  • 3. OLD STYLE PRESENTATION LAYER Server Browser GET /index.html HTTP/1.1 200/OK (HTML) GET /contacts-table.html HTTP/1.1 render markup 200/OK (HTML) POST /servlet/contacts HTTP/1.1 200/OK (HTML) Dienstag, 11. Februar 14 render markup
  • 4. DATA CENTRIC SERVICE LAYER Browser Server GET /index.html HTTP/1.1 200/OK (HTML) GET /api/contacts HTTP/1.1 render markup 200/OK (JSON) PUT /api/contacts/12 HTTP/1.1 render markup Dienstag, 11. Februar 14 200/OK (JSON)
  • 5. WHERE ARE WE HEADING TO ? Browser Server GET /index.html HTTP/1.1 200/OK (HTML) GET /contacts-table.html HTTP/1.1 200/OK (HTML) ts ! cke o ws://future.now/ws S eb W render markup Dienstag, 11. Februar 14 PUT /api/contacts/12 HTTP/1.1 200/OK (JSON) render markup
  • 6. REST AND CRUD Dienstag, 11. Februar 14
  • 7. JAX-RS @GET @Produces("application/json") public Collection<ToDo> getAll() throws ServiceException { ... } @GET @Path("/{uuid}") @Produces("application/json") public ToDo get(@PathParam("uuid")String id) throws ServiceException { ... } @PUT @Consumes("application/json") @Produces("application/json") public ToDo createToDo(ToDo toDo) throws ServiceException { ... } Dienstag, 11. Februar 14
  • 8. CORS CROSS ORIGIN RESOURCE SHARING Dienstag, 11. Februar 14
  • 9. PREFLIGHT REQUEST curl -X OPTIONS --verbose --insecure https://localhost:8181/baas/api/todo > OPTIONS /baas/api/todo HTTP/1.1 ... < HTTP/1.1 200 OK < X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Apple Inc./1.6) < Server: GlassFish Server Open Source Edition 3.1.2.2 < Allow: OPTIONS,GET,HEAD,PUT < Last-modified: Do, 15 Aug 2013 00:26:54 MESZ < Access-Control-Allow-Origin: * < Access-Control-Allow-Methods: GET, POST, PUT, DELETE < Access-Control-Allow-Headers: content-type,authorization,x-requested-with < Access-Control-Max-Age: 1728000 < Content-Type: application/vnd.sun.wadl+xml < Content-Length: 1642 < Date: Wed, 14 Aug 2013 22:44:55 GMT < <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <application xmlns="http://wadl.dev.java.net/2009/02"> ... </application> Dienstag, 11. Februar 14
  • 10. CORS Browser Server of origin Service provider GET /index.html HTTP/1.1 200/OK (HTML) ! est qu pr ht re eflig OPTIONS /api/contacts HTTP/1.1 200/OK (WADL) GET /api/contacts HTTP/1.1 render markup Dienstag, 11. Februar 14 200/OK (JSON)
  • 11. SETTING CORS HEADERS JEE WebFilter (Glassfish 4.0) @WebFilter(filterName = "CorsFilter", urlPatterns = {"/*"}) public class CorsFilter implements Filter { private void doBeforeProcessing(ServletRequest request, ServletResponse response) throws IOException, ServletException { final HttpServletResponse httpResponse = (HttpServletResponse)response; httpResponse.addHeader("Access-Control-Allow-Origin", "*"); httpResponse.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); httpResponse.addHeader("Access-Control-Allow-Headers", "x-requested-with, accept, origin, authorization"); httpResponse.addHeader("Access-Control-Max-Age", "1728000"); } } ... // netbeans default Filter pattern Dienstag, 11. Februar 14
  • 12. CORS curl -X OPTIONS --verbose --insecure https://localhost:8181/baas/api/todo < HTTP/1.1 200 OK < X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Apple Inc./1.6) < Server: GlassFish Server Open Source Edition 3.1.2.2 < Allow: OPTIONS,GET,HEAD,PUT < Last-modified: Do, 15 Aug 2013 00:26:54 MESZ < Access-Control-Allow-Origin: * < Access-Control-Allow-Methods: GET, POST, PUT, DELETE < Access-Control-Allow-Headers: content-type,authorization,x-requested-with < Access-Control-Max-Age: 1728000 < Content-Type: application/vnd.sun.wadl+xml < Content-Length: 1642 < Date: Wed, 14 Aug 2013 22:44:55 GMT < <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <application xmlns="http://wadl.dev.java.net/2009/02"> ... </application> Dienstag, 11. Februar 14
  • 13. WADL <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <application xmlns="http://wadl.dev.java.net/2009/02"> <resources base="https://localhost:8181/baas/api/"> <resource path="todo"> <method id="createToDo" name="PUT"> <request> <representation mediaType="application/json"/> </request> <response> <representation mediaType="application/json"/> </response> </method> ... </resource> </resources> </application> Dienstag, 11. Februar 14
  • 16. HTTPS AND BASIC AUTH • + easy to implement • - password is sent on every request • (- browser stores credentials for session) • (- browser may store creds permanently) • corporate proxies • not for really sensitive data Dienstag, 11. Februar 14
  • 17. BASIC AUTHENTICATION curl -X GET --verbose --insecure https://localhost:8181/baas/api/todo > GET /baas/api/todo HTTP/1.1 ... < < < < < < < < < < < HTTP/1.1 401 Unauthorized X-Powered-By: Servlet/3.0 JSP/2.2 [...] Server: GlassFish Server Open Source Edition 3.1.2.2 Pragma: No-cache Cache-Control: no-cache Expires: Thu, 01 Jan 1970 01:00:00 CET WWW-Authenticate: Basic realm="file" Content-Type: text/html Content-Length: 1073 Date: Wed, 14 Aug 2013 23:33:48 GMT Dienstag, 11. Februar 14
  • 18. BASIC AUTHENTICATION curl -X GET --verbose --insecure -u marc:geheim https://localhost:8181/baas/api/todo > > > > > > GET /baas/api/todo HTTP/1.1 Authorization: Basic bWFyYzpnZWhlaW0= User-Agent: ... Host: localhost:8181 Accept: */* < HTTP/1.1 200 OK Dienstag, 11. Februar 14
  • 20. HTTPS AND FORM AUTH • auth method form in web.xml • credential sent only once (+) • SSO (+) • corporate proxies (-) Dienstag, 11. Februar 14
  • 21. SETTING CORS HEADERS Jersey (eg. Jersey/Tomcat) public class CrossOriginResourceSharingFilter implements ContainerResponseFilter { @Override public ContainerResponse filter( ContainerRequest request, ContainerResponse response) { } } Dienstag, 11. Februar 14 response.getHttpHeaders().putSingle( "Access-Control-Allow-Origin", "*"); response.getHttpHeaders().putSingle( "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); response.getHttpHeaders().putSingle( "Access-Control-Allow-Headers", "content-type,authorization,x-requested-with"); response.getHttpHeaders().putSingle( "Access-Control-Max-Age", "3600"); return response;