Skip to content

Commit 52d6ecf

Browse files
committed
[Whiteboard, DTOs] HttpRuntimeService.getRuntimeDTO() works
1 parent a20f3d6 commit 52d6ecf

File tree

43 files changed

+1756
-685
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1756
-685
lines changed

pax-web-extender-whiteboard/readme.adoc

Lines changed: 147 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ Servlet containers themselves also have "default"/"resource" servlets to serve s
165165

166166
ALl these servlets do several things like handling _index_ for directory access (or not), preventing access to `/WEB-INF/`, etc. For actual resource serving, another interface is used:
167167

168-
* `org.eclipse.jetty.server.ResourceService.doGet()` → `org.eclipse.jetty.http.HttpContent.ContentFactory.getContent()` → `org.eclipse.jetty.util.resource.ResourceFactory.getResource()` → `org.eclipse.jetty.servlet.DefaultServlet.getResource()`
168+
* `org.eclipse.jetty.server.ResourceService.doGet()` → `org.eclipse.jetty.http.HttpContent.ContentFactory.getContent()` → `org.eclipse.jetty.util.resource.ResourceFactory.getResource()` → `org.eclipse.jetty.servlet.DefaultServlet.getResource()`
169169
** if `org.eclipse.jetty.servlet.DefaultServlet._resourceBase` is not `null`: org.eclipse.jetty.util.resource.Resource.addPath()`
170170
** `org.eclipse.jetty.server.handler.ContextHandler.getResource()` → `org.eclipse.jetty.util.resource.Resource.addPath()`
171171
** `javax.servlet.ServletContext.getResource()`
@@ -286,3 +286,149 @@ _Error pages_ are (from `web.xml` point of view) mappings from error codes or FQ
286286
* `org.eclipse.jetty.servlet.ErrorPageErrorHandler._errorPages`
287287
* `org.apache.catalina.util.ErrorPageSupport.exceptionPages` and `org.apache.catalina.util.ErrorPageSupport.statusPages`
288288
* `io.undertow.servlet.api.DeploymentInfo.errorPages` and `io.undertow.servlet.core.DeploymentImpl.errorPages` (no specific Undertow `web.xml` parser. It's parsed in Wildfly by `org.jboss.metadata.parser.servlet.WebCommonMetaDataParser#parse()`)
289+
290+
== DTOs
291+
292+
Whiteboard DTOs (chapter `140.9 The Http Service Runtime Service`) is the last task I planned before Pax Web 8.0.0.GA.
293+
Whiteboard specification assumes huge control over everything registered to the Whiteboard, but Pax Web moves the emphasis to native (Jetty/Tomcat/Undertow) mechanisms of the servlet container, so not everything is as easy as it'd be when implemented using single `DispatcherServlet`.
294+
295+
=== Where Pax Web 8 implements `org.osgi.service.http.runtime.HttpServiceRuntime`?
296+
297+
I decided to register this service not from pax-web-extender-whiteboard bundle, which is responsible for tracking Whiteboard services. In Pax Web 8, this service is published from pax-web-runtime and the _source_ of DTO information is `org.ops4j.pax.web.service.spi.model.ServerModel`, which keeps all the web elements - from Whiteboard, HttpService/WebContainer and from the WABs.
298+
299+
=== DTO for successful services
300+
301+
This part is easier - because every validated Whiteboard service is registered into `ServerModel`, we can easily associated the DTO information.
302+
303+
=== DTO for failed services
304+
305+
This is a bit trickier, at least for the Whiteboard part, because failed registrations are _not_ passed to pax-web-runtime. But I'll think about something.
306+
307+
=== DTO failure reasons
308+
309+
Checking the specification, these are the failure codes:
310+
311+
* `FAILURE_REASON_UNKNOWN` = 0 Failure reason is unknown.
312+
* `FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING` = 1 No matching ServletContextHelper.
313+
* `FAILURE_REASON_SERVLET_CONTEXT_FAILURE` = 2 Matching ServletContextHelper, but the context is not used due to a problem with the context.
314+
* `FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE` = 3 Service is shadowed by another service. For example, a service with the same service properties but a higher service ranking.
315+
* `FAILURE_REASON_EXCEPTION_ON_INIT` = 4 An exception occurred during initializing of the service. This reason can only happen for servlets and servlet filters.
316+
* `FAILURE_REASON_SERVICE_NOT_GETTABLE` = 5 The service is registered in the service registry but getting the service fails as it returns null.
317+
* `FAILURE_REASON_VALIDATION_FAILED` = 6 The service is registered in the service registry but the service properties are invalid.
318+
* `FAILURE_REASON_SERVICE_IN_USE` = 7 The service is not registered as a prototype scoped service and is already in use with a servlet context and therefore can't be used with another servlet context.
319+
* `FAILURE_REASON_SERVLET_WRITE_TO_LOCATION_DENIED` = 8 The servlet is not registered as it is configured to have multipart enabled, but the bundle containing the servlet has no write permission to the provided location for the uploaded files. Since: 1.1
320+
* `FAILURE_REASON_WHITEBOARD_WRITE_TO_DEFAULT_DENIED` = 9 The servlet is not registered as it is configured to have multipart enabled, but the whiteboard implementation has no write permission to the default location for the uploaded files. Since: 1.1
321+
* `FAILURE_REASON_SERVLET_READ_FROM_DEFAULT_DENIED` = 10 The servlet is not registered as it is configured to have multipart enabled, but the bundle containing the servlet has no read permission to the default location for the uploaded files. Since: 1.1
322+
* `FAILURE_REASON_WHITEBOARD_WRITE_TO_LOCATION_DENIED` = 11 The servlet is not registered as it is configured to have multipart enabled, but the whiteboard implementation has no write permission to the provided location for the uploaded files. Since: 1.1
323+
324+
Here are the failure codes associated with particular web element FailedDTOs:
325+
326+
* `FailedErrorPageDTO`:
327+
** DTOConstants.FAILURE_REASON_UNKNOWN
328+
** DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT
329+
** DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
330+
** DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE
331+
** DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE
332+
** DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE
333+
* `FailedFilterDTO`:
334+
** DTOConstants.FAILURE_REASON_UNKNOWN
335+
** DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT
336+
** DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
337+
** DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE
338+
** DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE
339+
** DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE
340+
* `FailedListenerDTO`:
341+
** DTOConstants.FAILURE_REASON_UNKNOWN
342+
** DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT
343+
** DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
344+
** DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE
345+
** DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE
346+
** DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE
347+
* `FailedPreprocessorDTO`:
348+
** DTOConstants.FAILURE_REASON_UNKNOWN
349+
** DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT
350+
** DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE
351+
* `FailedResourceDTO`:
352+
** DTOConstants.FAILURE_REASON_UNKNOWN
353+
** DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT
354+
** DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
355+
** DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE
356+
** DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE
357+
** DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE
358+
* `FailedServletContextDTO`:
359+
** DTOConstants.FAILURE_REASON_UNKNOWN
360+
** DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT
361+
** DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
362+
** DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE
363+
** DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE
364+
** DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE
365+
* `FailedServletDTO`:
366+
** DTOConstants.FAILURE_REASON_UNKNOWN
367+
** DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT
368+
** DTOConstants.FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING
369+
** DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE
370+
** DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE
371+
** DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE
372+
** DTOConstants.FAILURE_REASON_SERVLET_WRITE_TO_LOCATION_DENIED
373+
** DTOConstants.FAILURE_REASON_WHITEBOARD_WRITE_TO_DEFAULT_DENIED
374+
** DTOConstants.FAILURE_REASON_SERVLET_READ_FROM_DEFAULT_DENIED
375+
376+
And here's the revers mapping (FailedDTOs associated with failure codes):
377+
378+
* (0) `FAILURE_REASON_UNKNOWN`:
379+
** `FailedErrorPageDTO`
380+
** `FailedFilterDTO`
381+
** `FailedListenerDTO`
382+
** `FailedPreprocessorDTO`
383+
** `FailedResourceDTO`
384+
** `FailedServletContextDTO`
385+
** `FailedServletDTO`
386+
* (1) `FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING`:
387+
** `FailedErrorPageDTO`
388+
** `FailedFilterDTO`
389+
** `FailedListenerDTO`
390+
** `FailedResourceDTO`
391+
** `FailedServletContextDTO` (why?)
392+
** `FailedServletDTO`
393+
* (2) `FAILURE_REASON_SERVLET_CONTEXT_FAILURE`:
394+
** `FailedErrorPageDTO`
395+
** `FailedFilterDTO`
396+
** `FailedListenerDTO`
397+
** `FailedResourceDTO`
398+
** `FailedServletContextDTO`
399+
** `FailedServletDTO`
400+
* (3) `FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE`:
401+
** `FailedErrorPageDTO`
402+
** `FailedFilterDTO`
403+
** `FailedListenerDTO` (why?)
404+
** `FailedResourceDTO`
405+
** `FailedServletContextDTO`
406+
** `FailedServletDTO`
407+
* (4) `FAILURE_REASON_EXCEPTION_ON_INIT`:
408+
** `FailedErrorPageDTO` (why?)
409+
** `FailedFilterDTO`
410+
** `FailedListenerDTO` (why? especially for fine-graned listeners, like request attribute listeners)
411+
** `FailedPreprocessorDTO`
412+
** `FailedResourceDTO` (why? even if I know there's DefaultServlet underneath)
413+
** `FailedServletContextDTO` (why? ServletContextHelpers are not initialized)
414+
** `FailedServletDTO`
415+
* (5) `FAILURE_REASON_SERVICE_NOT_GETTABLE`:
416+
** `FailedErrorPageDTO`
417+
** `FailedFilterDTO`
418+
** `FailedListenerDTO`
419+
** `FailedPreprocessorDTO`
420+
** `FailedResourceDTO`
421+
** `FailedServletContextDTO`
422+
** `FailedServletDTO`
423+
* (6) `FAILURE_REASON_VALIDATION_FAILED`:
424+
** no particular failure DTO mentioned in the specification
425+
* (7) `FAILURE_REASON_SERVICE_IN_USE`:
426+
** no particular failure DTO mentioned in the specification
427+
* (8) `FAILURE_REASON_SERVLET_WRITE_TO_LOCATION_DENIED`:
428+
** `FailedServletDTO`
429+
* (9) `FAILURE_REASON_WHITEBOARD_WRITE_TO_DEFAULT_DENIED`:
430+
** `FailedServletDTO`
431+
* (10) `FAILURE_REASON_SERVLET_READ_FROM_DEFAULT_DENIED`:
432+
** `FailedServletDTO`
433+
* (11) `FAILURE_REASON_WHITEBOARD_WRITE_TO_LOCATION_DENIED`:
434+
** no particular failure DTO mentioned in the specification

pax-web-extender-whiteboard/src/main/java/org/ops4j/pax/web/extender/whiteboard/internal/Activator.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,12 @@ public class Activator implements BundleActivator {
100100
*/
101101
private final List<ServiceTracker<?, ?>> trackers = new ArrayList<>();
102102

103-
private ExtendedHttpServiceRuntime httpServiceRuntime;
104-
105103
@Override
106104
public void start(final BundleContext bundleContext) throws Exception {
107105
LOG.info("Starting Pax Web Whiteboard Extender");
108106

109107
this.context = bundleContext;
110108

111-
// this is implementation of Whiteboard Service's org.osgi.service.http.runtime.HttpServiceRuntime
112-
httpServiceRuntime = new ExtendedHttpServiceRuntime(bundleContext);
113-
httpServiceRuntime.start();
114-
115109
// this is where "trackers" register/unregister their customized objects.
116110
// a short summary:
117111
// - we have lot of customizers in org.ops4j.pax.web.extender.whiteboard.internal.tracker package ("tracker"
@@ -128,7 +122,7 @@ public void start(final BundleContext bundleContext) throws Exception {
128122
//
129123
// in other words - "extender context" is the component that bridges between tracked web elements + customized
130124
// model elements on one side and "current" WebContainer obtained using proper bundle(context) on the other side
131-
whiteboardExtenderContext = new WhiteboardExtenderContext(httpServiceRuntime, bundleContext);
125+
whiteboardExtenderContext = new WhiteboardExtenderContext(bundleContext);
132126

133127
// we immediately register "default" ServletContextHelper as OSGi service
134128
// felix.http registers something like this:
@@ -191,8 +185,6 @@ public void stop(final BundleContext bundleContext) throws Exception {
191185
}
192186
this.trackers.clear();
193187

194-
httpServiceRuntime.stop();
195-
196188
if (registration != null) {
197189
registration.unregister();
198190
registration = null;

pax-web-extender-whiteboard/src/main/java/org/ops4j/pax/web/extender/whiteboard/internal/BundleWhiteboardApplication.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ public class BundleWhiteboardApplication {
7676
*/
7777
private volatile ServiceReference<WebContainer> webContainerServiceRef;
7878

79-
public BundleWhiteboardApplication(Bundle bundle, WebContainerManager webContainerManager,
80-
ExtendedHttpServiceRuntime httpServiceRuntime) {
79+
public BundleWhiteboardApplication(Bundle bundle, WebContainerManager webContainerManager) {
8180
this.bundle = bundle;
8281
this.webContainerManager = webContainerManager;
8382
}

pax-web-extender-whiteboard/src/main/java/org/ops4j/pax/web/extender/whiteboard/internal/ExtendedHttpServiceRuntime.java

Lines changed: 0 additions & 157 deletions
This file was deleted.

0 commit comments

Comments
 (0)