Skip to content

Commit

Permalink
whiteboard servlet runtime now forwards all properties
Browse files Browse the repository at this point in the history
fixes #46

Signed-off-by: Juergen Albert <j.albert@data-in-motion.biz>
  • Loading branch information
juergen-albert committed Sep 16, 2024
1 parent b065379 commit 00aa722
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,5 +263,13 @@ protected String getBaseURI(ServiceReference<JakartarsServiceRuntime> runtime) {
throw new IllegalArgumentException(
"The JAXRS Service Runtime did not declare an endpoint property");
}

@Test
public void testWhiteboardPropertiesForward() throws Exception {
ServiceReference<JakartarsServiceRuntime> serviceRuntime = tracker.getServiceReference();
Object object = serviceRuntime.getProperties().get("addition.property");
assertEquals("test.property", object);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
{
"jersey.jakartars.whiteboard.name" : "JRSWB",
"jersey.context.path" : "test",
"osgi.http.whiteboard.target" : "(id=SWB)"
"osgi.http.whiteboard.target" : "(id=SWB)",
"addition.property" : "test.property"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class JakartarsServletWhiteboardRuntimeComponent {
private String target;
private String basePath;
private ServiceTracker<HttpServiceRuntime, ServletWhiteboardBasedJerseyServiceRuntime> httpRuntimeTracker;
private Map<String, Object> props;

/**
* Called on component activation
Expand All @@ -63,6 +64,7 @@ public class JakartarsServletWhiteboardRuntimeComponent {
public void activate(BundleContext context, Map<String, Object> props) throws ConfigurationException {

this.context = context;
this.props = props;
target = (String) props.get(HttpWhiteboardConstants.HTTP_WHITEBOARD_TARGET);
basePath = (String) props.getOrDefault(JerseyConstants.JERSEY_CONTEXT_PATH, "/");
openTracker();
Expand Down Expand Up @@ -121,7 +123,7 @@ private HttpServiceTracker(BundleContext context, Filter filter,

@Override
public ServletWhiteboardBasedJerseyServiceRuntime addingService(ServiceReference<HttpServiceRuntime> reference) {
return new ServletWhiteboardBasedJerseyServiceRuntime(context, basePath, reference);
return new ServletWhiteboardBasedJerseyServiceRuntime(context, basePath, reference, props);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,17 @@ public RestContext(ServiceRegistration<ServletContextHelper> contextHelperReg,
}

public ServletWhiteboardBasedJerseyServiceRuntime(BundleContext context, String basePath,
ServiceReference<HttpServiceRuntime> runtimeTarget) {
ServiceReference<HttpServiceRuntime> runtimeTarget, Map<String, Object> props) {
this.context = context;
this.basePath = basePath;
this.runtimeTarget = runtimeTarget;
httpId = (Long) runtimeTarget.getProperty(SERVICE_ID);
this.httpWhiteboardTarget = String.format("(%s=%s)", SERVICE_ID, httpId);
this.runtime = new JerseyServiceRuntime<>(context, this::registerContainer, this::unregisterContainer);

runtime.start(Map.of(JAKARTA_RS_SERVICE_ENDPOINT, getURLs(),
SERVICE_DESCRIPTION, "REST whiteboard for HttpServiceRuntime " + httpId));
Map<String, Object> runtimeProperties = new HashMap<String, Object>(props);
runtimeProperties.put(JAKARTA_RS_SERVICE_ENDPOINT, getURLs());
runtimeProperties.put(SERVICE_DESCRIPTION, "REST whiteboard for HttpServiceRuntime " + httpId);
runtime.start(runtimeProperties);
}


Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<bnd.version>6.4.0</bnd.version>
<bnd.version>7.0.0</bnd.version>
<junit-jupiter.version>5.9.2</junit-jupiter.version>
<assertj.version>3.24.2</assertj.version>
<mockito.version>5.4.0</mockito.version>
Expand Down

0 comments on commit 00aa722

Please sign in to comment.