Make namebindings also be null when not specified
Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/08c4cf71 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/08c4cf71 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/08c4cf71 Branch: refs/heads/master Commit: 08c4cf71e9f5c2a23410e5e878ab950f692baf5c Parents: 872fc00 Author: Carlos Sierra <[email protected]> Authored: Fri Feb 16 13:05:33 2018 +0100 Committer: Carlos Sierra <[email protected]> Committed: Fri Feb 16 13:05:33 2018 +0100 ---------------------------------------------------------------------- jax-rs.itests/src/main/java/test/JaxrsTest.java | 6 ++--- .../internal/AriesJaxrsServiceRuntime.java | 12 +++++++++ .../introspection/ClassIntrospector.java | 8 +++--- .../introspection/ClassIntrospectorTest.java | 26 +++++++++----------- 4 files changed, 31 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/08c4cf71/jax-rs.itests/src/main/java/test/JaxrsTest.java ---------------------------------------------------------------------- diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java index 3d70015..0dbd57a 100644 --- a/jax-rs.itests/src/main/java/test/JaxrsTest.java +++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java @@ -144,7 +144,7 @@ public class JaxrsTest extends TestHelper { assertArrayEquals( new String[]{MediaType.TEXT_PLAIN}, resourceMethod.producingMimeType); - assertArrayEquals(new String[0], resourceMethod.nameBindings); + assertNull(resourceMethod.nameBindings); } @@ -239,7 +239,7 @@ public class JaxrsTest extends TestHelper { assertArrayEquals( new String[]{MediaType.TEXT_PLAIN}, resourceMethod.producingMimeType); - assertArrayEquals(new String[0], resourceMethod.nameBindings); + assertNull(resourceMethod.nameBindings); } @Test @@ -266,7 +266,7 @@ public class JaxrsTest extends TestHelper { assertEquals("/{name}", resourceMethod.path); assertNull(resourceMethod.consumingMimeType); assertNull(resourceMethod.producingMimeType); - assertArrayEquals(new String[]{}, resourceMethod.nameBindings); + assertNull(resourceMethod.nameBindings); } @Test http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/08c4cf71/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java index 2c1f082..3c29f32 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java @@ -493,6 +493,10 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime { Set<String> nameBindings = AnnotationUtils.getNameBindings( eri._class.getAnnotations()); + if (nameBindings.isEmpty()) { + nameBindings = null; + } + extensionDTO.consumes = consumes == null ? null : JAXRSUtils.getConsumeTypes(consumes).stream(). map( @@ -600,6 +604,10 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime { new HashMap<>(); for (ExtensionDTO extensionDTO : applicationDTO.extensionDTOs) { + if (extensionDTO.nameBindings == null) { + continue; + } + for (String nameBinding : extensionDTO.nameBindings) { Set<ExtensionDTO> extensionDTOS = nameBoundExtensions.computeIfAbsent( @@ -615,6 +623,10 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime { for (ResourceMethodInfoDTO resourceMethodInfo : resourceDTO.resourceMethods) { + if (resourceMethodInfo.nameBindings == null) { + continue; + } + for (String nameBinding : resourceMethodInfo.nameBindings) { Set<ExtensionDTO> extensionDTOS = nameBoundExtensions.get( nameBinding); http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/08c4cf71/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospector.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospector.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospector.java index 50ac499..6063e13 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospector.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospector.java @@ -52,7 +52,7 @@ public class ClassIntrospector { clazz, clazz, true, true, bus); Stream<ResourceMethodInfoDTO> convert = convert( - new HashSet<>(), "/", null, null, null, Collections.emptySet(), + new HashSet<>(), "/", null, null, null, null, true, classResourceInfo); return convert.collect(Collectors.toList()); @@ -97,7 +97,7 @@ public class ClassIntrospector { List<MediaType> consumeParam = consumeMime == null ? null : new ArrayList<>(consumeMime); List<MediaType> produceParam = produceMime == null ? null : new ArrayList<>(produceMime); - HashSet<String> nameBindingsParam = new HashSet<>(nameBindings); + HashSet<String> nameBindingsParam = nameBindings == null ? null : new HashSet<>(nameBindings); Stream<ResourceMethodInfoDTO> stream = operationResourceInfos.stream(). @@ -192,8 +192,8 @@ public class ClassIntrospector { String[]::new ); - resourceMethodInfoDTO.nameBindings = nameBindings.toArray( - new String[0]); + resourceMethodInfoDTO.nameBindings = nameBindings == null ? null : + nameBindings.toArray(new String[0]); try { resourceMethodInfoDTO.path = Paths.get(path).normalize().toString(); http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/08c4cf71/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospectorTest.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospectorTest.java b/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospectorTest.java index 867d5a2..d8abb38 100644 --- a/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospectorTest.java +++ b/jax-rs.whiteboard/src/test/java/org/apache/aries/jax/rs/whiteboard/internal/introspection/ClassIntrospectorTest.java @@ -43,8 +43,6 @@ import static org.junit.Assert.assertTrue; public class ClassIntrospectorTest { - private static final String[] ALL_TYPES = {MediaType.WILDCARD}; - @Test public void testPlainResource() { Bus bus = BusFactory.getDefaultBus(true); @@ -65,7 +63,7 @@ public class ClassIntrospectorTest { assertNull(resourceMethodInfoDTO.consumingMimeType); assertNull(resourceMethodInfoDTO.producingMimeType); assertEquals("/", resourceMethodInfoDTO.path); - assertArrayEquals(new String[]{}, resourceMethodInfoDTO.nameBindings); + assertNull(resourceMethodInfoDTO.nameBindings); } @Test @@ -143,7 +141,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.consumingMimeType = null; resourceMethodInfoDTO.producingMimeType = null; resourceMethodInfoDTO.path = "/"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -155,7 +153,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.consumingMimeType = null; resourceMethodInfoDTO.producingMimeType = null; resourceMethodInfoDTO.path = "/"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -190,7 +188,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.consumingMimeType = null; resourceMethodInfoDTO.producingMimeType = null; resourceMethodInfoDTO.path = "/common"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -203,7 +201,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.consumingMimeType = null; resourceMethodInfoDTO.producingMimeType = null; resourceMethodInfoDTO.path = "/common"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -238,7 +236,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.consumingMimeType = null; resourceMethodInfoDTO.producingMimeType = null; resourceMethodInfoDTO.path = "/common"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -250,7 +248,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.consumingMimeType = null; resourceMethodInfoDTO.producingMimeType = null; resourceMethodInfoDTO.path = "/common/different"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -286,7 +284,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.producingMimeType = new String[]{MediaType.APPLICATION_XML}; resourceMethodInfoDTO.path = "/resource"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -300,7 +298,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.producingMimeType = new String[]{MediaType.APPLICATION_JSON}; resourceMethodInfoDTO.path = "/resource/subresource"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -317,7 +315,7 @@ public class ClassIntrospectorTest { MediaType.APPLICATION_JSON }; resourceMethodInfoDTO.path = "/resource/subresource"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -331,7 +329,7 @@ public class ClassIntrospectorTest { resourceMethodInfoDTO.producingMimeType = new String[]{MediaType.APPLICATION_JSON}; resourceMethodInfoDTO.path = "/resource/subresource/{path}"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove( @@ -347,7 +345,7 @@ public class ClassIntrospectorTest { MediaType.APPLICATION_JSON }; resourceMethodInfoDTO.path = "/resource/subresource/{path}"; - resourceMethodInfoDTO.nameBindings = new String[]{}; + resourceMethodInfoDTO.nameBindings = null; assertTrue( wrappers.remove(
