logger.trace("Could not find a writer for {} and {}. Try to find JAF DataSourceProvider", //$NON-NLS-1$
entity.getClass().getName(),
responseMediaType);
}
DataContentHandler dataContentHandler = null;
// Write Entity with ASF DataContentHandler
// try to find a data handler using JavaBeans Activation Framework, if
// found use DataSourceProvider
dataContentHandler = CommandMap
.getDefaultCommandMap()
.createDataContentHandler(responseMediaType.getType() + "/" + responseMediaType.getSubtype()); //$NON-NLS-1$
if (dataContentHandler == null) {
if (logger.isErrorEnabled()) {
logger.error(Messages.getMessage("noWriterOrDataSourceProvider", entity.getClass() //$NON-NLS-1$
.getName(), responseMediaType));
}
// WINK-379 - From the spec :
// If no methods support one of the acceptable response entity body media types
// an implementation MUST generate a WebApplicationException with a not acceptable
// response (HTTP 406 status) and no entity
throw new WebApplicationException(HttpStatus.NOT_ACCEPTABLE.getCode());
}
if (logger.isTraceEnabled()) {
logger
.trace("Serialization using data content handler {}", dataContentHandler.getClass() //$NON-NLS-1$
.getName());
}
FlushHeadersOutputStream outputStream = new FlushHeadersOutputStream(httpResponse, httpHeaders, responseMediaType);
if (logger.isTraceEnabled()) {
logger.trace("{}@{}.writeTo({}, {}, {}) being called", new Object[] { //$NON-NLS-1$
dataContentHandler.getClass().getName(),
Integer.toHexString(System.identityHashCode(dataContentHandler)),
entity, responseMediaType.toString(), outputStream});
}
dataContentHandler
.writeTo(entity,
responseMediaType.getType() + "/" + responseMediaType.getSubtype(), outputStream); //$NON-NLS-1$
logger.trace("Flushing headers if not written"); //$NON-NLS-1$
outputStream.flushHeaders();
}