org.jboss.resteasy.reactive.server.jaxrs.ProvidersImpl Maven / Gradle / Ivy
package org.jboss.resteasy.reactive.server.jaxrs;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
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;
import org.jboss.resteasy.reactive.server.core.Deployment;
public class ProvidersImpl implements Providers {
private final Deployment deployment;
public ProvidersImpl(Deployment deployment) {
this.deployment = deployment;
}
@Override
public MessageBodyReader getMessageBodyReader(Class type, Type genericType, Annotation[] annotations,
MediaType mediaType) {
List> readers = deployment.getSerialisers().findReaders(null, type, mediaType);
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 = deployment.getSerialisers().findWriters(null, type, mediaType, RuntimeType.SERVER);
for (MessageBodyWriter> writer : writers) {
if (writer.isWriteable(type, genericType, annotations, mediaType)) {
return (MessageBodyWriter) writer;
}
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public ExceptionMapper getExceptionMapper(Class type) {
Map.Entry> entry = deployment.getExceptionMapper()
.getExceptionMapper(type, null, null);
if (entry != null) {
return (ExceptionMapper) entry.getValue();
}
return null;
}
@Override
public ContextResolver getContextResolver(Class contextType, MediaType mediaType) {
return deployment.getContextResolvers().getContextResolver(contextType, mediaType);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy