cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [cxf] Diff for: [GitHub] coheigea merged pull request #487: Ensure JAXB and javax.activation are not required for JAX-RS
Date Tue, 15 Jan 2019 20:35:57 GMT
diff --git a/core/src/main/java/org/apache/cxf/service/model/EndpointInfo.java b/core/src/main/java/org/apache/cxf/service/model/EndpointInfo.java
index 9d5dcc298e5..90c054aad88 100644
--- a/core/src/main/java/org/apache/cxf/service/model/EndpointInfo.java
+++ b/core/src/main/java/org/apache/cxf/service/model/EndpointInfo.java
@@ -21,8 +21,8 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.cxf.ws.addressing.AttributedURIType;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
-import org.apache.cxf.ws.addressing.EndpointReferenceUtils;
 
 /**
  * The EndpointInfo contains the information for a web service 'port' inside of a service.
@@ -94,9 +94,17 @@ public String getAddress() {
 
     public void setAddress(String addr) {
         if (null == address) {
-            address = EndpointReferenceUtils.getEndpointReference(addr);
+            // address = EndpointReferenceUtils.getEndpointReference(addr); loads jaxb and
we want to avoid it
+            final EndpointReferenceType reference = new EndpointReferenceType();
+            final AttributedURIType a = new AttributedURIType();
+            a.setValue(addr);
+            reference.setAddress(a);
+            address = reference;
         } else {
-            EndpointReferenceUtils.setAddress(address, addr);
+            final AttributedURIType a = new AttributedURIType();
+            a.setValue(addr);
+            address.setAddress(a);
+            // EndpointReferenceUtils.setAddress(address, addr);
         }
     }
 
diff --git a/core/src/main/java/org/apache/cxf/transport/AbstractDestination.java b/core/src/main/java/org/apache/cxf/transport/AbstractDestination.java
index 91abb63a853..e7e89ec49cf 100644
--- a/core/src/main/java/org/apache/cxf/transport/AbstractDestination.java
+++ b/core/src/main/java/org/apache/cxf/transport/AbstractDestination.java
@@ -25,6 +25,7 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.ws.addressing.AttributedURIType;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.ws.addressing.EndpointReferenceUtils;
 
@@ -95,7 +96,7 @@ public void shutdown() {
     protected abstract class AbstractBackChannelConduit extends AbstractConduit {
 
         public AbstractBackChannelConduit() {
-            super(EndpointReferenceUtils.getAnonymousEndpointReference());
+            super(getAnonymousEndpointReference());
         }
 
         /**
@@ -112,6 +113,15 @@ protected Logger getLogger() {
         }
     }
 
+    // EndpointReferenceUtils#getAnonymousEndpointReference would load jaxb, avoid it
+    private static EndpointReferenceType getAnonymousEndpointReference() {
+        final EndpointReferenceType reference = new EndpointReferenceType();
+        final AttributedURIType a = new AttributedURIType();
+        a.setValue(EndpointReferenceUtils.ANONYMOUS_ADDRESS);
+        reference.setAddress(a);
+        return reference;
+    }
+
     /**
      * {@inheritDoc}
      */
