.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));
}
throw new WebApplicationException(500);
}
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();
}