use of org.glassfish.jersey.message.ReaderModel in project jersey by jersey.
the class MessageBodyFactory method processMessageBodyReadersForType.
private List<ReaderModel> processMessageBodyReadersForType(final Class<?> clazz) {
final List<ReaderModel> suitableReaders = new ArrayList<>();
final Class<?> wrapped = Primitives.wrap(clazz);
for (final ReaderModel reader : readers) {
if (reader.providedType() == null || reader.providedType() == clazz || reader.providedType().isAssignableFrom(wrapped)) {
suitableReaders.add(reader);
}
}
// Type -> Writer.
Collections.sort(suitableReaders, WORKER_BY_TYPE_COMPARATOR);
mbrTypeLookupCache.put(clazz, suitableReaders);
// Type -> MediaType.
typeToMediaTypeReadersCache.put(clazz, getMessageBodyWorkersMediaTypesByType(suitableReaders));
return suitableReaders;
}
use of org.glassfish.jersey.message.ReaderModel in project jersey by jersey.
the class MessageBodyFactory method addReaders.
private static void addReaders(final List<ReaderModel> models, final Set<MessageBodyReader> readers, final boolean custom) {
for (final MessageBodyReader provider : readers) {
final List<MediaType> values = MediaTypes.createFrom(provider.getClass().getAnnotation(Consumes.class));
models.add(new ReaderModel(provider, values, custom));
}
}
use of org.glassfish.jersey.message.ReaderModel in project jersey by jersey.
the class MessageBodyFactory method getMessageBodyReaderMediaTypes.
@Override
@SuppressWarnings("unchecked")
public List<MediaType> getMessageBodyReaderMediaTypes(final Class<?> type, final Type genericType, final Annotation[] annotations) {
final Set<MediaType> readableMediaTypes = new LinkedHashSet<>();
for (final ReaderModel model : readers) {
boolean readableWorker = false;
for (final MediaType mt : model.declaredTypes()) {
if (model.isReadable(type, genericType, annotations, mt)) {
readableMediaTypes.add(mt);
readableWorker = true;
}
if (!readableMediaTypes.contains(MediaType.WILDCARD_TYPE) && readableWorker && model.declaredTypes().contains(MediaType.WILDCARD_TYPE)) {
readableMediaTypes.add(MediaType.WILDCARD_TYPE);
}
}
}
final List<MediaType> mtl = new ArrayList<>(readableMediaTypes);
Collections.sort(mtl, MediaTypes.PARTIAL_ORDER_COMPARATOR);
return mtl;
}
use of org.glassfish.jersey.message.ReaderModel in project jersey by jersey.
the class MessageBodyFactory method _getMessageBodyReader.
@SuppressWarnings("unchecked")
private <T> MessageBodyReader<T> _getMessageBodyReader(final Class<T> c, final Type t, final Annotation[] as, final MediaType mediaType, final List<ReaderModel> models, final PropertiesDelegate propertiesDelegate) {
// Ensure a parameter-less lookup type to prevent excessive memory consumption
// reported in JERSEY-2297
final MediaType lookupType = mediaType == null || mediaType.getParameters().isEmpty() ? mediaType : new MediaType(mediaType.getType(), mediaType.getSubtype());
final ModelLookupKey lookupKey = new ModelLookupKey(c, lookupType);
List<ReaderModel> readers = mbrLookupCache.get(lookupKey);
if (readers == null) {
readers = new ArrayList<>();
for (final ReaderModel model : models) {
if (isCompatible(model, c, mediaType)) {
readers.add(model);
}
}
Collections.sort(readers, new WorkerComparator<>(c, mediaType));
mbrLookupCache.put(lookupKey, readers);
}
if (readers.isEmpty()) {
return null;
}
final TracingLogger tracingLogger = TracingLogger.getInstance(propertiesDelegate);
MessageBodyReader<T> selected = null;
final Iterator<ReaderModel> iterator = readers.iterator();
while (iterator.hasNext()) {
final ReaderModel model = iterator.next();
if (model.isReadable(c, t, as, mediaType)) {
selected = (MessageBodyReader<T>) model.provider();
tracingLogger.log(MsgTraceEvent.MBR_SELECTED, selected);
break;
}
tracingLogger.log(MsgTraceEvent.MBR_NOT_READABLE, model.provider());
}
if (tracingLogger.isLogEnabled(MsgTraceEvent.MBR_SKIPPED)) {
while (iterator.hasNext()) {
final ReaderModel model = iterator.next();
tracingLogger.log(MsgTraceEvent.MBR_SKIPPED, model.provider());
}
}
return selected;
}
use of org.glassfish.jersey.message.ReaderModel in project jersey by jersey.
the class MethodSelectingRouter method isReadable.
private boolean isReadable(final RequestSpecificConsumesProducesAcceptor candidate) {
final Invocable invocable = candidate.methodRouting.method.getInvocable();
final Method handlingMethod = invocable.getHandlingMethod();
final Parameter entityParam = getEntityParam(invocable);
if (entityParam == null) {
return true;
} else {
final Class<?> entityType = entityParam.getRawType();
for (final ReaderModel model : workers.getReaderModelsForType(entityType)) {
if (model.isReadable(entityType, entityParam.getType(), handlingMethod.getDeclaredAnnotations(), candidate.consumes.combinedType)) {
return true;
}
}
}
return false;
}
Aggregations