ops4j / org.ops4j.pax.web

OSGi R7 Http Service, Whiteboard and Web Applications (OSGi CMPN Release chapters 102, 140 and 128) implementation using Jetty 9, Tomcat 9 or Undertow 2.
https://ops4j1.jira.com/wiki/display/paxweb/Pax+Web
Other
146 stars 184 forks source link

Only first whiteboard resource pattern is considered [PAXWEB-1272] #1551

Closed ops4j-issues closed 3 years ago

ops4j-issues commented 4 years ago

Jean-Baptiste Onofre created PAXWEB-1272

When registering a resource like this:

 @Component(immediate = true,
 service = PersonalProfileResource.class,
 property =
{ "osgi.http.whiteboard.resource.pattern=/profile/*", "osgi.http.whiteboard.resource.pattern=/profile/contact/*", "osgi.http.whiteboard.resource.prefix=/profile" }
)

only the first pattern is taken into account, second one is ignored.


Affects: 7.2.18 Fixed in: 7.3.12, 7.2.22 Votes: 0, Watches: 1

grgrzybek commented 3 years ago

Pax Web 8 changes the tracking model entirely. Now the resource tracker looks like this:

@Override
protected ServletModel createElementModel(ServiceReference<Object> serviceReference, Integer rank, Long serviceId) {
    log.debug("Creating resource model from R7 whiteboard service {} (id={})", serviceReference, serviceId);
    // URL patterns
    String[] urlPatterns = Utils.getPaxWebProperty(serviceReference,
            null, HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PATTERN,
            Utils::asStringArray);
    // prefix
    String path = Utils.getStringProperty(serviceReference, HttpWhiteboardConstants.HTTP_WHITEBOARD_RESOURCE_PREFIX);
    if (path == null || "".equals(path.trim())) {
        path = "/";
    }
    // pass everything to a handy builder - there's no servlet/servletSupplier/servletReference/servletClass
    // provided, which will trigger a call to ServerController.createResourceServlet()
    ServletModel.Builder builder = new ServletModel.Builder()
            .withServiceRankAndId(rank, serviceId)
            .withRegisteringBundle(serviceReference.getBundle())
            .withUrlPatterns(urlPatterns)
            .withLoadOnStartup(1)
            .withAsyncSupported(true)
            .withRawPath(path) // could be file: or a chroot inside a bundle - we'll check and validate later
            .resourceServlet(true);
    return builder.build();
}