starting to fix jaxrs whiteboard example (not yet finished)
diff --git a/winegrower-cepages/pom.xml b/winegrower-cepages/pom.xml
index e2f17b7..9a47614 100644
--- a/winegrower-cepages/pom.xml
+++ b/winegrower-cepages/pom.xml
@@ -37,6 +37,7 @@
<properties>
<karaf.version>4.2.1</karaf.version>
+ <cxf.version>3.2.6</cxf.version>
</properties>
<modules>
diff --git a/winegrower-cepages/winegrower-cepage-cxf-rs/pom.xml b/winegrower-cepages/winegrower-cepage-cxf-rs/pom.xml
index 4065c28..a383d51 100644
--- a/winegrower-cepages/winegrower-cepage-cxf-rs/pom.xml
+++ b/winegrower-cepages/winegrower-cepage-cxf-rs/pom.xml
@@ -28,10 +28,6 @@
<artifactId>cxf-rs</artifactId>
<name>Apache Winegrower :: Cepages :: CXF JAX-RS</name>
- <properties>
- <cxf.version>3.2.6</cxf.version>
- </properties>
-
<dependencies>
<dependency>
<groupId>org.apache.winegrower.cepages</groupId>
diff --git a/winegrower-cepages/winegrower-cepage-jaxrs/pom.xml b/winegrower-cepages/winegrower-cepage-jaxrs/pom.xml
index 981bdd6..e274ebb 100644
--- a/winegrower-cepages/winegrower-cepage-jaxrs/pom.xml
+++ b/winegrower-cepages/winegrower-cepage-jaxrs/pom.xml
@@ -49,6 +49,11 @@
<artifactId>org.apache.aries.component-dsl.component-dsl</artifactId>
<version>1.2.1</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.cxf</groupId>
+ <artifactId>cxf-rt-rs-sse</artifactId>
+ <version>${cxf.version}</version>
+ </dependency>
</dependencies>
</project>
\ No newline at end of file
diff --git a/winegrower-core/src/main/java/org/apache/winegrower/Ripener.java b/winegrower-core/src/main/java/org/apache/winegrower/Ripener.java
index 56e8250..a3664a2 100644
--- a/winegrower-core/src/main/java/org/apache/winegrower/Ripener.java
+++ b/winegrower-core/src/main/java/org/apache/winegrower/Ripener.java
@@ -40,7 +40,7 @@
import org.apache.winegrower.deployer.OSGiBundleLifecycle;
import org.apache.winegrower.scanner.StandaloneScanner;
import org.apache.winegrower.scanner.manifest.ActivatorManifestContributor;
-import org.apache.winegrower.scanner.manifest.BlueprintManifestContributor;
+import org.apache.winegrower.scanner.manifest.OSGIInfContributor;
import org.apache.winegrower.scanner.manifest.KarafCommandManifestContributor;
import org.apache.winegrower.scanner.manifest.ManifestContributor;
import org.apache.winegrower.service.BundleRegistry;
@@ -82,7 +82,7 @@
private Collection<String> scanningExcludes;
private Collection<ManifestContributor> manifestContributors = Stream.concat(
// built-in
- Stream.of(new KarafCommandManifestContributor(), new ActivatorManifestContributor(), new BlueprintManifestContributor()),
+ Stream.of(new KarafCommandManifestContributor(), new ActivatorManifestContributor(), new OSGIInfContributor()),
// extensions
StreamSupport.stream(ServiceLoader.load(ManifestContributor.class).spliterator(), false)
).collect(toList());
@@ -90,6 +90,7 @@
private List<String> prioritizedBundles = asList(
"org.apache.aries.blueprint.core",
"org.apache.aries.blueprint.cm",
+ "org.apache.aries.jax.rs.whiteboard",
"pax-web-extender-whiteboard",
"pax-web-runtime");
diff --git a/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/BlueprintManifestContributor.java b/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/BlueprintManifestContributor.java
deleted file mode 100644
index ec782e6..0000000
--- a/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/BlueprintManifestContributor.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package org.apache.winegrower.scanner.manifest;
-
-import static java.util.Collections.list;
-import static java.util.Optional.ofNullable;
-import static java.util.stream.Collectors.joining;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.function.Supplier;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-import java.util.stream.Stream;
-import java.util.zip.ZipEntry;
-
-import org.apache.xbean.finder.AnnotationFinder;
-import org.apache.xbean.finder.archive.Archive;
-import org.apache.xbean.finder.archive.FileArchive;
-import org.apache.xbean.finder.archive.JarArchive;
-import org.apache.xbean.finder.util.Files;
-
-public class BlueprintManifestContributor implements ManifestContributor {
- @Override
- public void contribute(final AnnotationFinder finder, final Supplier<Manifest> manifest) {
- final Archive archive = finder.getArchive();
- if (JarArchive.class.isInstance(archive)) {
- try (final JarFile jar = new JarFile(Files.toFile(JarArchive.class.cast(archive).getUrl()))) {
- addBlueprintEntries(manifest, list(jar.entries()).stream()
- .filter(it -> it.getName().startsWith("OSGI-INF/blueprint/") && it.getName().endsWith(".xml"))
- .map(ZipEntry::getName)
- .collect(joining(",")));
- } catch (final IOException e) {
- // no-op
- }
- } else if (FileArchive.class.isInstance(archive)) {
- final File base = FileArchive.class.cast(archive).getDir();
- final File blueprint = new File(base, "OSGI-INF/blueprint/");
- if (blueprint.isDirectory()) {
- addBlueprintEntries(manifest, Stream.of(ofNullable(blueprint.list()).orElseGet(() -> new String[0]))
- .filter(it -> it.endsWith(".xml"))
- .map(it -> "OSGI-INF/blueprint/" + it)
- .collect(joining(",")));
- }
- }
- }
-
- private void addBlueprintEntries(final Supplier<Manifest> manifest, final String list) {
- if (list.isEmpty()) {
- return;
- }
- manifest.get().getMainAttributes().putValue("Bundle-Blueprint", list);
- }
-}
diff --git a/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/OSGIInfContributor.java b/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/OSGIInfContributor.java
new file mode 100644
index 0000000..ae51540
--- /dev/null
+++ b/winegrower-core/src/main/java/org/apache/winegrower/scanner/manifest/OSGIInfContributor.java
@@ -0,0 +1,80 @@
+package org.apache.winegrower.scanner.manifest;
+
+import static java.util.Collections.list;
+import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.joining;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.function.Supplier;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+
+import org.apache.xbean.finder.AnnotationFinder;
+import org.apache.xbean.finder.archive.Archive;
+import org.apache.xbean.finder.archive.FileArchive;
+import org.apache.xbean.finder.archive.JarArchive;
+import org.apache.xbean.finder.util.Files;
+
+public class OSGIInfContributor implements ManifestContributor {
+
+ @Override
+ public void contribute(final AnnotationFinder finder, final Supplier<Manifest> manifest) {
+ final Archive archive = finder.getArchive();
+ if (JarArchive.class.isInstance(archive)) {
+ try (final JarFile jar = new JarFile(Files.toFile(JarArchive.class.cast(archive).getUrl()))) {
+ final Collection<JarEntry> entries = list(jar.entries());
+ addBlueprintEntries(manifest, filterEntries(entries, "OSGI-INF/blueprint/"));
+ addServiceComponentEntries(manifest, filterEntries(entries, "OSGI-INF/"));
+ } catch (final IOException e) {
+ // no-op
+ }
+ } else if (FileArchive.class.isInstance(archive)) {
+ final File base = FileArchive.class.cast(archive).getDir();
+ {
+ final File blueprint = new File(base, "OSGI-INF/blueprint/");
+ if (blueprint.isDirectory()) {
+ addBlueprintEntries(manifest, filterChildren(blueprint, "OSGI-INF/blueprint/"));
+ }
+ }
+ {
+ final File from = new File(base, "OSGI-INF/");
+ if (from.isDirectory()) {
+ addServiceComponentEntries(manifest, filterChildren(from, "OSGI-INF/"));
+ }
+ }
+ }
+ }
+
+ private String filterChildren(final File from, final String prefix) {
+ return Stream.of(ofNullable(from.list()).orElseGet(() -> new String[0]))
+ .filter(it -> it.endsWith(".xml"))
+ .map(it -> prefix + it)
+ .collect(joining(","));
+ }
+
+ private String filterEntries(final Collection<JarEntry> entries, String s) {
+ return entries.stream()
+ .filter(it -> it.getName().startsWith(s) && it.getName().endsWith(".xml"))
+ .map(ZipEntry::getName)
+ .collect(joining(","));
+ }
+
+ private void addBlueprintEntries(final Supplier<Manifest> manifest, final String list) {
+ if (list.isEmpty()) {
+ return;
+ }
+ manifest.get().getMainAttributes().putValue("Bundle-Blueprint", list);
+ }
+
+ private void addServiceComponentEntries(final Supplier<Manifest> manifest, final String list) {
+ if (list.isEmpty()) {
+ return;
+ }
+ manifest.get().getMainAttributes().putValue("Service-Component", list);
+ }
+}
diff --git a/winegrower-core/src/main/java/org/apache/winegrower/service/OSGiServices.java b/winegrower-core/src/main/java/org/apache/winegrower/service/OSGiServices.java
index 737ed30..bced400 100644
--- a/winegrower-core/src/main/java/org/apache/winegrower/service/OSGiServices.java
+++ b/winegrower-core/src/main/java/org/apache/winegrower/service/OSGiServices.java
@@ -129,7 +129,9 @@
if (properties != null) {
list(properties.keys()).forEach(key -> serviceProperties.put(key, properties.get(key)));
}
- serviceProperties.put(Constants.OBJECTCLASS, classes);
+ if (!serviceProperties.containsKey(Constants.OBJECTCLASS)) {
+ serviceProperties.put(Constants.OBJECTCLASS, classes.length == 1 ? classes[0] : classes);
+ }
serviceProperties.put(Constants.SERVICE_ID, idGenerator.getAndIncrement());
serviceProperties.put(Constants.SERVICE_BUNDLEID, from.getBundleId());
if (ServiceFactory.class.isInstance(service)) {
diff --git a/winegrower-examples/jaxrs-whiteboard/pom.xml b/winegrower-examples/jaxrs-whiteboard/pom.xml
index 030cde4..cdc4068 100644
--- a/winegrower-examples/jaxrs-whiteboard/pom.xml
+++ b/winegrower-examples/jaxrs-whiteboard/pom.xml
@@ -48,6 +48,11 @@
<artifactId>jaxrs</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr</artifactId>
+ <version>2.0.14</version>
+ </dependency>
</dependencies>
<build>
@@ -56,6 +61,12 @@
<groupId>org.apache.winegrower</groupId>
<artifactId>winegrower-maven-plugin</artifactId>
<version>${project.version}</version>
+ <configuration>
+ <systemVariables>
+ <winegrower.service.org.apache.aries.jax.rs.whiteboard.default.osgi.http.whiteboard.context.name>/</winegrower.service.org.apache.aries.jax.rs.whiteboard.default.osgi.http.whiteboard.context.name>
+ <winegrower.service.org.apache.aries.jax.rs.whiteboard.default.osgi.http.whiteboard.context.path>/</winegrower.service.org.apache.aries.jax.rs.whiteboard.default.osgi.http.whiteboard.context.path>
+ </systemVariables>
+ </configuration>
</plugin>
</plugins>
</build>
diff --git a/winegrower-examples/jaxrs-whiteboard/src/main/java/org/apache/winegrower/examples/jaxrs/Harvest.java b/winegrower-examples/jaxrs-whiteboard/src/main/java/org/apache/winegrower/examples/jaxrs/Harvest.java
index 518c8e2..774ca7f 100644
--- a/winegrower-examples/jaxrs-whiteboard/src/main/java/org/apache/winegrower/examples/jaxrs/Harvest.java
+++ b/winegrower-examples/jaxrs-whiteboard/src/main/java/org/apache/winegrower/examples/jaxrs/Harvest.java
@@ -13,15 +13,13 @@
*/
package org.apache.winegrower.examples.jaxrs;
-import org.osgi.service.component.annotations.Component;
+import java.time.LocalDate;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
-import java.time.LocalDate;
-@Component(service = Harvest.class)
@Path("/api/harvest")
public class Harvest {
@GET
diff --git a/winegrower-examples/jaxrs-whiteboard/src/main/resources/OSGI-INF/org.apache.winegrower.examples.jaxrs.Harvest.xml b/winegrower-examples/jaxrs-whiteboard/src/main/resources/OSGI-INF/org.apache.winegrower.examples.jaxrs.Harvest.xml
new file mode 100644
index 0000000..46b549d
--- /dev/null
+++ b/winegrower-examples/jaxrs-whiteboard/src/main/resources/OSGI-INF/org.apache.winegrower.examples.jaxrs.Harvest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<component name="Harvest">
+ <property name="osgi.jaxrs.endpoint" value="/api/"/>
+ <property name="osgi.jaxrs.resource" value="true"/>
+ <implementation class="org.apache.winegrower.examples.jaxrs.Harvest"/>
+ <service>
+ <provide interface="org.apache.winegrower.examples.jaxrs.Harvest"/>
+ </service>
+</component>