openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1824613 - in /openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave: Meecrowave.java cxf/ConfigurableBus.java cxf/MeecrowaveBus.java
Date Sat, 17 Feb 2018 17:52:55 GMT
Author: rmannibucau
Date: Sat Feb 17 17:52:55 2018
New Revision: 1824613

URL: http://svn.apache.org/viewvc?rev=1824613&view=rev
Log:
creating a default global bus in case there is not at startup to avoid the server one to be
the one used by clients

Added:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java?rev=1824613&r1=1824612&r2=1824613&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/Meecrowave.java
Sat Feb 17 17:52:55 2018
@@ -61,7 +61,6 @@ import java.util.concurrent.atomic.Atomi
 import java.util.function.BiPredicate;
 import java.util.function.Consumer;
 import java.util.function.Function;
-import java.util.function.Predicate;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 
@@ -97,10 +96,12 @@ import org.apache.catalina.startup.Tomca
 import org.apache.commons.lang3.text.StrLookup;
 import org.apache.commons.lang3.text.StrSubstitutor;
 import org.apache.coyote.http2.Http2Protocol;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.johnzon.core.BufferStrategy;
 import org.apache.meecrowave.api.StartListening;
 import org.apache.meecrowave.api.StopListening;
+import org.apache.meecrowave.cxf.ConfigurableBus;
 import org.apache.meecrowave.cxf.CxfCdiAutoSetup;
 import org.apache.meecrowave.io.IO;
 import org.apache.meecrowave.logging.jul.Log4j2Logger;
@@ -137,6 +138,7 @@ public class Meecrowave implements AutoC
     }
 
     private final Builder configuration;
+    protected ConfigurableBus clientBus;
     protected File base;
     protected final File ownedTempDir;
     protected InternalTomcat tomcat;
@@ -149,6 +151,7 @@ public class Meecrowave implements AutoC
 
     public Meecrowave() {
         this(new Builder());
+        this.clientBus = new ConfigurableBus();
     }
 
     public Meecrowave(final Builder builder) {
@@ -648,6 +651,13 @@ public class Meecrowave implements AutoC
 
         beforeStart();
 
+
+        if (configuration.initializeClientBus && BusFactory.getDefaultBus(false)
== null) {
+            clientBus.initProviders(configuration,
+                    ofNullable(Thread.currentThread().getContextClassLoader()).orElseGet(ClassLoader::getSystemClassLoader));
+            BusFactory.setDefaultBus(clientBus);
+        }
+
         try {
             if (!initialized) {
                 tomcat.init();
@@ -857,6 +867,9 @@ public class Meecrowave implements AutoC
                 new LogFacade(Meecrowave.class.getName()).error(e.getMessage(), e);
             }
         }
+        if (BusFactory.getDefaultBus(false) == clientBus) {
+            BusFactory.setDefaultBus(null);
+        }
         try {
             contexts.values().forEach(Runnable::run);
         } finally {
@@ -1226,6 +1239,9 @@ public class Meecrowave implements AutoC
         @CliOption(name = "default-ssl-hostconfig-name", description = "The name of the default
SSLHostConfig that will be used for secure https connections.")
         private String defaultSSLHostConfigName;
 
+        @CliOption(name = "cxf-initialize-client-bus", description = "Should the client bus
be set. If false the server one will likely be reused.")
+        private boolean initializeClientBus;
+
         private final Map<Class<?>, Object> extensions = new HashMap<>();
         private final Collection<Consumer<Tomcat>> instanceCustomizers = new
ArrayList<>();
 
@@ -1248,6 +1264,14 @@ public class Meecrowave implements AutoC
             }));
         }
 
+        public boolean isInitializeClientBus() {
+            return initializeClientBus;
+        }
+
+        public void setInitializeClientBus(final boolean initializeClientBus) {
+            this.initializeClientBus = initializeClientBus;
+        }
+
         public boolean isJaxwsSupportIfAvailable() {
             return jaxwsSupportIfAvailable;
         }

