This is an automated email from the ASF dual-hosted git repository.
rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/johnzon.git
The following commit(s) were added to refs/heads/master by this push:
new bec9120 JOHNZON-189 Add support for JAX RS Whiteboard
bec9120 is described below
commit bec9120628ebce3ce47fd1d6e00301d4f1a801ec
Author: Raymond Auge <[email protected]>
AuthorDate: Thu Sep 27 21:12:50 2018 -0400
JOHNZON-189 Add support for JAX RS Whiteboard
---
johnzon-osgi/pom.xml | 131 +++++++++++++++
.../java/org/apache/johnzon/osgi/Activator.java | 177 +++++++++++++++++++++
.../main/java/org/apache/johnzon/osgi/Config.java | 74 +++++++++
.../johnzon/osgi/cdi/CdiExtensionFactory.java | 40 +++++
.../johnzon/osgi/cdi/RegisterCdiExtension.java | 74 +++++++++
.../org/apache/johnzon/osgi/cdi/package-info.java | 41 +++++
.../java/org/apache/johnzon/osgi/package-info.java | 30 ++++
pom.xml | 1 +
src/site/markdown/index.md | 41 +++++
9 files changed, 609 insertions(+)
diff --git a/johnzon-osgi/pom.xml b/johnzon-osgi/pom.xml
new file mode 100644
index 0000000..230c7fb
--- /dev/null
+++ b/johnzon-osgi/pom.xml
@@ -0,0 +1,131 @@
+<?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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <artifactId>johnzon</artifactId>
+ <groupId>org.apache.johnzon</groupId>
+ <version>1.2.3-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>johnzon-osgi</artifactId>
+ <name>Johnzon :: Support for OSGI Jaxrs Whiteboard</name>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.component-dsl</groupId>
+ <artifactId>org.apache.aries.component-dsl.component-dsl</artifactId>
+ <version>1.2.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.namespace.extender</artifactId>
+ <version>1.0.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.namespace.service</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.metatype.annotations</artifactId>
+ <version>1.4.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.cdi</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.jaxrs</artifactId>
+ <version>1.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.util.converter</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.util.function</artifactId>
+ <version>1.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.annotation</artifactId>
+ <version>7.0.0</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-annotation_1.3_spec</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jcdi_2.0_spec</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jaxrs_2.1_spec</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jsonb_1.0_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-jsonb</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.johnzon</groupId>
+ <artifactId>johnzon-mapper</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Import-Package>
+ javax.enterprise.inject.spi.*;resolution:=optional,*
+ </Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/Activator.java
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/Activator.java
new file mode 100644
index 0000000..6664c94
--- /dev/null
+++ b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/Activator.java
@@ -0,0 +1,177 @@
+/*
+ * 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.
+ */
+
+package org.apache.johnzon.osgi;
+
+import static org.apache.aries.component.dsl.OSGi.all;
+import static org.apache.aries.component.dsl.OSGi.coalesce;
+import static org.apache.aries.component.dsl.OSGi.configuration;
+import static org.apache.aries.component.dsl.OSGi.configurations;
+import static org.apache.aries.component.dsl.OSGi.ignore;
+import static org.apache.aries.component.dsl.OSGi.just;
+import static org.apache.aries.component.dsl.OSGi.register;
+
+import java.util.AbstractMap;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.annotation.Priority;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.apache.aries.component.dsl.OSGi;
+import org.apache.aries.component.dsl.OSGiResult;
+import org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider;
+import org.apache.johnzon.osgi.cdi.RegisterCdiExtension;
+import org.osgi.annotation.bundle.Header;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.PrototypeServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants;
+import org.osgi.util.converter.Converter;
+import org.osgi.util.converter.Converters;
+
+@Header(name = Constants.BUNDLE_ACTIVATOR, value = "${@class}")
+public class Activator implements BundleActivator {
+
+ private static final Converter CONVERTER = Converters.standardConverter();
+
+ private static final OSGi<Entry<Dictionary<String, ?>, Config>>
CONFIGURATION = coalesce(
+ all(
+ configurations(Config.CONFIG_PID),
+ configuration(Config.CONFIG_PID)
+ ),
+ just(Hashtable::new)
+ ).map(
+ properties -> new AbstractMap.SimpleImmutableEntry<>(
+ properties,
+ CONVERTER.convert(properties).to(Config.class)
+ )
+ );
+
+ private OSGiResult _result;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ _result = all(
+ ignore(
+ CONFIGURATION.flatMap(
+ entry -> register(
+ new String[]{
+ MessageBodyReader.class.getName(),
+ MessageBodyWriter.class.getName()
+ },
+ new JsonbJaxrsProviderFactory(entry.getValue()),
+ getJaxrsExtensionProperties(entry.getKey(),
entry.getValue())
+ )
+ )
+ ),
+ ignore(RegisterCdiExtension.ifPossible())
+ ).run(context);
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ _result.close();
+ }
+
+ @SuppressWarnings("serial")
+ private Map<String, ?> getJaxrsExtensionProperties(
+ Dictionary<String, ?> properties, Config config) {
+
+ Enumeration<String> keys = properties.keys();
+
+ return new HashMap<String, Object>() {{
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement();
+
+ if(!key.startsWith(".")) {
+ put(key, properties.get(key));
+ }
+ }
+
+ put(JaxrsWhiteboardConstants.JAX_RS_EXTENSION, true);
+ put(JaxrsWhiteboardConstants.JAX_RS_NAME, "johnzon.jsonb");
+
+ putIfAbsent("ignores", config.ignores());
+ putIfAbsent(
+ JaxrsWhiteboardConstants.JAX_RS_APPLICATION_SELECT,
+ config.osgi_jaxrs_application_select());
+ putIfAbsent(
+ JaxrsWhiteboardConstants.JAX_RS_MEDIA_TYPE,
+ config.osgi_jaxrs_media_type());
+ putIfAbsent(
+ Constants.SERVICE_RANKING,
+
JsonbJaxrsProvider.class.getAnnotation(Priority.class).value());
+ }};
+ }
+
+ private static class JsonbJaxrsProviderFactory implements
PrototypeServiceFactory<JsonbJaxrsProvider<?>> {
+
+ private final Config config;
+
+ public JsonbJaxrsProviderFactory(Config config) {
+ this.config = config;
+ }
+
+ @Override
+ public JsonbJaxrsProvider<?> getService(
+ Bundle bundle, ServiceRegistration<JsonbJaxrsProvider<?>>
registration) {
+
+ return new ExtendedJsonbJaxrsProvider(config);
+ }
+
+ @Override
+ public void ungetService(
+ Bundle bundle, ServiceRegistration<JsonbJaxrsProvider<?>>
registration, JsonbJaxrsProvider<?> service) {
+ }
+
+ }
+
+ private static class ExtendedJsonbJaxrsProvider extends
JsonbJaxrsProvider<Object> {
+ public ExtendedJsonbJaxrsProvider(final Config config) {
+ super(Arrays.asList(config.ignores()));
+
+
setThrowNoContentExceptionOnEmptyStreams(config.throw_no_content_exception_on_empty_streams());
+ setFailOnUnknownProperties(config.fail_on_unknown_properties());
+ setUseJsRange(config.use_js_range());
+ setOtherProperties(config.other_properties());
+ setIJson(config.ijson());
+ setEncoding(config.encoding());
+ setBinaryDataStrategy(config.binary_datastrategy());
+ setPropertyNamingStrategy(config.property_naming_strategy());
+ setPropertyOrderStrategy(config.property_order_strategy());
+ setNullValues(config.null_values());
+ setPretty(config.pretty());
+
setFailOnMissingCreatorValues(config.fail_on_missing_creator_values());
+
setPolymorphicSerializationPredicate(config.polymorphic_serialization_predicate());
+
setPolymorphicDeserializationPredicate(config.polymorphic_deserialization_predicate());
+ setPolymorphicDiscriminator(config.polymorphic_discriminator());
+ }
+ }
+
+}
diff --git a/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/Config.java
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/Config.java
new file mode 100644
index 0000000..732f237
--- /dev/null
+++ b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/Config.java
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.apache.johnzon.osgi;
+
+import javax.ws.rs.core.MediaType;
+
+import org.osgi.service.metatype.annotations.AttributeDefinition;
+import org.osgi.service.metatype.annotations.ObjectClassDefinition;
+
+@ObjectClassDefinition(
+ description = "Configuration for Johnzon JSONB JAX-RS Whiteboard Message
Body Reader & Writer",
+ name = "Johnzon JAX-RS JSONB",
+ pid = Config.CONFIG_PID
+)
+public @interface Config {
+ public static final String CONFIG_PID = "org.apache.johnzon.jsonb";
+
+ @AttributeDefinition(description = "List of fully qualified class names to
ignore")
+ String[] ignores() default {};
+
+ @AttributeDefinition(description = "Filter expression used to match the
extension to JAX-RS Whiteboard Applications")
+ String osgi_jaxrs_application_select() default "(!(johnzon.jsonb=false))";
+
+ @AttributeDefinition(description = "List of media types handled by the
extension")
+ String[] osgi_jaxrs_media_type() default MediaType.APPLICATION_JSON;
+
+ boolean throw_no_content_exception_on_empty_streams() default false;
+
+ boolean fail_on_unknown_properties() default false;
+
+ boolean use_js_range() default false;
+
+ String other_properties() default "";
+
+ boolean ijson() default false;
+
+ String encoding() default "";
+
+ String binary_datastrategy() default "";
+
+ String property_naming_strategy() default "";
+
+ String property_order_strategy() default "";
+
+ boolean null_values() default false;
+
+ boolean pretty() default false;
+
+ boolean fail_on_missing_creator_values() default false;
+
+ String polymorphic_serialization_predicate() default "";
+
+ String polymorphic_deserialization_predicate() default "";
+
+ String polymorphic_discriminator() default "";
+
+}
\ No newline at end of file
diff --git
a/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/CdiExtensionFactory.java
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/CdiExtensionFactory.java
new file mode 100644
index 0000000..667a8ab
--- /dev/null
+++
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/CdiExtensionFactory.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package org.apache.johnzon.osgi.cdi;
+
+import javax.enterprise.inject.spi.Extension;
+
+import org.apache.johnzon.jsonb.cdi.JohnzonCdiExtension;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.PrototypeServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+public class CdiExtensionFactory implements PrototypeServiceFactory<Extension>
{
+
+ @Override
+ public Extension getService(Bundle bundle, ServiceRegistration<Extension>
registration) {
+ return new JohnzonCdiExtension();
+ }
+
+ @Override
+ public void ungetService(Bundle bundle, ServiceRegistration<Extension>
registration, Extension service) {
+ }
+
+}
diff --git
a/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/RegisterCdiExtension.java
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/RegisterCdiExtension.java
new file mode 100644
index 0000000..54ef918
--- /dev/null
+++
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/RegisterCdiExtension.java
@@ -0,0 +1,74 @@
+/*
+ * 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.
+ */
+
+package org.apache.johnzon.osgi.cdi;
+
+import static org.apache.aries.component.dsl.OSGi.NOOP;
+import static org.apache.aries.component.dsl.OSGi.effects;
+import static org.apache.aries.component.dsl.OSGi.register;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.annotation.Priority;
+
+import org.apache.aries.component.dsl.OSGi;
+import org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider;
+import org.osgi.framework.Constants;
+import org.osgi.service.cdi.CDIConstants;
+
+public class RegisterCdiExtension {
+
+ private RegisterCdiExtension() {
+ }
+
+ public static OSGi<?> ifPossible() {
+ if (tryLoadingCdi()) {
+ return register(
+ javax.enterprise.inject.spi.Extension.class,
+ new org.apache.johnzon.osgi.cdi.CdiExtensionFactory(),
+ getCdiExtensionProperties()
+ );
+ } else {
+ return effects(NOOP, NOOP);
+ }
+ }
+
+ private static boolean tryLoadingCdi() {
+ try {
+ Class.forName("javax.enterprise.inject.spi.Extension");
+ return true;
+ } catch (ClassNotFoundException cfne) {
+ return false;
+ }
+ }
+
+ @SuppressWarnings("serial")
+ private static Map<String, Object> getCdiExtensionProperties() {
+ return new HashMap<String, Object>() {{
+ put(CDIConstants.CDI_EXTENSION_PROPERTY, "JavaJSONB");
+ put("aries.cdi.extension.mode", "implicit");
+
+ putIfAbsent(
+ Constants.SERVICE_RANKING,
+
JsonbJaxrsProvider.class.getAnnotation(Priority.class).value());
+ }};
+ }
+
+}
diff --git
a/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/package-info.java
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/package-info.java
new file mode 100644
index 0000000..e57ab0b
--- /dev/null
+++ b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/cdi/package-info.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+@Capability(namespace = SERVICE_NAMESPACE,
+ attribute = {
+ CDI_EXTENSION_PROPERTY + "=JavaJSONB",
+ "objectClass:List<String>='javax.enterprise.inject.spi.Extension'"})
+@Capability(namespace = CDI_EXTENSION_PROPERTY,
+ attribute = CDI_EXTENSION_PROPERTY + "=JavaJSONB")
+@Requirement(
+ namespace = EXTENDER_NAMESPACE,
+ name = CDI_CAPABILITY_NAME,
+ version = CDI_SPECIFICATION_VERSION,
+ effective = EFFECTIVE_ACTIVE)
+package org.apache.johnzon.osgi.cdi;
+
+import static org.osgi.namespace.extender.ExtenderNamespace.EXTENDER_NAMESPACE;
+import static org.osgi.namespace.service.ServiceNamespace.SERVICE_NAMESPACE;
+import static org.osgi.resource.Namespace.EFFECTIVE_ACTIVE;
+import static org.osgi.service.cdi.CDIConstants.CDI_CAPABILITY_NAME;
+import static org.osgi.service.cdi.CDIConstants.CDI_EXTENSION_PROPERTY;
+import static org.osgi.service.cdi.CDIConstants.CDI_SPECIFICATION_VERSION;
+
+import org.osgi.annotation.bundle.Capability;
+import org.osgi.annotation.bundle.Requirement;
diff --git
a/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/package-info.java
b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/package-info.java
new file mode 100644
index 0000000..198ac72
--- /dev/null
+++ b/johnzon-osgi/src/main/java/org/apache/johnzon/osgi/package-info.java
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+
+@Capability(namespace = SERVICE_NAMESPACE,
+ attribute = {
+ JAX_RS_MEDIA_TYPE + "=" + APPLICATION_JSON,
+
"objectClass:List<String>='javax.ws.rs.ext.MessageBodyReader,javax.ws.rs.ext.MessageBodyWriter'"})
+package org.apache.johnzon.osgi;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+import static org.osgi.namespace.service.ServiceNamespace.SERVICE_NAMESPACE;
+import static
org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_MEDIA_TYPE;
+
+import org.osgi.annotation.bundle.Capability;
diff --git a/pom.xml b/pom.xml
index 68169c0..415f4ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,6 +63,7 @@
<module>johnzon-jsonb</module>
<module>johnzon-json-extras</module>
<module>johnzon-jsonschema</module>
+ <module>johnzon-osgi</module>
</modules>
<dependencyManagement>
diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md
index 3f30aaa..4ed1f0a 100644
--- a/src/site/markdown/index.md
+++ b/src/site/markdown/index.md
@@ -534,3 +534,44 @@ Known limitations are (feel free to do a PR on github to
add these missing featu
* Doesn't support references in the schema
* Doesn't support: dependencies, propertyNames, if/then/else,
allOf/anyOf/oneOf/not, format validations
+
+### OSGi JAX-RS Whiteboard
+
+Though Johnzon artifacts are OSGi bundles to begin with, this module provides
further integration with the [OSGi JAX-RS
Whiteboard](https://osgi.org/specification/osgi.cmpn/7.0.0/service.jaxrs.html)
and [OSGi CDI
Integration](https://osgi.org/specification/osgi.enterprise/7.0.0/service.cdi.html)
specifications.
+
+##### JAX-RS
+
+This module provides `MessageBodyWriter` and `MessageBodyReader` extensions
for the media type `application/json` (by default) to whiteboard JAX-RS
Applications.
+
+Configuration of this extension is managed via Configuration Admin using the
**pid** `org.apache.johnzon.jsonb` and defines a Metatype schema with the
following properties:
+
+| Property | Synopsis | Type | Default |
+| ---- | ------------- | -- | -- |
+| `ignores` | List of fully qualified class names to ignore | String[] | empty
|
+| `osgi.jaxrs.application.select` | Filter expression used to match the
extension to JAX-RS Whiteboard Applications | String |
`(!(johnzon.jsonb=false))` *(which is a convention allowing the extension to
bind to all applications unless the application is configured with
`johnzon.jsonb=false`)* |
+| `osgi.jaxrs.media.type` | List of media types handled by the extension |
String[] | `application/json` |
+| `throw.no.content.exception.on.empty.streams` | | boolean | `false` |
+| `fail.on.unknown.properties` | | boolean | `false` |
+| `use.js.range` | | boolean | `false` |
+| `other.properties` | | String | empty |
+| `ijson` | | boolean | `false` |
+| `encoding` | | String | empty |
+| `binary.datastrategy` | | String | empty |
+| `property.naming.strategy` | | String | empty |
+| `property.order.strategy` | | String | empty |
+| `null.values` | | boolean | `false` |
+| `pretty` | | boolean | `false` |
+| `fail.on.missing.creator.values` | | boolean | `false` |
+| `polymorphic.serialization.predicate` | | String | empty |
+| `polymorphic.deserialization.predicate` | | String | empty |
+| `polymorphic.discriminator` | | String | empty |
+
+##### CDI
+
+Since JSON-B specification provides an integration with the CDI specification
to handle caching, this module also provides such integration for OSGi CDI
Integration specification by providing an
`javax.enterprise.inject.spi.Extension` service with the required service
property `osgi.cdi.extension` with the value `JavaJSONB`.
+
+##### Implicit Extensions
+
+In order to reduce the burden of configuration Apache Aries CDI (the OSGi CDI
Integration RI) provides a feature of implicit extensions. These are extensions
which the developer doesn't have to configure a requirement for in their CDI
bundle. The Johnzon JSON-B CDI extension is such an extension and as such when
running in Aries CDI does not need to be required.
+
+This is achieve using the service property `aries.cdi.extension.mode=implicit`.
\ No newline at end of file