You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2018/07/01 13:35:24 UTC
svn commit: r1834792 - in /openwebbeans/meecrowave/trunk/meecrowave-core/src:
main/java/org/apache/meecrowave/cxf/ test/java/org/apache/meecrowave/cxf/
Author: rmannibucau
Date: Sun Jul 1 13:35:24 2018
New Revision: 1834792
URL: http://svn.apache.org/viewvc?rev=1834792&view=rev
Log:
fixing johnzon autocleanup after upgrade
Modified:
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListener.java
openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListenerTest.java
Modified: 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=1834792&r1=1834791&r2=1834792&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/ConfigurableBus.java Sun Jul 1 13:35:24 2018
@@ -162,7 +162,7 @@ public class ConfigurableBus extends Ext
@Produces({MediaType.APPLICATION_JSON, "*/*+json"})
@Consumes({MediaType.APPLICATION_JSON, "*/*+json"})
public static class ConfiguredJsonbJaxrsProvider<T> extends JsonbJaxrsProvider<T> {
- private final JsonProvider provider;
+ private final Jsonb jsonb;
private ConfiguredJsonbJaxrsProvider(final String encoding,
final boolean nulls,
@@ -175,7 +175,6 @@ public class ConfigurableBus extends Ext
// 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(singletonList("[B"));
- this.provider = provider;
ofNullable(encoding).ifPresent(this::setEncoding);
ofNullable(namingStrategy).ifPresent(this::setPropertyNamingStrategy);
ofNullable(orderStrategy).ifPresent(this::setPropertyOrderStrategy);
@@ -183,13 +182,15 @@ public class ConfigurableBus extends Ext
setNullValues(nulls);
setIJson(iJson);
setPretty(pretty);
+ this.jsonb = JsonbBuilder.newBuilder()
+ .withProvider(provider)
+ .withConfig(config)
+ .build();
}
@Override
protected Jsonb createJsonb() {
- return JsonbBuilder.newBuilder()
- .withProvider(provider)
- .withConfig(config).build();
+ return jsonb;
}
}
Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListener.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListener.java?rev=1834792&r1=1834791&r2=1834792&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListener.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListener.java Sun Jul 1 13:35:24 2018
@@ -22,10 +22,8 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Objects;
-import java.util.concurrent.atomic.AtomicReference;
import javax.enterprise.inject.spi.CDI;
-import javax.json.bind.Jsonb;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.ClientLifeCycleListener;
@@ -42,6 +40,7 @@ import org.apache.meecrowave.logging.tom
public class MeecrowaveClientLifecycleListener implements ClientLifeCycleListener {
private final Method getReadersWriters;
private final Field delegate;
+ private final Field instance;
public MeecrowaveClientLifecycleListener() {
try {
@@ -56,6 +55,12 @@ public class MeecrowaveClientLifecycleLi
} catch (final NoSuchFieldException e) {
throw new IllegalArgumentException("Incompatible johnzon version detected", e);
}
+ try {
+ instance = JsonbJaxrsProvider.class.getClassLoader().loadClass("org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider$ProvidedInstance").getDeclaredField("instance");
+ instance.setAccessible(true);
+ } catch (final ClassNotFoundException | NoSuchFieldException e) {
+ throw new IllegalArgumentException("Incompatible johnzon version detected", e);
+ }
}
@Override
@@ -75,7 +80,7 @@ public class MeecrowaveClientLifecycleLi
.map(JsonbJaxrsProvider.class::cast)
.map(p -> {
try {
- return ((AtomicReference<Jsonb>) delegate.get(p)).get();
+ return instance.get(delegate.get(p));
} catch (final IllegalAccessException e) {
throw new IllegalStateException(e);
}
Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListenerTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListenerTest.java?rev=1834792&r1=1834791&r2=1834792&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListenerTest.java (original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/test/java/org/apache/meecrowave/cxf/MeecrowaveClientLifecycleListenerTest.java Sun Jul 1 13:35:24 2018
@@ -20,7 +20,6 @@ package org.apache.meecrowave.cxf;
import static org.junit.Assert.assertEquals;
-import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Collection;
@@ -41,11 +40,10 @@ import org.junit.Test;
public class MeecrowaveClientLifecycleListenerTest {
@Test
- public void autoClose() throws IOException, NoSuchFieldException, IllegalAccessException {
+ public void autoClose() throws NoSuchFieldException, IllegalAccessException {
try (final Meecrowave meecrowave = new Meecrowave(new Meecrowave.Builder()
.randomHttpPort()
.includePackages(MeecrowaveClientLifecycleListenerTest.class.getName())).bake()) {
- final JohnzonCdiExtension johnzonCdiExtension = CDI.current().select(JohnzonCdiExtension.class).get();
final Field jsonbs = JohnzonCdiExtension.class.getDeclaredField("jsonbs");
jsonbs.setAccessible(true);
final BeanManager beanManager = CDI.current().getBeanManager();