diff --git a/core/src/main/java/org/apache/cxf/ws/addressing/ContextJAXBUtils.java b/core/src/main/java/org/apache/cxf/ws/addressing/ContextJAXBUtils.java
new file mode 100644
index 00000000000..58a909e93a4
--- /dev/null
+++ b/core/src/main/java/org/apache/cxf/ws/addressing/ContextJAXBUtils.java
@@ -0,0 +1,77 @@
+/**
+ * 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.cxf.ws.addressing;
+
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+
+import org.apache.cxf.common.jaxb.JAXBContextCache;
+import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas;
+
+/**
+ * Holder for utility methods relating to contexts, allows to lazily load JAXB compared to
ContextUtils.
+ */
+public final class ContextJAXBUtils {
+    private static JAXBContext jaxbContext;
+    private static Set<Class<?>> jaxbContextClasses;
+
+   /**
+    * Prevents instantiation.
+    */
+    private ContextJAXBUtils() {
+    }
+
+    /**
+     * Retrieve a JAXBContext for marshalling and unmarshalling JAXB generated
+     * types.
+     *
+     * @return a JAXBContext
+     */
+    public static JAXBContext getJAXBContext() throws JAXBException {
+        synchronized (ContextJAXBUtils.class) {
+            if (jaxbContext == null || jaxbContextClasses == null) {
+                Set<Class<?>> tmp = new HashSet<>();
+                JAXBContextCache.addPackage(tmp, ContextUtils.WSA_OBJECT_FACTORY.getClass().getPackage().getName(),
+                            ContextUtils.WSA_OBJECT_FACTORY.getClass().getClassLoader());
+                JAXBContextCache.scanPackages(tmp);
+                CachedContextAndSchemas ccs
+                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
+                jaxbContextClasses = ccs.getClasses();
+                jaxbContext = ccs.getContext();
+            }
+        }
+        return jaxbContext;
+    }
+
+    /**
+     * Set the encapsulated JAXBContext (used by unit tests).
+     *
+     * @param ctx JAXBContext
+     */
+    public static void setJAXBContext(JAXBContext ctx) {
+        synchronized (ContextJAXBUtils.class) {
+            jaxbContext = ctx;
+            jaxbContextClasses = new HashSet<>();
+        }
+    }
+}
diff --git a/core/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java b/core/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java
index 69362f7b8a8..61e2c916d9a 100644
--- a/core/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java
+++ b/core/src/main/java/org/apache/cxf/ws/addressing/ContextUtils.java
@@ -22,18 +22,11 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.HashSet;
-import java.util.Set;
 import java.util.UUID;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-
 import org.apache.cxf.Bus;
-import org.apache.cxf.common.jaxb.JAXBContextCache;
-import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.endpoint.Endpoint;
@@ -59,8 +52,7 @@
     public static final ObjectFactory WSA_OBJECT_FACTORY = new ObjectFactory();
     public static final String ACTION = ContextUtils.class.getName() + ".ACTION";
 
-    private static final EndpointReferenceType NONE_ENDPOINT_REFERENCE =
-        EndpointReferenceUtils.getEndpointReference(Names.WSA_NONE_ADDRESS);
+    private static final EndpointReferenceType NONE_ENDPOINT_REFERENCE = new EndpointReferenceType();
 
     private static final Logger LOG = LogUtils.getL7dLogger(ContextUtils.class);
 
@@ -69,9 +61,6 @@
      */
     private static final String URN_UUID = "urn:uuid:";
 
-    private static JAXBContext jaxbContext;
-    private static Set<Class<?>> jaxbContextClasses;
-
     /**
      * Used by MAPAggregator to cache bad MAP fault name
      */
@@ -90,6 +79,11 @@
     private static final String PARTIAL_RESPONSE_SENT_PROPERTY =
         "org.apache.cxf.ws.addressing.partial.response.sent";
 
+    static {
+        NONE_ENDPOINT_REFERENCE.setAddress(new AttributedURIType());
+        NONE_ENDPOINT_REFERENCE.getAddress().setValue(Names.WSA_NONE_ADDRESS);
+    }
+
    /**
     * Prevents instantiation.
     */
@@ -515,41 +509,6 @@ public static boolean retrieveAsyncPostResponseDispatch(Message message)
{
         return ret != null && ret.booleanValue();
     }
 
