Skip to content
Browse files
adding a cxf workaround until we get a new cxf release
  • Loading branch information
rmannibucau committed May 22, 2018
1 parent 1e3ee3f commit d983f47406f530e2565a075640063104b466d6d1
Showing 1 changed file with 63 additions and 0 deletions.
@@ -0,0 +1,63 @@
package org.apache.geronimo.microprofile.opentracing.tck.setup;

import static;

import java.lang.reflect.Field;
import java.util.Map;

import javax.enterprise.context.ApplicationScoped;

import org.apache.cxf.cdi.extension.JAXRSServerFactoryCustomizationExtension;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
import org.apache.cxf.message.Message;

public class CxfCdiWorkaround implements JAXRSServerFactoryCustomizationExtension {
public void customize(final JAXRSServerFactoryBean bean) {
final Map<Class<?>, ResourceProvider> providers = getProviders(bean);
final Map<Class<?>, ResourceProvider> workaround = providers.entrySet().stream()
.collect(toMap(Map.Entry::getKey, e -> new WorkaroundProvider(e.getValue())));

private Map<Class<?>, ResourceProvider> getProviders(final JAXRSServerFactoryBean bean) {
try {
final Field f = JAXRSServerFactoryBean.class.getDeclaredField("resourceProviders");
return (Map<Class<?>, ResourceProvider>) f.get(bean);
} catch (final Exception e) {
throw new IllegalStateException(e);

private static class WorkaroundProvider implements ResourceProvider {
private final ResourceProvider delegate;

private WorkaroundProvider(final ResourceProvider value) {
this.delegate = value;

public Object getInstance(final Message m) {
return delegate.getInstance(m);

public void releaseInstance(final Message m, final Object o) {
// no-op: don't release otherwise we are not thread safe for @Dependent, this leaks but ok in *this* context

public Class<?> getResourceClass() {
return delegate.getResourceClass();

public boolean isSingleton() {
return true;

0 comments on commit d983f47

Please sign in to comment.