This is an automated email from the ASF dual-hosted git repository. buhhunyx pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push: new e81662e [CXF-7672] PrimitiveTextProvider: support java.net.URI and java.net.URL e81662e is described below commit e81662e6df07d03b8b9d1dee0ed829152d5aff83 Author: amarkevich <amarkev...@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 2f3dbfb..2bfb69b 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 b972c79..b5c8d36 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 buhhu...@apache.org.