@Override public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return workers.get().getMessageBodyWriter(type, genericType, annotations, mediaType); }
@Override public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return workers.get().getMessageBodyWriter(type, genericType, annotations, mediaType); }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public void writeTo(Optional<?> entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (!entity.isPresent()) { throw EmptyOptionalException.INSTANCE; } final Type innerGenericType = (genericType instanceof ParameterizedType) ? ((ParameterizedType) genericType).getActualTypeArguments()[0] : entity.get().getClass(); final MessageBodyWriter writer = requireNonNull(mbw).get().getMessageBodyWriter(entity.get().getClass(), innerGenericType, annotations, mediaType); writer.writeTo(entity.get(), entity.get().getClass(), innerGenericType, annotations, mediaType, httpHeaders, entityStream); }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public void writeTo(Optional<?> entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (!entity.isPresent()) { throw EmptyOptionalException.INSTANCE; } final ParameterizedType actualGenericType = (ParameterizedType) genericType; final Type actualGenericTypeArgument = actualGenericType.getActualTypeArguments()[0]; final MessageBodyWriter writer = requireNonNull(mbw).get().getMessageBodyWriter(entity.get().getClass(), actualGenericTypeArgument, annotations, mediaType); writer.writeTo(entity.get(), entity.get().getClass(), actualGenericTypeArgument, annotations, mediaType, httpHeaders, entityStream); }
@Override public void writeTo(T entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> responseHeaders, OutputStream entityStream) throws IOException, WebApplicationException { final MessageBodyWriter<U> writer = requireNonNull(mbw).get().getMessageBodyWriter(representation, representation, annotations, contentType); // Fix the headers, because Dropwizard error mappers always set the content type to APPLICATION_JSON responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, contentType); writer.writeTo(getRepresentation(entity), representation, representation, annotations, contentType, responseHeaders, entityStream); }
workers.getMessageBodyWriter(bean.getClass(), bean.getClass(), new Annotation[0], MediaType.APPLICATION_JSON_TYPE);
MessageBodyWriter writer = messageBodyWorkers.getMessageBodyWriter(entityClass, entityType, EMPTY_ANNOTATIONS, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
final MessageBodyWriter messageBodyWriter = workersProvider.get().getMessageBodyWriter(outboundEvent.getType(), outboundEvent.getGenericType(), annotations, eventMediaType); messageBodyWriter.writeTo(
@Override @SuppressWarnings("unchecked") public void aroundWriteTo(final WriterInterceptorContext context) throws WebApplicationException, IOException { processedCount--; //this is not regular interceptor -> count down traceBefore(null, MsgTraceEvent.WI_BEFORE); try { final TracingLogger tracingLogger = getTracingLogger(); if (tracingLogger.isLogEnabled(MsgTraceEvent.MBW_FIND)) { tracingLogger.log(MsgTraceEvent.MBW_FIND, context.getType().getName(), (context.getGenericType() instanceof Class ? ((Class) context.getGenericType()).getName() : context.getGenericType()), context.getMediaType(), java.util.Arrays.toString(context.getAnnotations())); } final MessageBodyWriter writer = workers.getMessageBodyWriter(context.getType(), context.getGenericType(), context.getAnnotations(), context.getMediaType(), WriterInterceptorExecutor.this); if (writer == null) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_NOTFOUND_MESSAGEBODYWRITER( context.getMediaType(), context.getType(), context.getGenericType())); throw new MessageBodyProviderNotFoundException(LocalizationMessages.ERROR_NOTFOUND_MESSAGEBODYWRITER( context.getMediaType(), context.getType(), context.getGenericType())); } invokeWriteTo(context, writer); } finally { clearLastTracedInterceptor(); traceAfter(null, MsgTraceEvent.WI_AFTER); } }
@Override @SuppressWarnings("unchecked") public void aroundWriteTo(final WriterInterceptorContext context) throws WebApplicationException, IOException { processedCount--; //this is not regular interceptor -> count down traceBefore(null, MsgTraceEvent.WI_BEFORE); try { final TracingLogger tracingLogger = getTracingLogger(); if (tracingLogger.isLogEnabled(MsgTraceEvent.MBW_FIND)) { tracingLogger.log(MsgTraceEvent.MBW_FIND, context.getType().getName(), (context.getGenericType() instanceof Class ? ((Class) context.getGenericType()).getName() : context.getGenericType()), context.getMediaType(), java.util.Arrays.toString(context.getAnnotations())); } final MessageBodyWriter writer = workers.getMessageBodyWriter(context.getType(), context.getGenericType(), context.getAnnotations(), context.getMediaType(), WriterInterceptorExecutor.this); if (writer == null) { LOGGER.log(Level.SEVERE, LocalizationMessages.ERROR_NOTFOUND_MESSAGEBODYWRITER( context.getMediaType(), context.getType(), context.getGenericType())); throw new MessageBodyProviderNotFoundException(LocalizationMessages.ERROR_NOTFOUND_MESSAGEBODYWRITER( context.getMediaType(), context.getType(), context.getGenericType())); } invokeWriteTo(context, writer); } finally { clearLastTracedInterceptor(); traceAfter(null, MsgTraceEvent.WI_AFTER); } }
@Override public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return workers.get().getMessageBodyWriter(type, genericType, annotations, mediaType); }
@Override public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return workers.get().getMessageBodyWriter(type, genericType, annotations, mediaType); }
@Override public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return workers.get().getMessageBodyWriter(type, genericType, annotations, mediaType); }
@Override public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return workers.get().getMessageBodyWriter(type, genericType, annotations, mediaType); }
@Override public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) { return workers.get().getMessageBodyWriter(type, genericType, annotations, mediaType); }
@SuppressWarnings("unchecked") @Override public void writeTo(Object entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { final Type actualTypeArgument = actual(genericType); final MessageBodyWriter writer = workers.get().getMessageBodyWriter(entity.getClass(), actualTypeArgument, annotations, mediaType); writer.writeTo(entity, entity.getClass(), actualTypeArgument, annotations, mediaType, httpHeaders, entityStream); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public void writeTo(com.google.common.base.Optional<?> entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (!entity.isPresent()) { throw new NoContentException("Absent value for type: " + genericType); } Type innerGenericType = (genericType instanceof ParameterizedType) ? ((ParameterizedType) genericType).getActualTypeArguments()[0] : entity.get().getClass(); MessageBodyWriter writer = mbw.get().getMessageBodyWriter(entity.get().getClass(), innerGenericType, annotations, mediaType); writer.writeTo(entity.get(), entity.get().getClass(), innerGenericType, annotations, mediaType, httpHeaders, entityStream); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public void writeTo(Optional<?> entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (!entity.isPresent()) { throw new NoContentException("Absent value for type: " + genericType); } Type innerGenericType = (genericType instanceof ParameterizedType) ? ((ParameterizedType) genericType).getActualTypeArguments()[0] : entity.get().getClass(); MessageBodyWriter writer = mbw.get().getMessageBodyWriter(entity.get().getClass(), innerGenericType, annotations, mediaType); writer.writeTo(entity.get(), entity.get().getClass(), innerGenericType, annotations, mediaType, httpHeaders, entityStream); } }
@SuppressWarnings({"rawtypes", "unchecked"}) @Override public void writeTo(Optional<?> entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { if (!entity.isPresent()) { throw new NoContentException("Absent value for type: " + genericType); } Type innerGenericType = (genericType instanceof ParameterizedType) ? ((ParameterizedType) genericType).getActualTypeArguments()[0] : entity.get().getClass(); MessageBodyWriter writer = mbw.get().getMessageBodyWriter(entity.get().getClass(), innerGenericType, annotations, mediaType); writer.writeTo(entity.get(), entity.get().getClass(), innerGenericType, annotations, mediaType, httpHeaders, entityStream); } }
@Override public void writeTo(T entity, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> responseHeaders, OutputStream entityStream) throws IOException, WebApplicationException { final MessageBodyWriter<U> writer = requireNonNull(mbw).get().getMessageBodyWriter(representation, representation, annotations, contentType); // Fix the headers, because Dropwizard error mappers always set the content type to APPLICATION_JSON responseHeaders.putSingle(HttpHeaders.CONTENT_TYPE, contentType); writer.writeTo(getRepresentation(entity), representation, representation, annotations, contentType, responseHeaders, entityStream); }