Object entity = request.getEntity();
if (entity == null) {
return;
}
ProvidersRegistry providersRegistry = request.getAttribute(ProvidersRegistry.class);
ClientRuntimeContext runtimeContext = new ClientRuntimeContext(providersRegistry);
RuntimeContext saved = RuntimeContextTLS.getRuntimeContext();
RuntimeContextTLS.setRuntimeContext(runtimeContext);
try {
Class<?> type = entity.getClass();
Type genericType = type;
if (entity instanceof GenericEntity) {
GenericEntity<?> genericEntity = (GenericEntity<?>)entity;
type = genericEntity.getRawType();
genericType = genericEntity.getType();
entity = genericEntity.getEntity();
}
String contentType = request.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE);
MediaType contentMediaType = MediaType.valueOf(contentType);
MessageBodyWriter writer =
providersRegistry.getMessageBodyWriter(type,
genericType,
null,
contentMediaType,
runtimeContext);
if (writer == null) {