-    /**
-     * Retrieve a JAXBContext for marshalling and unmarshalling JAXB generated
-     * types.
-     *
-     * @return a JAXBContext
-     */
-    public static JAXBContext getJAXBContext() throws JAXBException {
-        synchronized (ContextUtils.class) {
-            if (jaxbContext == null || jaxbContextClasses == null) {
-                Set<Class<?>> tmp = new HashSet<>();
-                JAXBContextCache.addPackage(tmp, WSA_OBJECT_FACTORY.getClass().getPackage().getName(),
-                                            WSA_OBJECT_FACTORY.getClass().getClassLoader());
-                JAXBContextCache.scanPackages(tmp);
-                CachedContextAndSchemas ccs
-                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
-                jaxbContextClasses = ccs.getClasses();
-                jaxbContext = ccs.getContext();
-            }
-        }
-        return jaxbContext;
-    }
-
-    /**
-     * Set the encapsulated JAXBContext (used by unit tests).
-     *
-     * @param ctx JAXBContext
-     */
-    public static void setJAXBContext(JAXBContext ctx) throws JAXBException {
-        synchronized (ContextUtils.class) {
-            jaxbContext = ctx;
-            jaxbContextClasses = new HashSet<>();
-        }
-    }
-
-
     /**
      * @return a generated UUID
      */
