20
© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Condential. Reviving the Hp Service Felix Meschberger, Adobe Systems 1 Mittwoch, 24. Oktober 12

Reviving the HTTP Service - Felix Meschberger

Embed Size (px)

Citation preview

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Reviving the H!p ServiceFelix Meschberger, Adobe Systems

1

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

H"p Service 1.2

§ More or less unmodi!ed since OSGi R1 (May, 2000)§ Resource Registration

§ Custom Authentication

§ Based on Servlet API 2.1§ No Filters

§ No Servlet API Listeners

§ No Error Pages

§ Limited Servlet Registration (path pre!x only)

§ Complex registration:§ Requires H"pService to register with init callback

§ Requires keeping state of successful registration

§ Requires H"p Service to unregister

2

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Revive and Update

§ Servlet API Version

§ Servlet API Elements

§ Improved Registration

§ Whiteboard Support

3

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Requirements 1: H"p Service Updates

HS-1 #e solution MUST de!ne the relationship between the H"p Service and Web Application speci!cations.

HS-2 #e solution MUST update the H"p Service speci!cation to refer to the latest Servlet API speci!cation and de!ne to what extend the H"p Service provides support.

HS-3 #e solution MUST extend the H"pService service API to support Servlet registration with pa"erns as de!ned by the Servlet API speci!cation (Section 12.2, Speci!cation of Mappings, in the Servlet API 3.0 speci!cation). #is requirement aligns servlet registration to functionality provided by the Servlet API web application descriptor (web.xml).

HS-4 #e solution MUST extend the H"pService service API to support registration of Servlet API !lters with pa"erns as de!ned by the Servlet API speci!cation (Section 12.2, Speci!cation of Mappings, in the Servlet API 3.0 speci!cation) or referring to servlets by their names. #is requirement aligns mapping !lters to requests to functionality provided by the Servlet API web application descriptor (web.xml).

HS-5 #e solution MUST extend the H"pService service API to support registration of Servlet API listeners.

HS-6 #e solution MUST add support for error page con!guration.

HS-7 #e solution MUST de!ne how registered Servlets and Filters are named.

HS-8 #e solution MUST clarify ServletContext implementation in the H"pService for both standalone and bridged H"p Service implementations.

HS-9 #e solution MUST clarify the ServletContext scope of Servlet API listeners registered through the H"pService.

HS-10 #e solution MAY specify support for scripted request processing. For example supporting JSP with Tag Libraries.

HS-11 #e solution MAY de!ne how H"pService instances can be dynamically con!gured.

HS-12 #e solution MUST de!ne service registration properties for the H"pService to re$ect con!guration of the service.

4

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Requirements 2: Whiteboard Registration

HS-13 #e solution MUST de!ne whiteboard registration of servlet services with the H"pService.

HS-14 #e solution MUST de!ne whiteboard registration of !lter services with the H"pService.

HS-15 #e solution MUST de!ne whiteboard registration of servlet listener services with the H"pService.

HS-16 #e solution MUST de!ne registration of OSGi H"pContext services used for Servlet and Filter registration.

HS-17 #e solution MUST de!ne how servlets, !lters, and servlet listener services are matched with H"pService services for registration.

HS-18 #e solution MUST support registration of static resources according to the extender pa"ern.

HS-19 #e solution MUST support registration of error pages according to the extender pa"ern.

HS-20 #e solution MUST de!ne a capability for the osgi.extender namespace. Bundles providing resources and/or error pages can then require this capability.

HS-21 #e solution MUST de!ne a capability for the whiteboard pa"ern registration in one of the standard namespaces (or a new namespace to be de!ned in the Chapter 135, Common Namespaces Speci!cation). Bundles registering servlet, !lter, and/or servlet listener services can then require this capability.

5

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Servlet API Version

§ Which Servlet API to support/require ?§ Servlet API 3.0 for the latest and greatest ?

§ Must not alienate Embedded Systems !

§ Servlet API and the Platform§ 2.4 requires Java 1.3

§ 2.5 requires Java 5

§ 3.0 requires Java 6

6

>= 2.4

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Servlet API Elements

7

Servlet

Filter

Error Pages

Event Listener

EJB

MIME mapping

Replacements• EJB: Use Services• MIME mapping: Use HttpContext

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Servlet Registration - H"p Service 1.2

8

public interface HttpService {

public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context) throws ServletException, NamespaceException;

public void unregister(String alias);

}

Single path Pre!x only

Servlet or Resource ?

Manage State

Service Required

Share ?

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Servlet Registration - H"p Service 1.2

8

public interface HttpService {

public void registerServlet(String alias, Servlet servlet, Dictionary initparams, HttpContext context) throws ServletException, NamespaceException;

public void unregister(String alias);

}

