if (genericType instanceof TypeVariable) {
genericType = InjectionUtils.getSuperType(ori.getClassResourceInfo().getServiceClass(),
(TypeVariable)genericType);
}
MessageBodyWriter writer = null;
MediaType responseType = null;
for (MediaType type : availableContentTypes) {
writer = ProviderFactory.getInstance(message)
.createMessageBodyWriter(targetType, genericType,
invoked != null ? invoked.getAnnotations() : new Annotation[]{},
type,
message);
if (writer != null) {
responseType = type;
break;
}
}
OutputStream outOriginal = message.getContent(OutputStream.class);
if (writer == null) {
message.put(Message.CONTENT_TYPE, "text/plain");
message.put(Message.RESPONSE_CODE, 500);
writeResponseErrorMessage(outOriginal, "NO_MSG_WRITER", targetType.getSimpleName());
return;
}
boolean enabled = checkBufferingMode(message, writer, firstTry);
Object entity = getEntity(responseObj);
try {
responseType = checkFinalContentType(responseType);
LOG.fine("Response content type is: " + responseType.toString());
message.put(Message.CONTENT_TYPE, responseType.toString());
Annotation[] annotations = invoked != null ? invoked.getAnnotations() : new Annotation[]{};
long size = writer.getSize(entity, targetType, genericType, annotations, responseType);
if (size > 0) {
LOG.fine("Setting ContentLength to " + size + " as requested by "
+ writer.getClass().getName());
responseHeaders.putSingle(HttpHeaders.CONTENT_LENGTH, Long.toString(size));
}
LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
try {
writer.writeTo(entity, targetType, genericType,
annotations,
responseType,
responseHeaders,
message.getContent(OutputStream.class));