diff --git a/core/src/main/java/org/apache/cxf/ws/addressing/EndpointReferenceUtils.java b/core/src/main/java/org/apache/cxf/ws/addressing/EndpointReferenceUtils.java
index 3ced5511d18..e9451b9a6fa 100644
--- a/core/src/main/java/org/apache/cxf/ws/addressing/EndpointReferenceUtils.java
+++ b/core/src/main/java/org/apache/cxf/ws/addressing/EndpointReferenceUtils.java
@@ -752,7 +752,7 @@ public static EndpointReferenceType getEndpointReference(AttributedURIType
addre
      * @return EndpointReferenceType - the endpoint reference
      */
     public static EndpointReferenceType getAnonymousEndpointReference() {
-        EndpointReferenceType reference = new EndpointReferenceType();
+        final EndpointReferenceType reference = new EndpointReferenceType();
         setAddress(reference, ANONYMOUS_ADDRESS);
         return reference;
     }
diff --git a/core/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java b/core/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java
index 68b98e5dcf7..2704ebcf5c2 100644
--- a/core/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java
+++ b/core/src/main/java/org/apache/cxf/ws/addressing/VersionTransformer.java
@@ -482,7 +482,7 @@ public static EndpointReferenceType convertToNative(Object exposed) {
     public static JAXBContext getExposedJAXBContext(String exposedURI) throws JAXBException
{
 
         return NATIVE_VERSION.equals(exposedURI)
-            ? ContextUtils.getJAXBContext() : Names200408.WSA_NAMESPACE_NAME.equals(exposedURI)
? Names200408
+            ? ContextJAXBUtils.getJAXBContext() : Names200408.WSA_NAMESPACE_NAME.equals(exposedURI)
? Names200408
                 .getJAXBContext() : Names200403.WSA_NAMESPACE_NAME.equals(exposedURI) ? Names200403
                 .getJAXBContext() : null;
     }
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
index 38068cc95af..f3f8e2f3fc1 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
@@ -192,10 +192,10 @@ public void init(List<ClassResourceInfo> cris) {
             if (cris != null) {
                 allTypes = new HashSet<>(ResourceUtils.getAllRequestResponseTypes(cris,
true)
                     .getAllTypes().keySet());
-                context = ResourceUtils.createJaxbContext(allTypes, extraClass, cProperties);
+                context = org.apache.cxf.jaxrs.utils.JAXBUtils.createJaxbContext(allTypes,
extraClass, cProperties);
             } else if (extraClass != null) {
                 allTypes = new HashSet<>(Arrays.asList(extraClass));
-                context = ResourceUtils.createJaxbContext(allTypes, null, cProperties);
+                context = org.apache.cxf.jaxrs.utils.JAXBUtils.createJaxbContext(allTypes,
null, cProperties);
             }
 
             if (context != null) {
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
index 8e2eb379715..855d655025f 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
@@ -139,17 +139,18 @@ protected static ProviderCache initCache(Bus theBus) {
         return new ProviderCache(checkAll);
     }
     protected static void initFactory(ProviderFactory factory) {
+        // ensure to not load providers not available in a module environment if not needed
         factory.setProviders(false,
                              false,
                      new BinaryDataProvider<Object>(),
                      new SourceProvider<Object>(),
-                     new DataSourceProvider<Object>(),
+                     tryCreateInstance("org.apache.cxf.jaxrs.provider.DataSourceProvider"),
                      new FormEncodingProvider<Object>(),
                      new StringTextProvider(),
                      new PrimitiveTextProvider<Object>(),
-                     new JAXBElementProvider<Object>(),
-                     new JAXBElementTypedProvider(),
-                     new MultipartProvider());
+                     tryCreateInstance(JAXB_PROVIDER_NAME),
+                     tryCreateInstance("org.apache.cxf.jaxrs.provider.JAXBElementTypedProvider"),
+                     tryCreateInstance("org.apache.cxf.jaxrs.provider.MultipartProvider"));
         Object prop = factory.getBus().getProperty("skip.default.json.provider.registration");
         if (!PropertyUtils.isTrue(prop)) {
             factory.setProviders(false, false, createProvider(JSON_PROVIDER_NAME, factory.getBus()));
@@ -157,6 +158,16 @@ protected static void initFactory(ProviderFactory factory) {
 
     }
 
+    protected static Object tryCreateInstance(final String className) {
+        try {
+            final Class<?> cls = ClassLoaderUtils.loadClass(className, ProviderFactory.class);
+            return cls.getConstructor().newInstance();
+        } catch (final Throwable ex) {
+            LOG.fine(className + " not available, skipping");
+        }
+        return null;
+    }
+
     protected static Object createProvider(String className, Bus bus) {
 
         try {
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
index 7ad6030cb69..4f3e2925440 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.utils;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Collections;
 import java.util.HashSet;
@@ -27,7 +28,6 @@
 import java.util.Set;
 import java.util.logging.Logger;
 
-import javax.annotation.Priority;
 import javax.ws.rs.BeanParam;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.CookieParam;
@@ -48,6 +48,10 @@
 
 public final class AnnotationUtils {
     private static final Logger LOG = LogUtils.getL7dLogger(AnnotationUtils.class);
+    private static final Class<? extends Annotation> PRIORITY_API =
+            (Class<? extends Annotation>) loadClassOrNull("javax.annotation.Priority");
+    private static final Method PRIORITY_VALUE = getMethodOrNull(PRIORITY_API, "value");
+
     private static final Set<Class<?>> PARAM_ANNOTATION_CLASSES;
     private static final Set<Class<?>> METHOD_ANNOTATION_CLASSES;
     static {
@@ -59,6 +63,25 @@ private AnnotationUtils() {
 
     }
 
+    private static Method getMethodOrNull(final Class<?> type, final String name) {
+        if (type == null) {
+            return null;
+        }
+        try {
+            return type.getMethod(name);
+        } catch (final NoSuchMethodException e) {
+            return null;
+        }
+    }
+
+    private static Class<?> loadClassOrNull(final String name) {
+        try {
+            return org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass(
+                    name, AnnotationUtils.class);
+        } catch (final ClassNotFoundException e) {
+            return null;
+        }
+    }
 
     private static Set<Class<?>> initParamAnnotationClasses() {
         Set<Class<?>> classes = new HashSet<>();
@@ -82,8 +105,15 @@ private AnnotationUtils() {
     }
 
     public static int getBindingPriority(Class<?> providerCls) {
-        Priority b = getClassAnnotation(providerCls, Priority.class);
-        return b == null ? Priorities.USER : b.value();
+        if (PRIORITY_API == null) {
+            return Priorities.USER;
+        }
+        Annotation b = getClassAnnotation(providerCls, PRIORITY_API);
+        try {
+            return b == null ? Priorities.USER : Integer.class.cast(PRIORITY_VALUE.invoke(b));
+        } catch (final IllegalAccessException | InvocationTargetException e) {
+            return Priorities.USER;
+        }
     }
     public static Set<String> getNameBindings(Annotation[] targetAnns) {
         if (targetAnns.length == 0) {
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
index 5e6196f1a50..357e477da10 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
@@ -22,9 +22,13 @@
 import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -37,6 +41,24 @@
     private JAXBUtils() {
 
     }
+
+    public static JAXBContext createJaxbContext(Set<Class<?>> classes, Class<?>[]
extraClass,
+                                                Map<String, Object> contextProperties)
{
+        if (classes == null || classes.isEmpty()) {
+            return null;
+        }
+        org.apache.cxf.common.jaxb.JAXBUtils.scanPackages(classes, extraClass, null);
+
+        JAXBContext ctx;
+        try {
+            ctx = JAXBContext.newInstance(classes.toArray(new Class[0]), contextProperties);
+            return ctx;
+        } catch (JAXBException ex) {
+            LOG.log(Level.SEVERE, "No JAXB context can be created", ex);
+        }
+        return null;
+    }
+
     public static void closeUnmarshaller(Unmarshaller u) {
         if (u instanceof Closeable) {
             //need to do this to clear the ThreadLocal cache
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
index 89368f2abb4..a2bbbfede90 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
@@ -67,9 +67,6 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Provider;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Document;
@@ -79,7 +76,6 @@
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.BundleUtils;
-import org.apache.cxf.common.jaxb.JAXBUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.feature.Feature;
@@ -658,6 +654,13 @@ private static void getAllTypesForResource(ClassResourceInfo resource,
                                                ResourceTypes types,
                                                boolean jaxbOnly,
                                                MessageBodyWriter<?> jaxbWriter) {
+        Class<?> jaxbElement = null;
+        try {
+            jaxbElement = ClassLoaderUtils.loadClass("javax.xml.bind.JAXBElement", ResourceUtils.class);
+        } catch (final ClassNotFoundException e) {
+            // no-op
+        }
+
         for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos())
{
             Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke() :
ori.getAnnotatedMethod();
             Class<?> realReturnType = method.getReturnType();
@@ -668,7 +671,7 @@ private static void getAllTypesForResource(ClassResourceInfo resource,
             Type type = method.getGenericReturnType();
             if (jaxbOnly) {
                 checkJaxbType(resource.getServiceClass(), cls, realReturnType == Response.class
|| ori.isAsync()
-                    ? cls : type, types, method.getAnnotations(), jaxbWriter);
+                    ? cls : type, types, method.getAnnotations(), jaxbWriter, jaxbElement);
             } else {
                 types.getAllTypes().put(cls, type);
             }
@@ -680,7 +683,7 @@ private static void getAllTypesForResource(ClassResourceInfo resource,
                         Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
                         if (jaxbOnly) {
                             checkJaxbType(resource.getServiceClass(), inType, paramType,
types,
-                                          method.getParameterAnnotations()[pm.getIndex()],
jaxbWriter);
+                                          method.getParameterAnnotations()[pm.getIndex()],
jaxbWriter, jaxbElement);
                         } else {
                             types.getAllTypes().put(inType, paramType);
                         }
@@ -712,7 +715,8 @@ private static void checkJaxbType(Class<?> serviceClass,
                                       Type genericType,
                                       ResourceTypes types,
                                       Annotation[] anns,
-                                      MessageBodyWriter<?> jaxbWriter) {
+                                      MessageBodyWriter<?> jaxbWriter,
+                                      Class<?> jaxbElement) {
         boolean isCollection = false;
         if (InjectionUtils.isSupportedCollectionOrArray(type)) {
             type = InjectionUtils.getActualType(genericType);
@@ -727,7 +731,7 @@ private static void checkJaxbType(Class<?> serviceClass,
         }
         if (type == null
             || InjectionUtils.isPrimitive(type)
-            || JAXBElement.class.isAssignableFrom(type)
+            || (jaxbElement != null && jaxbElement.isAssignableFrom(type))
             || Response.class.isAssignableFrom(type)
             || type.isInterface()) {
             return;
@@ -1022,23 +1026,4 @@ private static boolean isValidApplicationClass(Class<?> c, Set<Object>
singleton
         return true;
     }
 
-    //TODO : consider moving JAXBDataBinding.createContext to JAXBUtils
-    public static JAXBContext createJaxbContext(Set<Class<?>> classes, Class<?>[]
extraClass,
-                                          Map<String, Object> contextProperties) {
-        if (classes == null || classes.isEmpty()) {
-            return null;
-        }
-        JAXBUtils.scanPackages(classes, extraClass, null);
-
-        JAXBContext ctx;
-        try {
-            ctx = JAXBContext.newInstance(classes.toArray(new Class[0]),
-                                          contextProperties);
-            return ctx;
-        } catch (JAXBException ex) {
-            LOG.log(Level.SEVERE, "No JAXB context can be created", ex);
-        }
-        return null;
-    }
-
 }
diff --git a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
index 805e854b896..926d42d4dfb 100644
--- a/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
+++ b/rt/rs/description/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
@@ -327,7 +327,8 @@ public StringBuilder generateWADL(String baseURI,
 
         JAXBContext jaxbContext = null;
         if (useJaxbContextForQnames && !allTypes.isEmpty()) {
-            jaxbContext = ResourceUtils.createJaxbContext(new HashSet<>(allTypes),
null, jaxbContextProperties);
+            jaxbContext = org.apache.cxf.jaxrs.utils.JAXBUtils
+                    .createJaxbContext(new HashSet<>(allTypes), null, jaxbContextProperties);
             if (jaxbContext == null) {
                 LOG.warning("JAXB Context is null: possibly due to one of input classes being
not accepted");
             }
diff --git a/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
b/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
index cf3f87e77e1..324c1f872ca 100644
--- a/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
+++ b/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/soap/MAPCodecTest.java
@@ -43,6 +43,7 @@
 import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.ws.addressing.AddressingProperties;
 import org.apache.cxf.ws.addressing.AttributedURIType;
+import org.apache.cxf.ws.addressing.ContextJAXBUtils;
 import org.apache.cxf.ws.addressing.ContextUtils;
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.ws.addressing.EndpointReferenceUtils;
@@ -91,7 +92,7 @@ public void tearDown() throws Exception {
         expectedNamespaceURI = null;
         mimeHeaders = null;
         correlatedExchange = null;
-        ContextUtils.setJAXBContext(null);
+        ContextJAXBUtils.setJAXBContext(null);
         nonReplyRelationship = null;
     }
 
@@ -310,7 +311,7 @@ public Element getHeader(SoapVersion version) {
         });
         List<Header> headers = message.getHeaders();
         JAXBContext jaxbContext = control.createMock(JAXBContext.class);
-        ContextUtils.setJAXBContext(jaxbContext);
+        ContextJAXBUtils.setJAXBContext(jaxbContext);
         Names200408.setJAXBContext(jaxbContext);
         Names200403.setJAXBContext(jaxbContext);
         if (outbound) {
@@ -345,7 +346,7 @@ private void setUpEncode(boolean requestor, SoapMessage message, Element
header,
     private void setUpDecode(SoapMessage message, List<Header> headers, AddressingProperties
maps,
                              String mapProperty, boolean requestor) throws Exception {
         Unmarshaller unmarshaller = control.createMock(Unmarshaller.class);
-        ContextUtils.getJAXBContext().createUnmarshaller();
+        ContextJAXBUtils.getJAXBContext().createUnmarshaller();
         EasyMock.expectLastCall().andReturn(unmarshaller);
         String uri = maps.getNamespaceURI();
         boolean exposedAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);


With regards,
Apache Git Services

Mime
View raw message