Added: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java?rev=1824613&view=auto
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
(added)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
Sat Feb 17 17:52:55 2018
@@ -0,0 +1,365 @@
+/*
+ * 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.meecrowave.cxf;
+
+import static java.util.Optional.of;
+import static java.util.Optional.ofNullable;
+import static java.util.stream.Collectors.toList;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.json.JsonArray;
+import javax.json.JsonArrayBuilder;
+import javax.json.JsonBuilderFactory;
+import javax.json.JsonMergePatch;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+import javax.json.JsonObjectBuilder;
+import javax.json.JsonPatch;
+import javax.json.JsonPatchBuilder;
+import javax.json.JsonPointer;
+import javax.json.JsonReader;
+import javax.json.JsonReaderFactory;
+import javax.json.JsonString;
+import javax.json.JsonStructure;
+import javax.json.JsonValue;
+import javax.json.JsonWriter;
+import javax.json.JsonWriterFactory;
+import javax.json.bind.Jsonb;
+import javax.json.bind.JsonbBuilder;
+import javax.json.spi.JsonProvider;
+import javax.json.stream.JsonGenerator;
+import javax.json.stream.JsonGeneratorFactory;
+import javax.json.stream.JsonParser;
+import javax.json.stream.JsonParserFactory;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.johnzon.core.AbstractJsonFactory;
+import org.apache.johnzon.core.JsonGeneratorFactoryImpl;
+import org.apache.johnzon.core.JsonParserFactoryImpl;
+import org.apache.johnzon.jaxrs.DelegateProvider;
+import org.apache.johnzon.jaxrs.JsrMessageBodyReader;
+import org.apache.johnzon.jaxrs.JsrMessageBodyWriter;
+import org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider;
+import org.apache.meecrowave.Meecrowave;
+
+public class ConfigurableBus extends ExtensionManagerBus {
+    public void initProviders(final Meecrowave.Builder builder,
+                              final ClassLoader loader) {
+        final List<Object> providers =
+                ofNullable(builder.getJaxrsDefaultProviders())
+                        .map(s -> Stream.of(s.split(" *, *"))
+                                .map(String::trim)
+                                .filter(p -> !p.isEmpty())
+                                .map(name -> {
+                                    try {
+                                        return Thread.currentThread().getContextClassLoader().loadClass(name).newInstance();
+                                    } catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
+                                        throw new IllegalArgumentException(name + " can't
be created");
+                                    }
+                                })
+                                .collect(Collectors.<Object>toList()))
+                        .orElseGet(() -> {
+                            // ensure both providers share the same memory reuse logic
+                            final JsonProvider provider = JsonProvider.provider();
+                            final JsonReaderFactory readerFactory = provider.createReaderFactory(
+                                    new HashMap<String, Object>() {{
+                                        put(JsonParserFactoryImpl.SUPPORTS_COMMENTS, builder.isJsonpSupportsComment());
+                                        of(builder.getJsonpMaxStringLen()).filter(v ->
v > 0)
+                                                .ifPresent(s -> put(JsonParserFactoryImpl.MAX_STRING_LENGTH,
+                                                        s));
+                                        of(builder.getJsonpMaxReadBufferLen()).filter(v ->
v > 0)
+                                                .ifPresent(s -> put(JsonParserFactoryImpl.BUFFER_LENGTH,
+                                                        s));
+                                        ofNullable(builder.getJsonpBufferStrategy()).ifPresent(
+                                                s -> put(AbstractJsonFactory.BUFFER_STRATEGY,
s));
+                                    }});
+                            final JsonWriterFactory writerFactory = provider.createWriterFactory(
+                                    new HashMap<String, Object>() {{
+                                        put(JsonGenerator.PRETTY_PRINTING, builder.isJsonpPrettify());
+                                        of(builder.getJsonpMaxWriteBufferLen()).filter(v
-> v > 0)
+                                                .ifPresent(v -> put(
+                                                        JsonGeneratorFactoryImpl
+                                                                .GENERATOR_BUFFER_LENGTH,
+                                                        v));
+                                        ofNullable(builder.getJsonpBufferStrategy()).ifPresent(
+                                                s -> put(AbstractJsonFactory.BUFFER_STRATEGY,
s));
+                                    }});
+                            return Stream.<Object>of(
+                                    new ConfiguredJsonbJaxrsProvider(
+                                            builder.getJsonbEncoding(), builder.isJsonbNulls(),
+                                            builder.isJsonbIJson(), builder.isJsonbPrettify(),
+                                            builder.getJsonbBinaryStrategy(), builder.getJsonbNamingStrategy(),
+                                            builder.getJsonbOrderStrategy(),
+                                            new DelegateJsonProvider(provider, readerFactory,
writerFactory)),
+                                    new ConfiguredJsrProvider(readerFactory, writerFactory))
+                                    .collect(toList());
+                        });
+
+        if (builder.isJaxrsAutoActivateBeanValidation()) {
+            try { // we don't need the jaxrsbeanvalidationfeature since bean validation cdi
extension handles it normally
+                loader.loadClass("javax.validation.Validation");
+                final Object instance = loader.loadClass("org.apache.cxf.jaxrs.validation.ValidationExceptionMapper")
+                        .getConstructor().newInstance();
+                instance.getClass().getGenericInterfaces(); // validate bval can be used,
check NoClassDefFoundError javax.validation.ValidationException
+                providers.add(instance);
+            } catch (final Exception | NoClassDefFoundError e) {
+                // no-op
+            }
+        }
+
+        // client
+        if (getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {
+            setProperty("skip.default.json.provider.registration", "true");
+            setProperty("org.apache.cxf.jaxrs.bus.providers", providers);
+        }
+    }
+
+    @Provider
+    @Produces({MediaType.APPLICATION_JSON, "*/*+json"})
+    @Consumes({MediaType.APPLICATION_JSON, "*/*+json"})
+    public static class ConfiguredJsonbJaxrsProvider<T> extends JsonbJaxrsProvider<T>
{
+        private final JsonProvider provider;
+
+        private ConfiguredJsonbJaxrsProvider(final String encoding,
+                                             final boolean nulls,
+                                             final boolean iJson,
+                                             final boolean pretty,
+                                             final String binaryStrategy,
+                                             final String namingStrategy,
+                                             final String orderStrategy,
+                                             final JsonProvider provider) {
+            // ATTENTION this is only a workaround for MEECROWAVE-49 and shall get removed
after Johnzon has a fix for it!
+            // We add byte[] to the ignored types.
+            super(Arrays.asList("[B"));
+            this.provider = provider;
+            ofNullable(encoding).ifPresent(this::setEncoding);
+            ofNullable(namingStrategy).ifPresent(this::setPropertyNamingStrategy);
+            ofNullable(orderStrategy).ifPresent(this::setPropertyOrderStrategy);
+            ofNullable(binaryStrategy).ifPresent(this::setBinaryDataStrategy);
+            setNullValues(nulls);
+            setIJson(iJson);
+            setPretty(pretty);
+        }
+
+        protected Jsonb createJsonb() {
+            return JsonbBuilder.newBuilder()
+                    .withProvider(provider)
+                    .withConfig(config).build();
+        }
+    }
+
+    @Provider
+    @Produces({MediaType.APPLICATION_JSON, "application/*+json"})
+    @Consumes({MediaType.APPLICATION_JSON, "application/*+json"})
+    public static class ConfiguredJsrProvider extends DelegateProvider<JsonStructure>
{ // TODO: probably wire the encoding in johnzon
+        private ConfiguredJsrProvider(final JsonReaderFactory readerFactory,
+                                      final JsonWriterFactory writerFactory) {
+            super(new JsrMessageBodyReader(readerFactory, false), new JsrMessageBodyWriter(writerFactory,
false));
+        }
+    }
+
+    private static class DelegateJsonProvider extends JsonProvider {
+        private final JsonReaderFactory readerFactory;
+        private final JsonWriterFactory writerFactory;
+        private final JsonProvider provider;
+
+        private DelegateJsonProvider(final JsonProvider provider, final JsonReaderFactory
readerFactory, final JsonWriterFactory writerFactory) {
+            this.provider = provider;
+            this.readerFactory = readerFactory;
+            this.writerFactory = writerFactory;
+        }
+
+        @Override
+        public JsonWriterFactory createWriterFactory(final Map<String, ?> config) {
+            return writerFactory;
+        }
+
+        @Override
+        public JsonReaderFactory createReaderFactory(final Map<String, ?> config) {
+            return readerFactory;
+        }
+
+        @Override
+        public JsonParser createParser(final Reader reader) {
+            return provider.createParser(reader);
+        }
+
+        @Override
+        public JsonParser createParser(final InputStream in) {
+            return provider.createParser(in);
+        }
+
+        @Override
+        public JsonParserFactory createParserFactory(final Map<String, ?> config) {
+            return provider.createParserFactory(config);
+        }
+
+        @Override
+        public JsonGenerator createGenerator(final Writer writer) {
+            return provider.createGenerator(writer);
+        }
+
+        @Override
+        public JsonGenerator createGenerator(final OutputStream out) {
+            return provider.createGenerator(out);
+        }
+
+        @Override
+        public JsonGeneratorFactory createGeneratorFactory(final Map<String, ?> config)
{
+            return provider.createGeneratorFactory(config);
+        }
+
+        @Override
+        public JsonReader createReader(final Reader reader) {
+            return provider.createReader(reader);
+        }
+
+        @Override
+        public JsonReader createReader(final InputStream in) {
+            return provider.createReader(in);
+        }
+
+        @Override
+        public JsonWriter createWriter(final Writer writer) {
+            return provider.createWriter(writer);
+        }
+
+        @Override
+        public JsonWriter createWriter(final OutputStream out) {
+            return provider.createWriter(out);
+        }
+
+        @Override
+        public JsonObjectBuilder createObjectBuilder() {
+            return provider.createObjectBuilder();
+        }
+
+        @Override
+        public JsonObjectBuilder createObjectBuilder(final JsonObject jsonObject) {
+            return provider.createObjectBuilder(jsonObject);
+        }
+
+        @Override
+        public JsonObjectBuilder createObjectBuilder(final Map<String, Object> map)
{
+            return provider.createObjectBuilder(map);
+        }
+
+        @Override
+        public JsonArrayBuilder createArrayBuilder() {
+            return provider.createArrayBuilder();
+        }
+
+        @Override
+        public JsonArrayBuilder createArrayBuilder(final JsonArray initialData) {
+            return provider.createArrayBuilder(initialData);
+        }
+
+        @Override
+        public JsonArrayBuilder createArrayBuilder(final Collection<?> initialData)
{
+            return provider.createArrayBuilder(initialData);
+        }
+
+        @Override
+        public JsonPointer createPointer(final String path) {
+            return provider.createPointer(path);
+        }
+
+        @Override
+        public JsonBuilderFactory createBuilderFactory(final Map<String, ?> config)
{
+            return provider.createBuilderFactory(config);
+        }
+
+        @Override
+        public JsonString createValue(final String value) {
+            return provider.createValue(value);
+        }
+
+        @Override
+        public JsonNumber createValue(final int value) {
+            return provider.createValue(value);
+        }
+
+        @Override
+        public JsonNumber createValue(final long value) {
+            return provider.createValue(value);
+        }
+
+        @Override
+        public JsonNumber createValue(final double value) {
+            return provider.createValue(value);
+        }
+
+        @Override
+        public JsonNumber createValue(final BigDecimal value) {
+            return provider.createValue(value);
+        }
+
+        @Override
+        public JsonNumber createValue(final BigInteger value) {
+            return provider.createValue(value);
+        }
+
+        @Override
+        public JsonPatch createPatch(final JsonArray array) {
+            return provider.createPatch(array);
+        }
+
+        @Override
+        public JsonPatch createDiff(final JsonStructure source, final JsonStructure target)
{
+            return provider.createDiff(source, target);
+        }
+
+        @Override
+        public JsonPatchBuilder createPatchBuilder() {
+            return provider.createPatchBuilder();
+        }
+
+        @Override
+        public JsonPatchBuilder createPatchBuilder(final JsonArray initialData) {
+            return provider.createPatchBuilder(initialData);
+        }
+
+        @Override
+        public JsonMergePatch createMergePatch(final JsonValue patch) {
+            return provider.createMergePatch(patch);
+        }
+
+        @Override
+        public JsonMergePatch createMergeDiff(final JsonValue source, final JsonValue target)
{
+            return provider.createMergeDiff(source, target);
+        }
+    }
+}

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java?rev=1824613&r1=1824612&r2=1824613&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
Sat Feb 17 17:52:55 2018
@@ -1,75 +1,25 @@
 package org.apache.meecrowave.cxf;
 
