From e3c394199345fa0670bd0e1a0f8beb0448f2fac0 Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 17 Aug 2023 18:35:50 +0200 Subject: [PATCH] Deprecate duplicated methods and fields in MBR/MBW Signed-off-by: jansupol --- .../jersey/message/internal/AbstractFormProvider.java | 6 +++--- .../internal/AbstractMessageReaderWriterProvider.java | 11 ++++++++++- .../message/internal/BasicTypesMessageProvider.java | 6 +++--- .../jersey/message/internal/ByteArrayProvider.java | 4 ++-- .../jersey/message/internal/DataSourceProvider.java | 4 ++-- .../jersey/message/internal/EnumMessageProvider.java | 6 +++--- .../jersey/message/internal/InputStreamProvider.java | 4 ++-- .../jersey/message/internal/ReaderProvider.java | 8 ++++---- .../jersey/message/internal/ReaderWriter.java | 4 ++-- .../message/internal/StringMessageProvider.java | 6 +++--- .../jaxb/internal/AbstractCollectionJaxbProvider.java | 6 ++++-- .../jaxb/internal/AbstractJaxbElementProvider.java | 6 ++++-- .../internal/AbstractRootElementJaxbProvider.java | 6 ++++-- .../jersey/jsonb/internal/JsonBindingProvider.java | 3 ++- .../jersey/gson/internal/JsonGsonProvider.java | 5 +++-- .../internal/entity/JettisonArrayProvider.java | 7 ++++--- .../internal/entity/JettisonJaxbElementProvider.java | 3 ++- .../internal/entity/JettisonListElementProvider.java | 3 ++- .../internal/entity/JettisonObjectProvider.java | 7 ++++--- .../internal/entity/JettisonRootElementProvider.java | 3 ++- .../tests/e2e/client/RequestScopedReadEntityTest.java | 6 ++++-- .../AbstractDisableMetainfServicesLookupTest.java | 7 ++++--- .../tests/e2e/server/SingletonProviderTest.java | 7 ++++--- .../tests/e2e/common/ProvidersOrderingTest.java | 5 +++-- .../message/internal/StringMessageProvider.java | 6 +++--- 25 files changed, 83 insertions(+), 56 deletions(-) diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractFormProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractFormProvider.java index 1df64714c7..6d1ad387c1 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractFormProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractFormProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -43,7 +43,7 @@ public abstract class AbstractFormProvider extends AbstractMessageReaderWrite public > M readFrom(M map, MediaType mediaType, boolean decode, InputStream entityStream) throws IOException { - final String encoded = readFromAsString(entityStream, mediaType); + final String encoded = ReaderWriter.readFromAsString(entityStream, mediaType); final String charsetName = ReaderWriter.getCharset(mediaType).name(); @@ -90,6 +90,6 @@ public > void writeTo( } } - writeToAsString(sb.toString(), entityStream, mediaType); + ReaderWriter.writeToAsString(sb.toString(), entityStream, mediaType); } } diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractMessageReaderWriterProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractMessageReaderWriterProvider.java index 61362bcb0a..a0c715d100 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractMessageReaderWriterProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/AbstractMessageReaderWriterProvider.java @@ -81,11 +81,14 @@ public static void writeTo(Reader in, Writer out) throws IOException { * Get the character set from a media type. *

* The character set is obtained from the media type parameter "charset". - * If the parameter is not present the {@link #UTF8} charset is utilized. + * If the parameter is not present the {@link StandardCharsets#UTF_8} charset is utilized. * * @param m the media type. * @return the character set. + * + * @deprecated use {@code ReaderWriter.getCharset(m)} instead */ + @Deprecated public static Charset getCharset(MediaType m) { return ReaderWriter.getCharset(m); } @@ -99,7 +102,10 @@ public static Charset getCharset(MediaType m) { * @return the string. * * @throws IOException if there is an error reading from the input stream. + * + * @deprecated use {@code ReaderWriter.readFromAsString(in, type)} instead */ + @Deprecated public static String readFromAsString(InputStream in, MediaType type) throws IOException { return ReaderWriter.readFromAsString(in, type); } @@ -112,7 +118,10 @@ public static String readFromAsString(InputStream in, MediaType type) throws IOE * @param type the media type that determines the character set defining * how to decode bytes to characters. * @throws IOException in case of a write failure. + * + * @deprecated use {@code ReaderWriter.writeToAsString(s, out, type)} instead */ + @Deprecated public static void writeToAsString(String s, OutputStream out, MediaType type) throws IOException { ReaderWriter.writeToAsString(s, out, type); } diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/BasicTypesMessageProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/BasicTypesMessageProvider.java index b69a170420..7d661ea700 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/BasicTypesMessageProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/BasicTypesMessageProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -144,7 +144,7 @@ public Object readFrom( MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { - final String entityString = readFromAsString(entityStream, mediaType); + final String entityString = ReaderWriter.readFromAsString(entityStream, mediaType); if (entityString.isEmpty()) { throw new NoContentException(LocalizationMessages.ERROR_READING_ENTITY_MISSING()); } @@ -210,6 +210,6 @@ public void writeTo( MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - writeToAsString(o.toString(), entityStream, mediaType); + ReaderWriter.writeToAsString(o.toString(), entityStream, mediaType); } } diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/ByteArrayProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/ByteArrayProvider.java index 4871013d9f..9a7b4a0f9d 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/ByteArrayProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/ByteArrayProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -52,7 +52,7 @@ public byte[] readFrom( MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - writeTo(entityStream, out); + ReaderWriter.writeTo(entityStream, out); return out.toByteArray(); } diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/DataSourceProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/DataSourceProvider.java index 10c093242a..57113a224b 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/DataSourceProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/DataSourceProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -162,7 +162,7 @@ public void writeTo( final OutputStream entityStream) throws IOException { final InputStream in = t.getInputStream(); try { - writeTo(in, entityStream); + ReaderWriter.writeTo(in, entityStream); } finally { in.close(); } diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/EnumMessageProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/EnumMessageProvider.java index bcf30bd450..bd19684c7f 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/EnumMessageProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/EnumMessageProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -50,7 +50,7 @@ public Enum readFrom( MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { - final String value = readFromAsString(entityStream, mediaType); + final String value = ReaderWriter.readFromAsString(entityStream, mediaType); return Enum.valueOf(type, value); } @@ -67,6 +67,6 @@ public void writeTo( MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - writeToAsString(anEnum.name(), entityStream, mediaType); + ReaderWriter.writeToAsString(anEnum.name(), entityStream, mediaType); } } \ No newline at end of file diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/InputStreamProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/InputStreamProvider.java index 2419dda88d..e3663a0f71 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/InputStreamProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/InputStreamProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -79,7 +79,7 @@ public void writeTo( MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { try { - writeTo(t, entityStream); + ReaderWriter.writeTo(t, entityStream); } finally { t.close(); } diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderProvider.java index 4cf4cc6469..be0a9dc062 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -66,7 +66,7 @@ public Reader readFrom( new ByteArrayInputStream(new byte[0]), MessageUtils.getCharset(mediaType))); } - return new BufferedReader(new InputStreamReader(entityStream, getCharset(mediaType))); + return new BufferedReader(new InputStreamReader(entityStream, ReaderWriter.getCharset(mediaType))); } @Override @@ -86,8 +86,8 @@ public void writeTo( final OutputStream entityStream) throws IOException { try { final OutputStreamWriter out = new OutputStreamWriter(entityStream, - getCharset(mediaType)); - writeTo(t, out); + ReaderWriter.getCharset(mediaType)); + ReaderWriter.writeTo(t, out); out.flush(); } finally { t.close(); diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderWriter.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderWriter.java index e9944cf2a2..4c663872c4 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderWriter.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/ReaderWriter.java @@ -119,14 +119,14 @@ public static void writeTo(Reader in, Writer out) throws IOException { * Get the character set from a media type. *

* The character set is obtained from the media type parameter "charset". - * If the parameter is not present the {@link #UTF8} charset is utilized. + * If the parameter is not present the {@link StandardCharsets#UTF_8} charset is utilized. * * @param m the media type. * @return the character set. */ public static Charset getCharset(MediaType m) { String name = (m == null) ? null : m.getParameters().get(MediaType.CHARSET_PARAMETER); - return (name == null) ? UTF8 : Charset.forName(name); + return (name == null) ? StandardCharsets.UTF_8 : Charset.forName(name); } /** diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/StringMessageProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/StringMessageProvider.java index 45cd542511..1a6b4f47c4 100644 --- a/core-common/src/main/java/org/glassfish/jersey/message/internal/StringMessageProvider.java +++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/StringMessageProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -51,7 +51,7 @@ public String readFrom( MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { - return readFromAsString(entityStream, mediaType); + return ReaderWriter.readFromAsString(entityStream, mediaType); } @Override @@ -73,6 +73,6 @@ public void writeTo( MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { - writeToAsString(t, entityStream, mediaType); + ReaderWriter.writeToAsString(t, entityStream, mediaType); } } diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java index ec704969df..5f9e1a28db 100644 --- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java +++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java @@ -26,6 +26,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -56,6 +57,7 @@ import javax.xml.stream.XMLStreamReader; import org.glassfish.jersey.message.internal.EntityInputStream; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * An abstract provider for {@code T[]}, {@code Collection<T>}, @@ -238,12 +240,12 @@ public final void writeTo( ? Arrays.asList((Object[]) t) : (Collection) t; final Class elementType = getElementClass(type, genericType); - final Charset charset = getCharset(mediaType); + final Charset charset = ReaderWriter.getCharset(mediaType); final String charsetName = charset.name(); final Marshaller m = getMarshaller(elementType, mediaType); m.setProperty(Marshaller.JAXB_FRAGMENT, true); - if (charset != UTF8) { + if (charset != StandardCharsets.UTF_8) { m.setProperty(Marshaller.JAXB_ENCODING, charsetName); } setHeader(m, annotations); diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java index 9481a8cf4c..b7a125a17e 100644 --- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java +++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java @@ -23,6 +23,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import javax.ws.rs.BadRequestException; import javax.ws.rs.InternalServerErrorException; @@ -41,6 +42,7 @@ import org.glassfish.jersey.internal.LocalizationMessages; import org.glassfish.jersey.message.internal.EntityInputStream; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * An abstract provider for {@link JAXBElement}. @@ -145,8 +147,8 @@ public final void writeTo( OutputStream entityStream) throws IOException { try { final Marshaller m = getMarshaller(t.getDeclaredType(), mediaType); - final Charset c = getCharset(mediaType); - if (c != UTF8) { + final Charset c = ReaderWriter.getCharset(mediaType); + if (c != StandardCharsets.UTF_8) { m.setProperty(Marshaller.JAXB_ENCODING, c.name()); } setHeader(m, annotations); diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java index 261e982bc6..9b5c14c3d7 100644 --- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java +++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java @@ -22,6 +22,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import javax.ws.rs.BadRequestException; import javax.ws.rs.InternalServerErrorException; @@ -42,6 +43,7 @@ import org.glassfish.jersey.internal.LocalizationMessages; import org.glassfish.jersey.message.internal.EntityInputStream; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * An abstract provider for JAXB types that are annotated with @@ -150,8 +152,8 @@ public final void writeTo( OutputStream entityStream) throws IOException { try { final Marshaller m = getMarshaller(type, mediaType); - final Charset c = getCharset(mediaType); - if (c != UTF8) { + final Charset c = ReaderWriter.getCharset(mediaType); + if (c != StandardCharsets.UTF_8) { m.setProperty(Marshaller.JAXB_ENCODING, c.name()); } setHeader(m, annotations); diff --git a/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java b/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java index 8123741c1d..9b814d7956 100644 --- a/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java +++ b/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java @@ -42,6 +42,7 @@ import org.glassfish.jersey.jsonb.LocalizationMessages; import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider; import org.glassfish.jersey.message.internal.EntityInputStream; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * Entity provider (reader and writer) for JSONB. @@ -102,7 +103,7 @@ public void writeTo(Object o, Class type, Type genericType, OutputStream entityStream) throws IOException, WebApplicationException { Jsonb jsonb = getJsonb(type); try { - entityStream.write(jsonb.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType))); + entityStream.write(jsonb.toJson(o).getBytes(ReaderWriter.getCharset(mediaType))); entityStream.flush(); } catch (IOException e) { throw new ProcessingException(LocalizationMessages.ERROR_JSONB_SERIALIZATION(), e); diff --git a/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java b/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java index 556358757c..1ff0b549a4 100644 --- a/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java +++ b/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java @@ -42,6 +42,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * Entity provider (reader and writer) for Gson. @@ -81,7 +82,7 @@ public Object readFrom(Class type, Type genericType, Gson gson = getGson(type); try { return gson.fromJson(new InputStreamReader(entityInputStream, - AbstractMessageReaderWriterProvider.getCharset(mediaType)), genericType); + ReaderWriter.getCharset(mediaType)), genericType); } catch (Exception e) { throw new ProcessingException(LocalizationMessages.ERROR_GSON_DESERIALIZATION(), e); } @@ -100,7 +101,7 @@ public void writeTo(Object o, Class type, Type genericType, OutputStream entityStream) throws IOException, WebApplicationException { Gson gson = getGson(type); try { - entityStream.write(gson.toJson(o).getBytes(AbstractMessageReaderWriterProvider.getCharset(mediaType))); + entityStream.write(gson.toJson(o).getBytes(ReaderWriter.getCharset(mediaType))); entityStream.flush(); } catch (Exception e) { throw new ProcessingException(LocalizationMessages.ERROR_GSON_SERIALIZATION(), e); diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonArrayProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonArrayProvider.java index db4418dab0..7146dc7917 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonArrayProvider.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonArrayProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -33,6 +33,7 @@ import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONException; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * Low-level JSON media type message entity provider (reader & writer) for @@ -70,7 +71,7 @@ public JSONArray readFrom( MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { try { - return new JSONArray(readFromAsString(entityStream, mediaType)); + return new JSONArray(ReaderWriter.readFromAsString(entityStream, mediaType)); } catch (JSONException je) { throw new WebApplicationException( new Exception(LocalizationMessages.ERROR_PARSING_JSON_ARRAY(), je), @@ -89,7 +90,7 @@ public void writeTo( OutputStream entityStream) throws IOException { try { OutputStreamWriter writer = new OutputStreamWriter(entityStream, - getCharset(mediaType)); + ReaderWriter.getCharset(mediaType)); t.write(writer); writer.write("\n"); writer.flush(); diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java index 6cf18bcd89..b827baa894 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java @@ -40,6 +40,7 @@ import org.glassfish.jersey.jaxb.internal.AbstractJaxbElementProvider; import org.glassfish.jersey.jettison.JettisonJaxbContext; import org.glassfish.jersey.jettison.JettisonMarshaller; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * JSON message entity media type provider (reader & writer) for {@link javax.xml.bind.JAXBElement} @@ -95,7 +96,7 @@ protected boolean isSupported(MediaType m) { @Override protected final JAXBElement readFrom(Class type, MediaType mediaType, Unmarshaller unmarshaller, InputStream entityStream) throws JAXBException { - final Charset c = getCharset(mediaType); + final Charset c = ReaderWriter.getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(unmarshaller) .unmarshalJAXBElementFromJSON(new InputStreamReader(entityStream, c), type); diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java index 15004d5b50..5bf34fc016 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java @@ -47,6 +47,7 @@ import org.glassfish.jersey.jettison.JettisonConfig; import org.glassfish.jersey.jettison.JettisonConfigured; import org.glassfish.jersey.jettison.internal.Stax2JettisonFactory; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * JSON message entity media type provider (reader & writer) for collection @@ -132,7 +133,7 @@ public final void writeCollection(Class elementType, Collection t, MediaTy protected final XMLStreamReader getXMLStreamReader(Class elementType, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws XMLStreamException { JettisonConfig c = JettisonConfig.DEFAULT; - final Charset charset = getCharset(mediaType); + final Charset charset = ReaderWriter.getCharset(mediaType); if (u instanceof JettisonConfigured) { c = ((JettisonConfigured) u).getJSONConfiguration(); } diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonObjectProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonObjectProvider.java index f0bb28a0b3..9c42caf731 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonObjectProvider.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonObjectProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -33,6 +33,7 @@ import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * Low-level JSON media type message entity provider (reader & writer) for @@ -70,7 +71,7 @@ public JSONObject readFrom( MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { try { - return new JSONObject(readFromAsString(entityStream, mediaType)); + return new JSONObject(ReaderWriter.readFromAsString(entityStream, mediaType)); } catch (JSONException je) { throw new WebApplicationException( new Exception(LocalizationMessages.ERROR_PARSING_JSON_OBJECT(), je), @@ -89,7 +90,7 @@ public void writeTo( OutputStream entityStream) throws IOException { try { OutputStreamWriter writer = new OutputStreamWriter(entityStream, - getCharset(mediaType)); + ReaderWriter.getCharset(mediaType)); t.write(writer); writer.flush(); } catch (JSONException je) { diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java index 83040da558..68e39e26d9 100644 --- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java +++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java @@ -39,6 +39,7 @@ import org.glassfish.jersey.jaxb.internal.AbstractRootElementJaxbProvider; import org.glassfish.jersey.jettison.JettisonJaxbContext; import org.glassfish.jersey.jettison.JettisonMarshaller; +import org.glassfish.jersey.message.internal.ReaderWriter; /** * JSON message entity media type provider (reader & writer) for JAXB types that @@ -94,7 +95,7 @@ protected boolean isSupported(MediaType m) { @Override protected final Object readFrom(Class type, MediaType mediaType, Unmarshaller u, InputStream entityStream) throws JAXBException { - final Charset c = getCharset(mediaType); + final Charset c = ReaderWriter.getCharset(mediaType); return JettisonJaxbContext.getJSONUnmarshaller(u) .unmarshalFromJSON(new InputStreamReader(entityStream, c), type); diff --git a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java index 72855f06d3..b097f9ab82 100644 --- a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java +++ b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java @@ -37,6 +37,7 @@ import org.glassfish.jersey.client.ClientRequest; import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider; +import org.glassfish.jersey.message.internal.ReaderWriter; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; @@ -91,7 +92,7 @@ public Message readFrom( MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { return clientRequestProvider.get() != null - ? new Message(readFromAsString(entityStream, mediaType)) : new Message("failed"); + ? new Message(ReaderWriter.readFromAsString(entityStream, mediaType)) : new Message("failed"); } @Override @@ -108,7 +109,8 @@ public void writeTo( MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { - writeToAsString((clientRequestProvider.get() != null) ? message.text : "failed", entityStream, mediaType); + ReaderWriter + .writeToAsString((clientRequestProvider.get() != null) ? message.text : "failed", entityStream, mediaType); } } diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/AbstractDisableMetainfServicesLookupTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/AbstractDisableMetainfServicesLookupTest.java index ddd0b8303a..0caa21a214 100644 --- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/AbstractDisableMetainfServicesLookupTest.java +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/AbstractDisableMetainfServicesLookupTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -46,6 +46,7 @@ import org.glassfish.jersey.internal.ServiceFinderBinder; import org.glassfish.jersey.internal.inject.AbstractBinder; import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider; +import org.glassfish.jersey.message.internal.ReaderWriter; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; @@ -145,7 +146,7 @@ public UselessMessage readFrom( MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { - return new UselessMessage(readFromAsString(entityStream, mediaType)); + return new UselessMessage(ReaderWriter.readFromAsString(entityStream, mediaType)); } @Override @@ -167,7 +168,7 @@ public void writeTo( MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { - writeToAsString(t.getMessage(), entityStream, mediaType); + ReaderWriter.writeToAsString(t.getMessage(), entityStream, mediaType); } } // class UselessMessageBodyWriter diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/SingletonProviderTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/SingletonProviderTest.java index d75491eb3c..7d232899e5 100644 --- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/SingletonProviderTest.java +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/SingletonProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -40,6 +40,7 @@ import javax.ws.rs.ext.Provider; import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider; +import org.glassfish.jersey.message.internal.ReaderWriter; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.spi.ContextResolvers; import org.glassfish.jersey.test.JerseyTest; @@ -224,7 +225,7 @@ public String readFrom( MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { - return readFromAsString(entityStream, mediaType) + this + ":" + readerCounter++; + return ReaderWriter.readFromAsString(entityStream, mediaType) + this + ":" + readerCounter++; } @Override @@ -246,7 +247,7 @@ public void writeTo( MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { - writeToAsString(t + this + ":" + counter++, entityStream, mediaType); + ReaderWriter.writeToAsString(t + this + ":" + counter++, entityStream, mediaType); } } } diff --git a/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/ProvidersOrderingTest.java b/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/ProvidersOrderingTest.java index bab8c37bda..e7ad1e8957 100644 --- a/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/ProvidersOrderingTest.java +++ b/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/ProvidersOrderingTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -45,6 +45,7 @@ import org.glassfish.jersey.message.MessageBodyWorkers; import org.glassfish.jersey.message.internal.AbstractMessageReaderWriterProvider; +import org.glassfish.jersey.message.internal.ReaderWriter; import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; @@ -403,7 +404,7 @@ public byte[] readFrom( MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - writeTo(entityStream, out); + ReaderWriter.writeTo(entityStream, out); counter++; return out.toByteArray(); } diff --git a/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/message/internal/StringMessageProvider.java b/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/message/internal/StringMessageProvider.java index 203ecbc98d..d275e40614 100644 --- a/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/message/internal/StringMessageProvider.java +++ b/tests/integration/microprofile/rest-client/src/test/java/org/glassfish/jersey/message/internal/StringMessageProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -56,7 +56,7 @@ public String readFrom( MediaType mediaType, MultivaluedMap httpHeaders, InputStream entityStream) throws IOException { - return readFromAsString(entityStream, mediaType); + return ReaderWriter.readFromAsString(entityStream, mediaType); } @Override @@ -78,6 +78,6 @@ public void writeTo( MediaType mediaType, MultivaluedMap httpHeaders, OutputStream entityStream) throws IOException { - writeToAsString(t, entityStream, mediaType); + ReaderWriter.writeToAsString(t, entityStream, mediaType); } }