cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buhhu...@apache.org
Subject [cxf] branch 3.1.x-fixes updated: [CXF-7672] PrimitiveTextProvider: support java.net.URI and java.net.URL
Date Mon, 12 Mar 2018 07:28:13 GMT
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new 074de30  [CXF-7672] PrimitiveTextProvider: support java.net.URI and java.net.URL
074de30 is described below

commit 074de30a21018555b4523f4258ef94fec813fd12
Author: amarkevich <amarkevich@talend.com>
AuthorDate: Fri Mar 9 16:04:31 2018 +0300

    [CXF-7672] PrimitiveTextProvider: support java.net.URI and java.net.URL
---
 .../cxf/jaxrs/provider/PrimitiveTextProvider.java  |  9 ++++---
 .../jaxrs/provider/PrimitiveTextProviderTest.java  | 30 ++++++++++++++++------
 2 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
index 2af8a3e..c742a04 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
@@ -38,14 +38,15 @@ import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 
-@Consumes("text/plain")
-@Produces("text/plain")
+@Consumes(MediaType.TEXT_PLAIN)
+@Produces(MediaType.TEXT_PLAIN)
 public class PrimitiveTextProvider<T> extends AbstractConfigurableProvider
     implements MessageBodyReader<T>, MessageBodyWriter<T> {
 
     private static boolean isSupported(Class<?> type, MediaType mt) {
-        boolean isPrimitive = InjectionUtils.isPrimitiveOnly(type) || Enum.class.isAssignableFrom(type);
-        return isPrimitive && mt.isCompatible(MediaType.TEXT_PLAIN_TYPE);
+        boolean isPrimitive = InjectionUtils.isPrimitiveOnly(type);
+        return (isPrimitive || Enum.class.isAssignableFrom(type) || java.net.URI.class ==
type
+                || java.net.URL.class == type) && mt.isCompatible(MediaType.TEXT_PLAIN_TYPE);
     }
     
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
MediaType mt) {
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
index c6dafc7..80fc89b 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProviderTest.java
@@ -215,20 +215,34 @@ public class PrimitiveTextProviderTest extends Assert {
         TEST
     }
 
-    @SuppressWarnings({ "unchecked", "rawtypes" })
     @Test
     public void testEnum() throws Exception {
-        PrimitiveTextProvider p = new PrimitiveTextProvider<Object>();
+        testClass(TestEnum.TEST);
+    }
+
+    @Test
+    public void testURI() throws Exception {
+        testClass(new java.net.URI("uri"));
+    }
 
-        assertTrue(p.isWriteable(TestEnum.class, null, null, MediaType.TEXT_PLAIN_TYPE));
+    @Test
+    public void testURL() throws Exception {
+        testClass(new java.net.URL("http://www.example.com"));
+    }
+
+    private void testClass(Object value) throws Exception {
+        final PrimitiveTextProvider<Object> p = new PrimitiveTextProvider<Object>();
+
+        assertTrue(p.isWriteable(value.getClass(), null, null, MediaType.TEXT_PLAIN_TYPE));
         ByteArrayOutputStream os = new ByteArrayOutputStream();
-        p.writeTo(TestEnum.TEST, null, null, null, MediaType.TEXT_PLAIN_TYPE, null, os);
-        assertTrue(Arrays.equals(TestEnum.TEST.toString().getBytes(), os.toByteArray()));
+        p.writeTo(value, null, null, null, MediaType.TEXT_PLAIN_TYPE, null, os);
+        assertTrue(Arrays.equals(value.toString().getBytes(), os.toByteArray()));
 
-        assertTrue(p.isReadable(TestEnum.class, null, null, MediaType.TEXT_PLAIN_TYPE));
-        TestEnum valueRead = (TestEnum) p.readFrom(TestEnum.class, null, null, null, null,
+        assertTrue(p.isReadable(value.getClass(), null, null, MediaType.TEXT_PLAIN_TYPE));
+        @SuppressWarnings("unchecked")
+        Object valueRead = p.readFrom((Class<Object>) value.getClass(), null, null,
null, null,
                 new ByteArrayInputStream(os.toByteArray()));
-        assertSame(TestEnum.TEST, valueRead);
+        assertEquals(value, valueRead);
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
buhhunyx@apache.org.

Mime
View raw message