org.jboss.resteasy.client.jaxrs.internal.ClientConfiguration Maven / Gradle / Ivy
package org.jboss.resteasy.client.jaxrs.internal;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import jakarta.ws.rs.RuntimeType;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.client.ClientResponseFilter;
import jakarta.ws.rs.client.RxInvoker;
import jakarta.ws.rs.client.RxInvokerProvider;
import jakarta.ws.rs.container.DynamicFeature;
import jakarta.ws.rs.core.Configurable;
import jakarta.ws.rs.core.Configuration;
import jakarta.ws.rs.core.Feature;
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.ParamConverter;
import jakarta.ws.rs.ext.Providers;
import jakarta.ws.rs.ext.ReaderInterceptor;
import jakarta.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
import jakarta.ws.rs.ext.WriterInterceptor;
import org.jboss.resteasy.core.ThreadLocalResteasyProviderFactory;
import org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages;
import org.jboss.resteasy.spi.HeaderValueProcessor;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.interception.JaxrsInterceptorRegistry;
/**
* @author Bill Burke
* @version $Revision: 1 $
*/
public class ClientConfiguration implements Configuration, Configurable, Providers, HeaderValueProcessor {
protected ResteasyProviderFactory providerFactory;
public ClientConfiguration(final ResteasyProviderFactory factory) {
if (factory instanceof ThreadLocalResteasyProviderFactory) {
this.providerFactory = new LocalResteasyProviderFactory(
((ThreadLocalResteasyProviderFactory) factory).getDelegate());
} else {
this.providerFactory = new LocalResteasyProviderFactory(factory);
}
}
public ClientConfiguration(final ClientConfiguration parent) {
this(parent.getProviderFactory());
setProperties(parent.getProperties());
}
public void setProperties(Map newProps) {
if (newProps != null && !newProps.isEmpty()) {
providerFactory.setProperties(newProps);
}
}
protected ResteasyProviderFactory getProviderFactory() {
return providerFactory;
}
public Map getMutableProperties() {
return providerFactory.getMutableProperties();
}
/**
* Convert an object to a header string. First try StringConverter, then HeaderDelegate, then object.toString()
*
* @param object header object
* @return header string
*/
public String toHeaderString(Object object) {
if (object instanceof String)
return (String) object;
return providerFactory.toHeaderString(object);
}
public MessageBodyWriter getMessageBodyWriter(Class type, Type genericType, Annotation[] annotations,
MediaType mediaType) {
MessageBodyWriter writer = providerFactory.getClientMessageBodyWriter(type, genericType, annotations, mediaType);
if (writer != null)
LogMessages.LOGGER.debugf("MessageBodyWriter: %s", writer.getClass().getName());
return writer;
}
public MessageBodyReader getMessageBodyReader(Class type, Type genericType, Annotation[] annotations,
MediaType mediaType) {
MessageBodyReader reader = providerFactory.getClientMessageBodyReader(type, genericType, annotations, mediaType);
if (reader != null)
LogMessages.LOGGER.debugf("MessageBodyReader: %s", reader.getClass().getName());
return reader;
}
public WriterInterceptor[] getWriterInterceptors(Class declaring, AccessibleObject target) {
JaxrsInterceptorRegistry writerInterceptors = providerFactory.getClientWriterInterceptorRegistry();
return writerInterceptors == null ? null : writerInterceptors.postMatch(declaring, target);
}
public ReaderInterceptor[] getReaderInterceptors(Class declaring, AccessibleObject target) {
JaxrsInterceptorRegistry readerInterceptors = providerFactory.getClientReaderInterceptorRegistry();
return readerInterceptors == null ? null : readerInterceptors.postMatch(declaring, target);
}
public ClientRequestFilter[] getRequestFilters(Class declaring, AccessibleObject target) {
JaxrsInterceptorRegistry requestFilters = providerFactory.getClientRequestFilterRegistry();
return requestFilters == null ? null : requestFilters.postMatch(declaring, target);
}
public ClientResponseFilter[] getResponseFilters(Class declaring, AccessibleObject target) {
JaxrsInterceptorRegistry filters = providerFactory.getClientResponseFilters();
return filters == null ? null : filters.postMatch(declaring, target);
}
public Set getDynamicFeatures() {
return providerFactory.getClientDynamicFeatures();
}
public ParamConverter getParamConverter(Class> clazz, Type genericType, Annotation[] annotations) {
return providerFactory.getParamConverter(clazz, genericType, annotations);
}
public String toString(Object object) {
return providerFactory.toString(object, object.getClass(), null, null);
}
public String toString(Object object, Type type, Annotation[] annotations) {
return providerFactory.toString(object, object.getClass(), type, annotations);
}
// interface implementation
// Providers
@Override
public ExceptionMapper getExceptionMapper(Class type) {
return providerFactory.getExceptionMapper(type);
}
@Override
public ContextResolver getContextResolver(Class contextType, MediaType mediaType) {
return providerFactory.getContextResolver(contextType, mediaType);
}
// Configuration
@Override
public Map getProperties() {
return providerFactory.getProperties();
}
@Override
public Object getProperty(String name) {
return providerFactory.getProperty(name);
}
@Override
public Set> getClasses() {
return providerFactory.getClasses();
}
@Override
public Set
© 2015 - 2025 Weber Informatics LLC | Privacy Policy