Felix HTTP Paving the road to the future Jan Willem Janssen and - - PowerPoint PPT Presentation

felix http
SMART_READER_LITE
LIVE PREVIEW

Felix HTTP Paving the road to the future Jan Willem Janssen and - - PowerPoint PPT Presentation

Felix HTTP Paving the road to the future Jan Willem Janssen and Marcel Offermans SSID: Felix Password: felixdemo Browse to: http://10.61.0.161:8080/ Jan Willem Janssen Software architect at Luminis Technologies Currently working on


slide-1
SLIDE 1

Felix HTTP

Paving the road to the future

and Jan Willem Janssen Marcel Offermans

SSID: Felix Password: felixdemo Browse to: http://10.61.0.161:8080/

slide-2
SLIDE 2

Jan Willem Janssen

Software architect at Luminis Technologies Currently working on PulseOn and Amdatu Committer and PMC member at Apache Felix and Apache ACE

slide-3
SLIDE 3

Marcel Offermans

Director at Luminis Technologies, Fellow at Luminis Currently working on Amdatu Apache Member, Committer and PMC member at Apache ACE and Apache Felix

slide-4
SLIDE 4

Agenda

Modular Web Applications Current State Available Extensions The New Specification New extensions Future Work Wrap Up

slide-5
SLIDE 5

Modular Web Applications

slide-6
SLIDE 6

Modular Architectures

High Cohesion, Low Coupling Separation of Concerns Maintainable Code Reusable, Composable

slide-7
SLIDE 7

Deployments

Compose modules into different deployments Low bandwidth by just sending changed modules Fast deployments by being able to update running applications

slide-8
SLIDE 8

Current State

slide-9
SLIDE 9

Explicit Registration

public interface HttpService { void registerServlet(String alias, Servlet servlet, Dictionary initParams, HttpContext httpContext); void registerResources(String alias, String name, HttpContext httpContext); void unregister(String alias); HttpContext createDefaultHttpContext(); }

slide-10
SLIDE 10

Servlets

httpService.registerServlet("/hello", new HttpServlet() { @Override public void doGet(HttpServletRequest req, HttpServletResponse resp) { resp.setContentType("text/plain"); resp.getWriter().write("Hello ApacheCon world!"); } }, null /* initParams */, null /* httpContext */);

invoke the /hello servlet

...

slide-11
SLIDE 11

Resources

httpService.registerResources("/site", "/resources", null /* httpContext */); $ cat resources/hello Hello ApacheCon world, I'm a static resource!

request a static resource called hello

...

slide-12
SLIDE 12

HttpContext

Provides secure access to servlets and resources. Layer of abstraction for resource loading.

public interface HttpContext { boolean handleSecurity(HttpServletRequest request, HttpServletResponse response); URL getResource(String name); String getMimeType(String name); }

slide-13
SLIDE 13

Web Application Specification

Part of the OSGi Enterprise Specification, chapter 128. Web Application Bundle (WAB) are extended Java EE WAR files. They have optional JSP support. Integration with OSGi BundleContext and service registry.

slide-14
SLIDE 14

Available Extensions

slide-15
SLIDE 15

Whiteboard

don't call us, we'll call you! Register your Servlet in the service registry and add a property called alias containing its endpoint. For more information: http://www.osgi.org/wiki/uploads/Links/whiteboard.pdf

slide-16
SLIDE 16

Filters

Just like Servlets, these can be registered whiteboard style

  • r use explicit registration:

the ExtHttpService service from Felix HTTP the WebContainer service from PAX Web

slide-17
SLIDE 17

Amdatu Web Resources

  • f the
  • pen source project (Apache Licensed).

Part Amdatu.org

X-Web-Resource-Version: 1.1 X-Web-Resource: /amdatu-resources;resources X-Web-Resource-Default-Page: index.html,/doc=javadoc.html Include-Resource: resources=resources/basic

slide-18
SLIDE 18

Demo

request a static resource called /amdatu‑resources

...

slide-19
SLIDE 19

Amdatu Web REST

Extensive support for based on industry standards. REST endpoints JAX-RS based annotation support. Includes support for Jackson mappings. Self-documenting endpoints with Swagger.

slide-20
SLIDE 20

Demo

@Path("/rest") @Description("Provides a demo REST endpoint") public class DemoRestEndpoint { private String m_response = "Hello World!"; @GET @Produces(MediaType.TEXT_PLAIN) @Description("Gives a plain text response") public String getPlainResponse() { return m_response; } @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Description("Allows one to set the response to return") public void setResponse( @FormParam("response") @DefaultValue("Default response") String newResponse) { m_response = newResponse; } }

slide-21
SLIDE 21

Self- documenting Endpoints

Swagger is a library that creates documentation for endpoints based on JAX-RS annotations plus some extras. Go to Swagger documentation

slide-22
SLIDE 22

The new specification

slide-23
SLIDE 23

Whiteboard

