diff --git a/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveCompressionHandler.java b/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveCompressionHandler.java index c6be2343ccdb3..13ae7da4bebf2 100644 --- a/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveCompressionHandler.java +++ b/extensions/resteasy-reactive/rest/runtime/src/main/java/io/quarkus/resteasy/reactive/server/runtime/ResteasyReactiveCompressionHandler.java @@ -5,6 +5,7 @@ import jakarta.ws.rs.core.HttpHeaders; import jakarta.ws.rs.core.MediaType; +import org.jboss.resteasy.reactive.common.util.MediaTypeHelper; import org.jboss.resteasy.reactive.server.core.EncodedMediaType; import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext; import org.jboss.resteasy.reactive.server.spi.ServerHttpResponse; @@ -65,7 +66,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti if (encodedProduces == null) { synchronized (this) { if (encodedProduces == null) { - encodedProduces = new EncodedMediaType(MediaType.valueOf(produces)); + encodedProduces = new EncodedMediaType(MediaTypeHelper.valueOf(produces)); } } } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java index 4aa5847e58c06..1ff0d9ae77ba0 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/headers/HeaderUtil.java @@ -116,7 +116,7 @@ public static URI getLocation(MultivaluedMap headers) public static MediaType getMediaType(MultivaluedMap headers) { Object first = headers.getFirst(HttpHeaders.CONTENT_TYPE); if (first instanceof String contentType) { - return MediaType.valueOf(contentType); + return MediaTypeHelper.valueOf(contentType); } else { return (MediaType) first; } @@ -281,10 +281,10 @@ public static List getAcceptableMediaTypes(MultivaluedMap mediaTypes() { synchronized (this) { List ret = new ArrayList<>(); for (String i : mediaTypeStrings) { - ret.add(MediaType.valueOf(i)); + ret.add(MediaTypeHelper.valueOf(i)); } mediaTypes = Collections.unmodifiableList(ret); } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceReader.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceReader.java index 23930a80f5858..a52e1080233bc 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceReader.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceReader.java @@ -87,7 +87,7 @@ public List mediaTypes() { synchronized (this) { List mts = new ArrayList<>(mediaTypeStrings.size()); for (int i = 0; i < mediaTypeStrings.size(); i++) { - mts.add(MediaType.valueOf(mediaTypeStrings.get(i))); + mts.add(MediaTypeHelper.valueOf(mediaTypeStrings.get(i))); } mediaTypes = Collections.unmodifiableList(mts); } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceWriter.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceWriter.java index 5de3a260ba4ed..f638840e8617f 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceWriter.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceWriter.java @@ -90,7 +90,7 @@ public List mediaTypes() { synchronized (this) { List mts = new ArrayList<>(mediaTypeStrings.size()); for (int i = 0; i < mediaTypeStrings.size(); i++) { - mts.add(MediaType.valueOf(mediaTypeStrings.get(i))); + mts.add(MediaTypeHelper.valueOf(mediaTypeStrings.get(i))); } mediaTypes = Collections.unmodifiableList(mts); } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java index ce799d31a24d6..491b0c54c387f 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/MediaTypeHelper.java @@ -12,6 +12,8 @@ import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; +import org.jboss.resteasy.reactive.common.headers.MediaTypeHeaderDelegate; + /** * @author Bill Burke */ @@ -21,6 +23,14 @@ public class MediaTypeHelper { public static final MediaTypeComparator QS_COMPARATOR = new MediaTypeComparator("qs"); private static final String MEDIA_TYPE_SUFFIX_DELIM = "+"; + public static MediaType valueOf(String value) { + return MediaTypeHeaderDelegate.INSTANCE.fromString(value); + } + + public static String toString(MediaType mediaType) { + return MediaTypeHeaderDelegate.INSTANCE.toString(mediaType); + } + private static float getQTypeWithParamInfo(MediaType type, String parameterName) { if (type.getParameters() != null) { String val = type.getParameters().get(parameterName); @@ -212,7 +222,7 @@ public static List parseHeader(String header) { ArrayList types = new ArrayList<>(); String[] medias = header.split(","); for (String media : medias) { - types.add(MediaType.valueOf(media.trim())); + types.add(valueOf(media.trim())); } return types; } @@ -289,7 +299,7 @@ public static List toListOfMediaType(String[] mediaTypes) { List list = new ArrayList<>(mediaTypes.length); for (String mediaType : mediaTypes) { - list.add(MediaType.valueOf(mediaType)); + list.add(valueOf(mediaType)); } return Collections.unmodifiableList(list); diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/ServerMediaType.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/ServerMediaType.java index 9b34b68e1caaa..d385e9672428f 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/ServerMediaType.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/util/ServerMediaType.java @@ -10,6 +10,8 @@ import jakarta.ws.rs.core.MediaType; +import org.jboss.resteasy.reactive.common.headers.MediaTypeHeaderDelegate; + /** * A representation of a server side media type. * @@ -25,7 +27,7 @@ public class ServerMediaType { public static List mediaTypesFromArray(String[] mediaTypesStrs) { List mediaTypes = new ArrayList<>(mediaTypesStrs.length); for (String mediaTypesStr : mediaTypesStrs) { - mediaTypes.add(MediaType.valueOf(mediaTypesStr)); + mediaTypes.add(MediaTypeHeaderDelegate.INSTANCE.fromString(mediaTypesStr)); } return mediaTypes; } diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/EncodedMediaType.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/EncodedMediaType.java index 1c3c4310be4c9..9039e57b90116 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/EncodedMediaType.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/EncodedMediaType.java @@ -53,7 +53,7 @@ public MediaType getMediaType() { @Override public String getEncoded() { if (encoded == null) { - return encoded = mediaType.toString(); + return encoded = MediaTypeHelper.toString(mediaType); } return encoded; } diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java index 2b655205434df..e67c23eceab45 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeResourceDeployment.java @@ -149,7 +149,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz, Map pathParameterIndexes = buildParamIndexMap(classPathTemplate, methodPathTemplate); MediaType streamElementType = null; if (method.getStreamElementType() != null) { - streamElementType = MediaType.valueOf(method.getStreamElementType()); + streamElementType = MediaTypeHelper.valueOf(method.getStreamElementType()); } List consumesMediaTypes; if (method.getConsumes() == null) { @@ -157,7 +157,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz, } else { consumesMediaTypes = new ArrayList<>(method.getConsumes().length); for (String s : method.getConsumes()) { - consumesMediaTypes.add(MediaType.valueOf(s)); + consumesMediaTypes.add(MediaTypeHelper.valueOf(s)); } } @@ -407,7 +407,7 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz, if (method.getProduces() != null && method.getProduces().length > 0) { //the method can only produce a single content type, which is the most common case if (method.getProduces().length == 1) { - MediaType mediaType = MediaType.valueOf(method.getProduces()[0]); + MediaType mediaType = MediaTypeHelper.valueOf(method.getProduces()[0]); //its a wildcard type, makes it hard to determine statically if (mediaType.isWildcardType() || mediaType.isWildcardSubtype()) { handlers.add(new VariableProducesHandler(serverMediaType, serialisers)); diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java index efbd79da49c24..b9bf02d05af53 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/ClassRoutingHandler.java @@ -114,7 +114,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti try { if (MediaTypeHelper.getFirstMatch( target.value.getConsumes(), - Collections.singletonList(MediaType.valueOf(contentType))) == null) { + Collections.singletonList(MediaTypeHelper.valueOf(contentType))) == null) { throw new NotSupportedException("The content-type header value did not match the value in @Consumes"); } } catch (IllegalArgumentException e) { diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/MediaTypeMapper.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/MediaTypeMapper.java index 79780144bb854..e824f8deb3e16 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/MediaTypeMapper.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/MediaTypeMapper.java @@ -100,7 +100,7 @@ private List contentTypeFromRequest(ResteasyReactiveRequestContext re } List result = new ArrayList<>(contentTypeList.size()); for (String s : contentTypeList) { - result.add(MediaType.valueOf(s)); + result.add(MediaTypeHelper.valueOf(s)); } return result; } diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java index 88bd9824402c5..a9b09c19c00b7 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/handlers/RequestDeserializeHandler.java @@ -52,7 +52,7 @@ public void handle(ResteasyReactiveRequestContext requestContext) throws Excepti Object requestType = requestContext.getHeader(HttpHeaders.CONTENT_TYPE, true); if (requestType != null) { try { - effectiveRequestType = MediaType.valueOf((String) requestType); + effectiveRequestType = MediaTypeHelper.valueOf((String) requestType); } catch (Exception e) { log.debugv("Incorrect media type", e); throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build()); diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/jaxrs/HttpHeadersImpl.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/jaxrs/HttpHeadersImpl.java index 35185cb1ed0d8..2c1ea75accd86 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/jaxrs/HttpHeadersImpl.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/jaxrs/HttpHeadersImpl.java @@ -13,6 +13,7 @@ import org.jboss.resteasy.reactive.common.headers.HeaderUtil; import org.jboss.resteasy.reactive.common.util.CaseInsensitiveMap; +import org.jboss.resteasy.reactive.common.util.MediaTypeHelper; import org.jboss.resteasy.reactive.common.util.UnmodifiableMultivaluedMap; /** @@ -85,7 +86,7 @@ public MediaType getMediaType() { if (obj == cachedMediaTypeString) return cachedMediaType; cachedMediaTypeString = obj; - cachedMediaType = MediaType.valueOf(obj); + cachedMediaType = MediaTypeHelper.valueOf(obj); return cachedMediaType; }