All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.resteasy.reactive.client.impl.ProvidersImpl Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package org.jboss.resteasy.reactive.client.impl;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.List;

import jakarta.ws.rs.RuntimeType;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.ext.ContextResolver;
import jakarta.ws.rs.ext.ExceptionMapper;
import jakarta.ws.rs.ext.MessageBodyReader;
import jakarta.ws.rs.ext.MessageBodyWriter;
import jakarta.ws.rs.ext.Providers;

public class ProvidersImpl implements Providers {

    private final RestClientRequestContext context;

    public ProvidersImpl(RestClientRequestContext context) {
        this.context = context;
    }

    @Override
    public  MessageBodyReader getMessageBodyReader(Class type, Type genericType, Annotation[] annotations,
            MediaType mediaType) {
        List> readers = context.getRestClient().getClientContext().getSerialisers()
                .findReaders(context.getConfiguration(), type, mediaType, RuntimeType.CLIENT);
        for (MessageBodyReader reader : readers) {
            if (reader.isReadable(type, genericType, annotations, mediaType)) {
                return (MessageBodyReader) reader;
            }
        }
        return null;
    }

    @Override
    public  MessageBodyWriter getMessageBodyWriter(Class type, Type genericType, Annotation[] annotations,
            MediaType mediaType) {
        List> writers = context.getRestClient().getClientContext().getSerialisers()
                .findWriters(context.getConfiguration(), type, mediaType, RuntimeType.CLIENT);
        for (MessageBodyWriter writer : writers) {
            if (writer.isWriteable(type, genericType, annotations, mediaType)) {
                return (MessageBodyWriter) writer;
            }
        }
        return null;
    }

    @Override
    public  ExceptionMapper getExceptionMapper(Class type) {
        throw new UnsupportedOperationException(
                "`jakarta.ws.rs.ext.ExceptionMapper` are not supported in REST Client Reactive");
    }

    @Override
    public  ContextResolver getContextResolver(Class contextType, MediaType mediaType) {
        // TODO: support getting context resolver by mediaType (which is provided using the `@Produces` annotation).
        return context.getConfiguration().getContextResolver(contextType);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy