You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2021/05/03 01:47:26 UTC

[tomee] branch master updated (009fbc2 -> e962c4c)

This is an automated email from the ASF dual-hosted git repository.

dblevins pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git.


    from 009fbc2  Switch back to SXC and update the schema manually
     new 5071a2f  Sort parameter converters
     new ac58f55  Updated with fixes from CXF 3.5.0
     new 8e9c2a7  Switch back to CXF 3.4.3
     new e962c4c  Merge branch 'master' of github.com:apache/tomee

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            |   2 +-
 .../apache/cxf/jaxrs/provider/ProviderFactory.java |  60 +++-
 .../apache/cxf/jaxrs/utils/AnnotationUtils.java    | 308 +++++++++++++++++++++
 3 files changed, 368 insertions(+), 2 deletions(-)
 create mode 100644 tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java

[tomee] 02/04: Updated with fixes from CXF 3.5.0

Posted by db...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit ac58f55db2e75f8c4af70094f252b09b05c5188b
Author: David Blevins <da...@gmail.com>
AuthorDate: Sun May 2 18:45:47 2021 -0700

    Updated with fixes from CXF 3.5.0
---
 .../apache/cxf/jaxrs/utils/AnnotationUtils.java    | 308 +++++++++++++++++++++
 1 file changed, 308 insertions(+)

diff --git a/tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java b/tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
new file mode 100644
index 0000000..8d49e2d
--- /dev/null
+++ b/tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
@@ -0,0 +1,308 @@
+/**
+ * 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.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;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.ws.rs.BeanParam;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.DefaultValue;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.NameBinding;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Priorities;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ClassHelper;
+
+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 {
+        PARAM_ANNOTATION_CLASSES = initParamAnnotationClasses();
+        METHOD_ANNOTATION_CLASSES = initMethodAnnotationClasses();
+    }
+
+    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<? extends Annotation> loadClassOrNull(final String name) {
+        try {
+            return org.apache.cxf.common.classloader.ClassLoaderUtils.loadClass(
+                    name, AnnotationUtils.class, Annotation.class);
+        } catch (final ClassNotFoundException e) {
+            return null;
+        }
+    }
+
+    private static Set<Class<?>> initParamAnnotationClasses() {
+        Set<Class<?>> classes = new HashSet<>();
+        classes.add(PathParam.class);
+        classes.add(QueryParam.class);
+        classes.add(MatrixParam.class);
+        classes.add(HeaderParam.class);
+        classes.add(CookieParam.class);
+        classes.add(FormParam.class);
+        classes.add(BeanParam.class);
+        return classes;
+    }
+
+    private static Set<Class<?>> initMethodAnnotationClasses() {
+        Set<Class<?>> classes = new HashSet<>();
+        classes.add(HttpMethod.class);
+        classes.add(Path.class);
+        classes.add(Produces.class);
+        classes.add(Consumes.class);
+        return classes;
+    }
+
+    public static int getBindingPriority(Class<?> providerCls) {
+        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> getInstanceNameBindings(Bus bus, Object obj) {
+        final Class<?> realClazz = ClassHelper.getRealClass(bus, obj);
+        return getNameBindings(realClazz.getAnnotations());
+    }
+    
+    public static Set<String> getNameBindings(Bus bus, Class<?> clazz) {
+        final Class<?> realClazz = ClassHelper.getRealClassFromClass(bus, clazz);
+        return getNameBindings(realClazz.getAnnotations());
+    }
+    
+    public static Set<String> getNameBindings(Annotation[] targetAnns) {
+        if (targetAnns.length == 0) {
+            return Collections.emptySet();
+        }
+        Set<String> names = new LinkedHashSet<>();
+        for (Annotation a : targetAnns) {
+            NameBinding nb = a.annotationType().getAnnotation(NameBinding.class);
+            if (nb != null) {
+                names.add(a.annotationType().getName());
+            }
+        }
+        return names;
+    }
+
+    public static boolean isParamAnnotationClass(Class<?> annotationClass) {
+        return PARAM_ANNOTATION_CLASSES.contains(annotationClass);
+    }
+
+    public static boolean isValidParamAnnotationClass(Class<?> annotationClass) {
+        return PARAM_ANNOTATION_CLASSES.contains(annotationClass) || Context.class == annotationClass;
+    }
+
+    public static boolean isValidParamAnnotations(Annotation[] paramAnnotations) {
+        for (Annotation a : paramAnnotations) {
+            if (AnnotationUtils.isValidParamAnnotationClass(a.annotationType())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static boolean isMethodAnnotation(Annotation a) {
+        return METHOD_ANNOTATION_CLASSES.contains(a.annotationType())
+               || a.annotationType().getAnnotation(HttpMethod.class) != null;
+    }
+
+    public static String getAnnotationValue(Annotation a) {
+        String value = null;
+        if (a.annotationType() == PathParam.class) {
+            value = ((PathParam)a).value();
+        } else if (a.annotationType() == QueryParam.class) {
+            value = ((QueryParam)a).value();
+        } else if (a.annotationType() == MatrixParam.class) {
+            value = ((MatrixParam)a).value();
+        } else if (a.annotationType() == HeaderParam.class) {
+            value = ((HeaderParam)a).value();
+        } else if (a.annotationType() == CookieParam.class) {
+            value = ((CookieParam)a).value();
+        } else if (a.annotationType() == FormParam.class) {
+            value = ((FormParam)a).value();
+        }
+        return value;
+    }
+
+    public static <T> T getAnnotation(Annotation[] anns, Class<T> type) {
+        if (anns == null) {
+            return null;
+        }
+        for (Annotation a : anns) {
+            if (a.annotationType() == type) {
+                return type.cast(a);
+            }
+        }
+        return null;
+    }
+
+    public static Method getAnnotatedMethod(Class<?> serviceClass, Method m) {
+        Method annotatedMethod = doGetAnnotatedMethod(serviceClass, m);
+        return annotatedMethod == null ? m : annotatedMethod;
+    }
+
+    private static Method doGetAnnotatedMethod(Class<?> serviceClass, Method m) {
+
+        if (m != null) {
+            if (!m.isBridge() && !m.isSynthetic()) {
+                //the bridge/synthetic methods may not have the parameter annotations
+                //thus we will need to search the super classes/interfaces to make 
+                //sure we get the proper method that would also have the parameters annotated
+                //properly
+                for (Annotation a : m.getAnnotations()) {
+                    if (AnnotationUtils.isMethodAnnotation(a)) {
+                        return m;
+                    }
+                }
+                for (Annotation[] paramAnnotations : m.getParameterAnnotations()) {
+                    if (isValidParamAnnotations(paramAnnotations)) {
+                        LOG.warning("Method " + m.getName() + " in " + m.getDeclaringClass().getName()
+                                     + " has no JAX-RS Path or HTTP Method annotations");
+                        return m;
+                    }
+                }
+            }
+            Class<?> declaringClass = m.getDeclaringClass();
+            Class<?> superC = declaringClass.getSuperclass();
+            if (superC != null && Object.class != superC) {
+                try {
+                    Method method = doGetAnnotatedMethod(serviceClass,
+                                                         superC.getMethod(m.getName(), m.getParameterTypes()));
+                    if (method != null) {
+                        return method;
+                    }
+                } catch (NoSuchMethodException ex) {
+                    // ignore
+                }
+            }
+            for (Class<?> i : declaringClass.getInterfaces()) {
+                try {
+                    Method method = doGetAnnotatedMethod(serviceClass,
+                                                         i.getMethod(m.getName(), m.getParameterTypes()));
+                    if (method != null) {
+                        return method;
+                    }
+                } catch (NoSuchMethodException ex) {
+                    // ignore
+                }
+            }
+            if (declaringClass != serviceClass && !declaringClass.isInterface()) {
+                for (Class<?> i : serviceClass.getInterfaces()) {
+                    try {
+                        Method method = doGetAnnotatedMethod(serviceClass,
+                                                             i.getMethod(m.getName(), m.getParameterTypes()));
+                        if (method != null) {
+                            return method;
+                        }
+                    } catch (NoSuchMethodException ex) {
+                        // ignore
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    public static String getHttpMethodValue(Method m) {
+        for (Annotation a : m.getAnnotations()) {
+            HttpMethod httpM = a.annotationType().getAnnotation(HttpMethod.class);
+            if (httpM != null) {
+                return httpM.value();
+            }
+        }
+        return null;
+    }
+
+    public static <A extends Annotation> A getMethodAnnotation(Method m, Class<A> aClass) {
+        return m == null ? null : m.getAnnotation(aClass);
+    }
+
+    public static <A extends Annotation> A getClassAnnotation(Class<?> c, Class<A> aClass) {
+        if (c == null) {
+            return null;
+        }
+        A p = c.getAnnotation(aClass);
+        if (p != null) {
+            return p;
+        }
+
+        p = getClassAnnotation(c.getSuperclass(), aClass);
+        if (p != null) {
+            return p;
+        }
+
+        // finally try the first one on the interface
+        for (Class<?> i : c.getInterfaces()) {
+            p = getClassAnnotation(i, aClass);
+            if (p != null) {
+                return p;
+            }
+        }
+        return null;
+    }
+
+    public static String getDefaultParameterValue(Annotation[] anns) {
+
+        DefaultValue dv = AnnotationUtils.getAnnotation(anns, DefaultValue.class);
+        return dv != null ? dv.value() : null;
+    }
+
+}

[tomee] 01/04: Sort parameter converters

Posted by db...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 5071a2ffc406746d458681368f1f0011ed98f34f
Author: David Blevins <da...@gmail.com>
AuthorDate: Sun May 2 18:45:12 2021 -0700

    Sort parameter converters
---
 .../apache/cxf/jaxrs/provider/ProviderFactory.java | 60 +++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

diff --git a/tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java b/tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
index 27f575a..65c417c 100644
--- a/tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
+++ b/tomee/apache-tomee/src/patch/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
@@ -39,6 +39,7 @@ import java.util.Set;
 import java.util.TreeMap;
 import java.util.logging.Logger;
 
+import javax.annotation.Priority;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Configuration;
@@ -77,6 +78,8 @@ import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 
+import static javax.ws.rs.Priorities.USER;
+
 public abstract class ProviderFactory {
     public static final String DEFAULT_FILTER_NAME_BINDING = "org.apache.cxf.filter.binding";
     public static final String PROVIDER_SELECTION_PROPERTY_CHANGED = "provider.selection.property.changed";
@@ -662,6 +665,7 @@ public abstract class ProviderFactory {
         sortReaders();
         sortWriters();
         sortContextResolvers();
+        sortParamConverters();
 
         mapInterceptorFilters(readerInterceptors, readInts, ReaderInterceptor.class, true);
         mapInterceptorFilters(writerInterceptors, writeInts, WriterInterceptor.class, true);
@@ -783,7 +787,9 @@ public abstract class ProviderFactory {
         contextResolvers.sort(new ContextResolverComparator());
     }
 
-
+    private void sortParamConverters() {
+        paramConverters.sort(new ParamConverterComparator());
+    }
 
 
 
@@ -1517,4 +1523,56 @@ public abstract class ProviderFactory {
         writerInterceptors = sortedWriterInterceptors;
     }
 
+    protected static class ParamConverterComparator implements Comparator<ProviderInfo<ParamConverterProvider>> {
+
+        @Override
+        public int compare(final ProviderInfo<ParamConverterProvider> a,
+                           final ProviderInfo<ParamConverterProvider> b) {
+
+            /*
+             * Primary sort.  Also takes care of sorting custom
+             * converters from system converters due to priority
+             * defaults
+             */
+            int result = sortByPriority(a, b);
+
+            /*
+             * Secondary sort as this list *will* change order
+             * once in a while between jvm restarts, which can
+             * have frustrating consequences for users who are
+             * expecting no change in behavior as they aren't
+             * changing their code.
+             */
+            if (result == 0) {
+                result = sortByClassName(a, b);
+            }
+
+            return result;
+        }
+
+        public int sortByPriority(final ProviderInfo<ParamConverterProvider> a,
+                           final ProviderInfo<ParamConverterProvider> b) {
+            final int aPriority = getPriority(a);
+            final int bPriority = getPriority(b);
+
+            // Sort ascending as the priority with the lowest number wins
+            return Integer.compare(aPriority, bPriority);
+        }
+
+        public int sortByClassName(final ProviderInfo<ParamConverterProvider> a,
+                           final ProviderInfo<ParamConverterProvider> b) {
+
+            // Sort ascending as the priority with the lowest number wins
+            return a.getProvider().getClass().getName().compareTo(b.getProvider().getClass().getName());
+        }
+
+        private int getPriority(final ProviderInfo<ParamConverterProvider> providerInfo) {
+            final Priority priority = providerInfo.getProvider().getClass().getAnnotation(Priority.class);
+            if (priority!=null) {
+                return priority.value();
+            }
+            return providerInfo.isCustom() ? USER : USER + 1000;
+        }
+    }
+
 }