No longer an extension No explicit registration Specify HttpService to be used

slide-24
SLIDE 24

Example

Dictionary props = new Hashtable(); props.put("osgi.http.whiteboard.servlet.pattern", "/slidemgr"); props.put("osgi.http.whiteboard.target", "(http.service=demo)"); context.registerService(Servlet.class.getName(), new SlideManager(), props);

slide-25
SLIDE 25

(A)synchronous Servlets

Servlet 3.0 API Support wildcard one or more patterns Process work outside the servlet lifecycle

slide-26
SLIDE 26

Example code

class WorkerServlet extends HttpServlet { protected void doGet(HttpServletRequest req, HttpServletResponse resp) { final AsyncContext asyncContext = req.startAsync(req, resp); asyncContext.start(new DeepThought(asyncContext)); } } // class DeepThought implements Runnable { private AsyncContext m_context = // ... public void run() { // ...do some hard work... TimeUnit.DAYS.sleep(356L * 7500000L); HttpServletResponse response = (HttpServletResponse) asyncContext.getResponse(); response.setStatus(SC_OK); response.getWriter().printf("42"); asyncContext.complete(); } }

slide-27
SLIDE 27

Example registration

Dictionary props = new Hashtable(); props.put("osgi.http.whiteboard.servlet.pattern", "/worker/*"); props.put("osgi.http.whiteboard.servlet.asyncSupported", "true"); context.registerService(Servlet.class.getName(), new WorkerServlet(), props);

slide-28
SLIDE 28

Filters

Full support

slide-29
SLIDE 29

Example

Dictionary props = new Hashtable(); props.put("osgi.http.whiteboard.filter.pattern", "/*"); props.put("osgi.http.whiteboard.filter.dispatcher", new String[] {"REQUEST", "INCLUDE", "FORWARD"}); context.registerService(Filter.class.getName(), new SecurityFilter(), props);

slide-30
SLIDE 30

Listeners

Full support All events

slide-31
SLIDE 31

Example

final CountDownLatch latch = new CountDownLatch(1); ServletContextListener contextListener = new ServletContextListener() { public void contextDestroyed(ServletContextEvent event) {} public void contextInitialized(ServletContextEvent event) { latch.countDown(); } }; Dictionary props = new Hashtable(); props.put("osgi.http.whiteboard.context.select", "DEFAULT"); context.registerService(ServletContextListener.class.getName(), contextListener, props); assertTrue("HttpService not ready in time?!", latch.await(5, TimeUnit.SECONDS)); // continue with your itest...

slide-32
SLIDE 32

Custom Error Pages

By error code By exception

slide-33
SLIDE 33

Example

Dictionary props = new Hashtable(); props.put("osgi.http.whiteboard.servlet.errorPage", new String[] {"500", "java.io.IOException"}); context.registerService(Servlet.class.getName(), new MyErrorHandlingServlet(), props);

slide-34
SLIDE 34

New extensions

slide-35
SLIDE 35

WebSockets

“Real-time” Binary or text-based Two-way communication RFC 6455

slide-36
SLIDE 36

Example

// Client-side var wsConn = new WebSocket("ws://" + window.location.host + "/servlet", [ "my-protocol" ]); wsConn.onmessage = function(event) { var data = event.data; // do something with data } // Server-side, registered at "/servlet" class MyWebSocketServlet extends WebSocketServlet { public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) { if ("my-protocol".equals(protocol)) { return new WebSocket.OnTextMessage() { public void onOpen(Connection conn) {} public void onClose(int code, String reason) {} public void onMessage(String data) {} }; } return null; } }

slide-37
SLIDE 37

Demo

Multi-user Etch A Sketch

slide-38
SLIDE 38

SPDY

Let's make the web faster Session layer on top of SSL Reduce bandwidth & lower latency Push multiple resources in a request Basis of HTTP 2.0

slide-39
SLIDE 39

Application Session Presentation Transport

How SPDY fits in the OSI layer model.

slide-40
SLIDE 40

SPDY vs WebSockets

SPDY WebSockets Goal

  • ptimize HTTP

2-way communication Upgradeability transparent needs works Secure? ✔ (mandatory) ✔ (if needed) Two-way? ✔ / ✘ ✔ Multiplexed ✔ ✘ Prioritized ✔ ✘

slide-41
SLIDE 41

Demo

HTTP vs SPDY

slide-42
SLIDE 42

Future Work

slide-43
SLIDE 43

Finalize support for new HttpService specification Upgrade to Jetty 9 Allow “new style” WebSockets (JSR 356) to be used Improved support for SPDY

slide-44
SLIDE 44

Wrap Up

slide-45
SLIDE 45

New/updated specifications New features, functionality & improvements Available extensions Build modular web applications

slide-46
SLIDE 46

Questions?

slide-47
SLIDE 47

Links

felix.apache.org luminis-technologies.com bndtools.org amdatu.org bitbucket.org/marrs/apachecon2014-felix-http