-import org.apache.cxf.Bus;
-import org.apache.cxf.bus.extension.ExtensionManagerBus;
-import org.apache.cxf.common.util.ClassUnwrapper;
-import org.apache.cxf.feature.Feature;
-import org.apache.cxf.interceptor.Interceptor;
-import org.apache.cxf.message.Message;
-import org.apache.johnzon.core.AbstractJsonFactory;
-import org.apache.johnzon.core.JsonGeneratorFactoryImpl;
-import org.apache.johnzon.core.JsonParserFactoryImpl;
-import org.apache.johnzon.jaxrs.DelegateProvider;
-import org.apache.johnzon.jaxrs.JsrMessageBodyReader;
-import org.apache.johnzon.jaxrs.JsrMessageBodyWriter;
-import org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider;
-import org.apache.meecrowave.Meecrowave;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
 
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.json.JsonArray;
-import javax.json.JsonArrayBuilder;
-import javax.json.JsonBuilderFactory;
-import javax.json.JsonMergePatch;
-import javax.json.JsonNumber;
-import javax.json.JsonObject;
-import javax.json.JsonObjectBuilder;
-import javax.json.JsonPatch;
-import javax.json.JsonPatchBuilder;
-import javax.json.JsonPointer;
-import javax.json.JsonReader;
-import javax.json.JsonReaderFactory;
-import javax.json.JsonString;
-import javax.json.JsonStructure;
-import javax.json.JsonValue;
-import javax.json.JsonWriter;
-import javax.json.JsonWriterFactory;
-import javax.json.bind.Jsonb;
-import javax.json.bind.JsonbBuilder;
-import javax.json.spi.JsonProvider;
-import javax.json.stream.JsonGenerator;
-import javax.json.stream.JsonGeneratorFactory;
-import javax.json.stream.JsonParser;
-import javax.json.stream.JsonParserFactory;
 import javax.servlet.ServletContext;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.ext.Provider;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
 