[tomee] 04/04: Merge branch 'master' of github.com:apache/tomee

Posted by db...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit e962c4ca97eb3b1c9784681ad365f9b6735c6356
Merge: 8e9c2a7 009fbc2
Author: David Blevins <da...@gmail.com>
AuthorDate: Sun May 2 18:47:12 2021 -0700

    Merge branch 'master' of github.com:apache/tomee

 .../openejb/assembler/classic/WebAppInfo.java      |  1 +
 .../org/apache/openejb/config/AppInfoBuilder.java  |  2 ++
 .../apache/openejb/config/DeploymentLoader.java    |  1 +
 .../org/apache/openejb/config/ReadDescriptors.java |  2 ++
 .../java/org/apache/openejb/config/WebModule.java  |  9 ++++++
 .../java/org/apache/openejb/jee/WebApp$JAXB.java   | 13 +++++++++
 .../main/java/org/apache/openejb/jee/WebApp.java   | 16 +++++++++++
 .../test/java/org/apache/openejb/jee/JeeTest.java  |  4 +++
 .../src/test/resources/web_5-example-expected.xml  | 32 ++++++++++++++++++++++
 .../src/test/resources/web_5-example.xml           | 32 ++++++++++++++++++++++
 .../apache/tomee/catalina/TomcatWebAppBuilder.java | 18 ++++++++++--
 11 files changed, 127 insertions(+), 3 deletions(-)

[tomee] 03/04: Switch back to CXF 3.4.3

Posted by db...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 8e9c2a79593d7f5862437630db35da9dffba778c
Author: David Blevins <da...@gmail.com>
AuthorDate: Sun May 2 18:46:20 2021 -0700

    Switch back to CXF 3.4.3
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index f6db1af..cb85152 100644
--- a/pom.xml
+++ b/pom.xml
@@ -148,7 +148,7 @@
 
     <tomcat.version>9.0.45</tomcat.version>
 
-    <cxf.version>3.5.0-SNAPSHOT</cxf.version>
+    <cxf.version>3.4.3</cxf.version>
     <ehcache.version>2.10.3</ehcache.version>
     <!-- used by cxf for security (replay attack) -->
     <jetty.version>7.5.3.v20111011</jetty.version>