Single path Pre!x only

Servlet or Resource ?

Manage State

Service Required

unregisterServlet(servlet)

Pa"ernWhiteboard Allow Array

Share ?Whiteboard

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Sample Traditional Servlet

9

@Component(service = Servlet.class, property = "alias=/")public class SampleServletOld extends HttpServlet {

private HttpService httpService;

private String servletAlias;

private boolean servletRegistered;

@Activate private void activate(Map<String, Object> config) throws ServletException, NamespaceException { this.servletAlias = (String) config.get("alias"); this.httpService.registerServlet(this.servletAlias, this, null, null); this.servletRegistered = true; }

@Deactivate private void deactivate() { if (this.servletRegistered) { this.httpService.unregister(servletAlias); } }

@Reference(unbind = "unbindHttpService") private void bindHttpService(final HttpService httpService) { this.httpService = httpService; }

private void unbindHttpService(final HttpService httpService) { if (this.httpService == httpService) { this.httpService = null; } }}

Manage State

Service Required

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Sample Traditional Servlet with new API

10

@Component(service = Servlet.class, property = "alias=/")public class SampleServletNew extends HttpServlet {

private HttpService httpService;

private boolean servletRegistered;

@Activate private void activate(Map<String, Object> config) throws ServletException, NamespaceException { String servletAlias = (String) config.get("alias"); this.httpService.registerServlet(servletAlias, this, null, null); this.servletRegistered = true; }

@Deactivate private void deactivate() { if (this.servletRegistered) { this.httpService.unregisterServlet(this); } }

@Reference(unbind = "unbindHttpService") private void bindHttpService(final HttpService httpService) { this.httpService = httpService; }

private void unbindHttpService(final HttpService httpService) { if (this.httpService == httpService) { this.httpService = null; } }}

Manage State

Service Required

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Sample Whiteboard Servlet

11

@Component(service = Servlet.class, property = "org.osgi.pattern=/")public class SampleServletWhiteboard extends HttpServlet {

}

§ No State Management

§ No H"p Service reference

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Alias vs. Pa"ern

12

H!p Service Servlet API Match Type

/alias /pre!x/* Pre!x Match

*.ext Extension Match

„“ (empty) Context Root Match

/ Default Servlet

/exact/match Exact Match

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Alias vs. Pa"ern

12

H!p Service Servlet API Match Type

/alias /pre!x/* Pre!x Match

*.ext Extension Match

„“ (empty) Context Root Match

/ Default Servlet

/exact/match Exact Match

public void registerServlet(String[] pattern, Servlet servlet, Dictionary<String, String> initparams, HttpContext context) throws ServletException, NamespaceException;

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

H"p Context and Servlet Context

13

Common Servlet Context(e.g. from Servlet Container)

Servlet Context 1 Servlet Context n

H"p Context 1 H"p Context n

Context PathH"p Sessions

A"ributesResourcesMIME Types

A"ributesResources

MIME Types

Authentication Authentication

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Event Listener

§ Listeners are Services§ Listener interface is Service Name

§ Supported Listeners depending on Servlet API Support

§ Whiteboard Registration

§ All Events from H"p Service (not con!ned to ServletContext)

14

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Error Pages

§ De!ned as mappings§ Status Code -> Location

§ Exception Type -> Location

§ Proposal: HttpService extension

§ registerErrorPage(int code, String location)§ unregisterErrorPage(int code)§ registerErrorPage(String exceptionType, String location)§ unregisterErrorPage(String exceptionType)

15

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Whiteboard Support

§ Add-On to H"p Service

§ Gets Servlet, Filter, H"pContext services

§ Registers with H"p Service

§ Matches Servlet to H"pContext with property

16

Servlet

H"pContext

H"p Service

context.name

pa"ern

Filter

pa"ern

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

H"p Service Whiteboard Properties

17

Servlet H!pContext Filter

osgi.http.context.id

osgi.http.context.shared

osgi.http.pattern

osgi.http.errorPage

osgi.http.init.*

Refers to H"pContext

Identi!es Refers to H"pContext

n/aShared across

Bundles ? n/a

Registration Pa"ern n/a

Registration Pa"ern

Status CodeException Type n/a n/a

Init Parameters n/a Init Parameters

Mittwoch, 24. Oktober 12

© 2011 Adobe Systems Incorporated. All Rights Reserved. Adobe Con!dential.

Links

§ h"p://wiki.osgi.org/wiki/WebExperience

§ RFP 150 H"p Service Updates(h"ps://www.osgi.org/bugzilla/show_bug.cgi?id=146)

§ Discuss: [email protected]

18

Mittwoch, 24. Oktober 12