tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-2045 ensure @Provider is not mandatory when explicitly registered
Date Thu, 01 Jun 2017 21:21:54 GMT
Repository: tomee
Updated Branches:
  refs/heads/master 022d8fa45 -> 2be715d0d


TOMEE-2045 ensure @Provider is not mandatory when explicitly registered


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/2be715d0
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/2be715d0
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/2be715d0

Branch: refs/heads/master
Commit: 2be715d0d698e234f9886b450fb3643c0fb89f16
Parents: 022d8fa
Author: rmannibucau <rmannibucau@apache.org>
Authored: Thu Jun 1 23:21:48 2017 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Thu Jun 1 23:21:48 2017 +0200

----------------------------------------------------------------------
 .../cxf/rs/ProviderWithoutAnnotationTest.java   | 103 +++++++++++++++++++
 .../apache/openejb/server/rest/RESTService.java |  21 +++-
 2 files changed, 123 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/2be715d0/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/ProviderWithoutAnnotationTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/ProviderWithoutAnnotationTest.java
b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/ProviderWithoutAnnotationTest.java
new file mode 100644
index 0000000..d1e6c03
--- /dev/null
+++ b/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/ProviderWithoutAnnotationTest.java
@@ -0,0 +1,103 @@
+/*
+ * 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.openejb.server.cxf.rs;
+
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.RandomPort;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+
+@EnableServices("jax-rs")
+@RunWith(ApplicationComposer.class)
+@Classes(innerClassesAsBean = true)
+public class ProviderWithoutAnnotationTest {
+    @RandomPort("http")
+    private URL base;
+
+    @Test
+    public void run() {
+        final Client client = ClientBuilder.newClient();
+        try {
+            assertEquals("foo", client.target(base.toExternalForm() + "openejb/api/ProviderWithoutAnnotationTest")
+                    .request("foo/bar")
+                    .get(String.class));
+        } finally {
+            client.close();
+        }
+    }
+
+    @ApplicationPath("api")
+    public static class App extends Application {
+        @Override
+        public Set<Class<?>> getClasses() {
+            return new HashSet<>(asList(Endpoint.class, FooWriter.class));
+        }
+    }
+
+    @Path("ProviderWithoutAnnotationTest")
+    public static class Endpoint {
+        @GET
+        @Produces("foo/bar")
+        public Endpoint get() {
+            return this;
+        }
+    }
+
+    @Produces("foo/*")
+    public static class FooWriter implements MessageBodyWriter<Endpoint> {
+        @Override
+        public boolean isWriteable(final Class<?> type, final Type genericType, final
Annotation[] annotations, final MediaType mediaType) {
+            return type == Endpoint.class && mediaType.getType().equals("foo");
+        }
+
+        @Override
+        public long getSize(final Endpoint s, final Class<?> type, final Type genericType,
final Annotation[] annotations, final MediaType mediaType) {
+            return -1;
+        }
+
+        @Override
+        public void writeTo(final Endpoint s, final Class<?> type, final Type genericType,
final Annotation[] annotations,
+                            final MediaType mediaType, final MultivaluedMap<String, Object>
httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException
{
+            entityStream.write("foo".getBytes(StandardCharsets.UTF_8));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/2be715d0/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
----------------------------------------------------------------------
diff --git a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
index a10b1a7..1f7d1ce 100644
--- a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
+++ b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
@@ -46,6 +46,7 @@ import org.apache.openejb.server.httpd.BasicAuthHttpListenerWrapper;
 import org.apache.openejb.server.httpd.HttpListener;
 import org.apache.openejb.server.httpd.HttpListenerRegistry;
 import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.testing.rest.ContextProvider;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.config.WebBeansContext;
@@ -54,9 +55,18 @@ import org.apache.xbean.finder.MetaAnnotatedClass;
 import javax.naming.Context;
 import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.Path;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseFilter;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.ext.ContextResolver;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
 import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.WriterInterceptor;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -545,7 +555,16 @@ public abstract class RESTService implements ServerService, SelfManaging
{
     }
 
     private static <T> boolean isProvider(final Class<T> clazz) {
-        return new MetaAnnotatedClass<>(clazz).isAnnotationPresent(Provider.class);
+        return MessageBodyReader.class.isAssignableFrom(clazz) ||
+                MessageBodyWriter.class.isAssignableFrom(clazz) ||
+                ParamConverter.class.isAssignableFrom(clazz) ||
+                ContainerRequestFilter.class.isAssignableFrom(clazz) ||
+                ContainerResponseFilter.class.isAssignableFrom(clazz) ||
+                ReaderInterceptor.class.isAssignableFrom(clazz) ||
+                WriterInterceptor.class.isAssignableFrom(clazz) ||
+                ParamConverterProvider.class.isAssignableFrom(clazz) ||
+                ContextResolver.class.isAssignableFrom(clazz) ||
+                new MetaAnnotatedClass<>(clazz).isAnnotationPresent(Provider.class);
     }
 
     private boolean hasEjbAndIsNotAManagedBean(final Map<String, EJBRestServiceInfo>
restEjbs, final String clazz) {


Mime
View raw message