-import static java.util.Optional.of;
-import static java.util.Optional.ofNullable;
-import static java.util.stream.Collectors.toList;
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.util.ClassUnwrapper;
+import org.apache.cxf.feature.Feature;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Message;
+import org.apache.meecrowave.Meecrowave;
 
 @Named("cxf")
 @ApplicationScoped
 public class MeecrowaveBus implements Bus {
-    private final Bus delegate = new ExtensionManagerBus();
+    private final ConfigurableBus delegate = new ConfigurableBus();
 
     protected MeecrowaveBus() {
         // no-op: for proxies
@@ -79,78 +29,12 @@ public class MeecrowaveBus implements Bu
     public MeecrowaveBus(final ServletContext context) {
         setProperty(ClassUnwrapper.class.getName(), (ClassUnwrapper) this::getRealClass);
 
-        //X broken, breaks Paralell Tomcat classloader setExtension(contextClassLoader, ClassLoader.class);
// ServletController locks on the classloader otherwise
+        final ClassLoader appLoader = context.getClassLoader();
+        setExtension(appLoader, ClassLoader.class); // ServletController locks on the classloader
otherwise
 
         final Meecrowave.Builder builder = Meecrowave.Builder.class.cast(context.getAttribute("meecrowave.configuration"));
         if (builder != null && builder.isJaxrsProviderSetup()) {
-            final List<Object> providers =
-                    ofNullable(builder.getJaxrsDefaultProviders())
-                            .map(s -> Stream.of(s.split(" *, *"))
-                                    .map(String::trim)
-                                    .filter(p -> !p.isEmpty())
-                                    .map(name -> {
-                                        try {
-                                            return Thread.currentThread().getContextClassLoader().loadClass(name).newInstance();
-                                        } catch (InstantiationException | IllegalAccessException
| ClassNotFoundException e) {
-                                            throw new IllegalArgumentException(name + " can't
be created");
-                                        }
-                                    })
-                                    .collect(Collectors.<Object>toList()))
-                            .orElseGet(() -> {
-                                // ensure both providers share the same memory reuse logic
-                                final JsonProvider provider = JsonProvider.provider();
-                                final JsonReaderFactory readerFactory = provider.createReaderFactory(
-                                        new HashMap<String, Object>() {{
-                                            put(JsonParserFactoryImpl.SUPPORTS_COMMENTS,
builder.isJsonpSupportsComment());
-                                            of(builder.getJsonpMaxStringLen()).filter(v ->
v > 0)
-                                                            .ifPresent(s -> put(JsonParserFactoryImpl.MAX_STRING_LENGTH,
-                                                                    s));
-                                            of(builder.getJsonpMaxReadBufferLen()).filter(v
-> v > 0)
-                                                                .ifPresent(s -> put(JsonParserFactoryImpl.BUFFER_LENGTH,
-                                                                        s));
-                                            ofNullable(builder.getJsonpBufferStrategy()).ifPresent(
-                                                    s -> put(AbstractJsonFactory.BUFFER_STRATEGY,
s));
-                                        }});
-                                final JsonWriterFactory writerFactory = provider.createWriterFactory(
-                                        new HashMap<String, Object>() {{
-                                            put(JsonGenerator.PRETTY_PRINTING, builder.isJsonpPrettify());
-                                            of(builder.getJsonpMaxWriteBufferLen()).filter(v
-> v > 0)
-                                                                 .ifPresent(v -> put(
-                                                                         JsonGeneratorFactoryImpl
-                                                                                 .GENERATOR_BUFFER_LENGTH,
-                                                                         v));
-                                            ofNullable(builder.getJsonpBufferStrategy()).ifPresent(
-                                                    s -> put(AbstractJsonFactory.BUFFER_STRATEGY,
s));
-                                        }});
-                                return Stream.<Object>of(
-                                        new ConfiguredJsonbJaxrsProvider(
-                                                builder.getJsonbEncoding(), builder.isJsonbNulls(),
-                                                builder.isJsonbIJson(), builder.isJsonbPrettify(),
-                                                builder.getJsonbBinaryStrategy(), builder.getJsonbNamingStrategy(),
-                                                builder.getJsonbOrderStrategy(),
-                                                new DelegateJsonProvider(provider, readerFactory,
writerFactory)),
-                                        new ConfiguredJsrProvider(readerFactory, writerFactory))
-                                        .collect(toList());
-                            });
-
-            if (builder.isJaxrsAutoActivateBeanValidation()) {
-                try { // we don't need the jaxrsbeanvalidationfeature since bean validation
cdi extension handles it normally
-                    final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
-                    contextClassLoader.loadClass("javax.validation.Validation");
-                    final Object instance = contextClassLoader.loadClass("org.apache.cxf.jaxrs.validation.ValidationExceptionMapper")
-                                                       .getConstructor().newInstance();
-                    instance.getClass().getGenericInterfaces(); // validate bval can be used,
check NoClassDefFoundError javax.validation.ValidationException
-                    providers.add(instance);
-                } catch (final Exception | NoClassDefFoundError e) {
-                    // no-op
-                }
-            }
-
-            // client
-            if (getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {
-                setProperty("skip.default.json.provider.registration", "true");
-                setProperty("org.apache.cxf.jaxrs.bus.providers", providers);
-            }
+            delegate.initProviders(builder, appLoader);
         }
     }
 
@@ -267,220 +151,4 @@ public class MeecrowaveBus implements Bu
     public List<Interceptor<? extends Message>> getOutFaultInterceptors() {
         return delegate.getOutFaultInterceptors();
     }
-
-    @Provider
-    @Produces({MediaType.APPLICATION_JSON, "*/*+json"})
-    @Consumes({MediaType.APPLICATION_JSON, "*/*+json"})
-    public static class ConfiguredJsonbJaxrsProvider<T> extends JsonbJaxrsProvider<T>
{
-        private final JsonProvider provider;
-
-        private ConfiguredJsonbJaxrsProvider(final String encoding,
-                                             final boolean nulls,
-                                             final boolean iJson,
-                                             final boolean pretty,
-                                             final String binaryStrategy,
-                                             final String namingStrategy,
-                                             final String orderStrategy,
-                                             final JsonProvider provider) {
-            // ATTENTION this is only a workaround for MEECROWAVE-49 and shall get removed
after Johnzon has a fix for it!
-            // We add byte[] to the ignored types.
-            super(Arrays.asList("[B"));
-            this.provider = provider;
-            ofNullable(encoding).ifPresent(this::setEncoding);
-            ofNullable(namingStrategy).ifPresent(this::setPropertyNamingStrategy);
-            ofNullable(orderStrategy).ifPresent(this::setPropertyOrderStrategy);
-            ofNullable(binaryStrategy).ifPresent(this::setBinaryDataStrategy);
-            setNullValues(nulls);
-            setIJson(iJson);
-            setPretty(pretty);
-        }
-
-        protected Jsonb createJsonb() {
-            return JsonbBuilder.newBuilder()
-                               .withProvider(provider)
-                               .withConfig(config).build();
-        }
-    }
-
-    @Provider
-    @Produces({MediaType.APPLICATION_JSON, "application/*+json"})
-    @Consumes({MediaType.APPLICATION_JSON, "application/*+json"})
-    public static class ConfiguredJsrProvider extends DelegateProvider<JsonStructure>
{ // TODO: probably wire the encoding in johnzon
-        private ConfiguredJsrProvider(final JsonReaderFactory readerFactory,
-                                      final JsonWriterFactory writerFactory) {
-            super(new JsrMessageBodyReader(readerFactory, false), new JsrMessageBodyWriter(writerFactory,
false));
-        }
-    }
-
-    private static class DelegateJsonProvider extends JsonProvider {
-        private final JsonReaderFactory readerFactory;
-        private final JsonWriterFactory writerFactory;
-        private final JsonProvider provider;
-
-        private DelegateJsonProvider(final JsonProvider provider, final JsonReaderFactory
readerFactory, final JsonWriterFactory writerFactory) {
-            this.provider = provider;
-            this.readerFactory = readerFactory;
-            this.writerFactory = writerFactory;
-        }
-
-        @Override
-        public JsonWriterFactory createWriterFactory(final Map<String, ?> config) {
-            return writerFactory;
-        }
-
-        @Override
-        public JsonReaderFactory createReaderFactory(final Map<String, ?> config) {
-            return readerFactory;
-        }
-
-        @Override
-        public JsonParser createParser(final Reader reader) {
-            return provider.createParser(reader);
-        }
-
-        @Override
-        public JsonParser createParser(final InputStream in) {
-            return provider.createParser(in);
-        }
-
-        @Override
-        public JsonParserFactory createParserFactory( final Map<String, ?> config)
{
-            return provider.createParserFactory(config);
-        }
-
-        @Override
-        public JsonGenerator createGenerator(final Writer writer) {
-            return provider.createGenerator(writer);
-        }
-
-        @Override
-        public JsonGenerator createGenerator(final OutputStream out) {
-            return provider.createGenerator(out);
-        }
-
-        @Override
-        public JsonGeneratorFactory createGeneratorFactory(final Map<String, ?> config)
{
-            return provider.createGeneratorFactory(config);
-        }
-
-        @Override
-        public JsonReader createReader(final Reader reader) {
-            return provider.createReader(reader);
-        }
-
-        @Override
-        public JsonReader createReader(final InputStream in) {
-            return provider.createReader(in);
-        }
-
-        @Override
-        public JsonWriter createWriter(final Writer writer) {
-            return provider.createWriter(writer);
-        }
-
-        @Override
-        public JsonWriter createWriter(final OutputStream out) {
-            return provider.createWriter(out);
-        }
-
-        @Override
-        public JsonObjectBuilder createObjectBuilder() {
-            return provider.createObjectBuilder();
-        }
-
-        @Override
-        public JsonObjectBuilder createObjectBuilder(final JsonObject jsonObject) {
-            return provider.createObjectBuilder(jsonObject);
-        }
-
-        @Override
-        public JsonObjectBuilder createObjectBuilder(final Map<String, Object> map)
{
-            return provider.createObjectBuilder(map);
-        }
-
-        @Override
-        public JsonArrayBuilder createArrayBuilder() {
-            return provider.createArrayBuilder();
-        }
-
-        @Override
-        public JsonArrayBuilder createArrayBuilder(final JsonArray initialData) {
-            return provider.createArrayBuilder(initialData);
-        }
-
-        @Override
-        public JsonArrayBuilder createArrayBuilder(final Collection<?> initialData)
{
-            return provider.createArrayBuilder(initialData);
-        }
-
-        @Override
-        public JsonPointer createPointer(final String path) {
-            return provider.createPointer(path);
-        }
-
-        @Override
-        public JsonBuilderFactory createBuilderFactory(final Map<String, ?> config)
{
-            return provider.createBuilderFactory(config);
-        }
-
-        @Override
-        public JsonString createValue(final String value) {
-            return provider.createValue(value);
-        }
-
-        @Override
-        public JsonNumber createValue(final int value) {
-            return provider.createValue(value);
-        }
-
-        @Override
-        public JsonNumber createValue(final long value) {
-            return provider.createValue(value);
-        }
-
-        @Override
-        public JsonNumber createValue(final double value) {
-            return provider.createValue(value);
-        }
-
-        @Override
-        public JsonNumber createValue(final BigDecimal value) {
-            return provider.createValue(value);
-        }
-
-        @Override
-        public JsonNumber createValue(final BigInteger value) {
-            return provider.createValue(value);
-        }
-
-        @Override
-        public JsonPatch createPatch(final JsonArray array) {
-            return provider.createPatch(array);
-        }
-
-        @Override
-        public JsonPatch createDiff(final JsonStructure source, final JsonStructure target)
{
-            return provider.createDiff(source, target);
-        }
-
-        @Override
-        public JsonPatchBuilder createPatchBuilder() {
-            return provider.createPatchBuilder();
-        }
-
-        @Override
-        public JsonPatchBuilder createPatchBuilder(final JsonArray initialData) {
-            return provider.createPatchBuilder(initialData);
-        }
-
-        @Override
-        public JsonMergePatch createMergePatch(final JsonValue patch) {
-            return provider.createMergePatch(patch);
-        }
-
-        @Override
-        public JsonMergePatch createMergeDiff(final JsonValue source, final JsonValue target)
{
-            return provider.createMergeDiff(source, target);
-        }
-    }
 }



Mime
View raw message