final Representation entity = request.isEntityAvailable() ? request
.getEntity() : null;
try {
if (entity != null) {
// Get the connector service to callback
final ConnectorService connectorService = getConnectorService(request);
if (connectorService != null) {
connectorService.beforeSend(entity);
}
// In order to workaround bug #6472250
// (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6472250),
// it is very important to reuse that exact same "rs" reference
// when manipulating the request stream, otherwise "insufficient
// data sent" exceptions will occur in "fixedLengthMode"
final OutputStream rs = getRequestEntityStream();
final WritableByteChannel wbc = getRequestEntityChannel();
if (wbc != null) {
entity.write(wbc);
} else if (rs != null) {
entity.write(rs);
rs.flush();
}
// Call-back after writing
if (connectorService != null) {
connectorService.afterSend(entity);
}
if (rs != null) {
rs.close();
} else if (wbc != null) {