* The high-level request.
* @return the status of the communication
*/
public Status sendRequest(Request request) {
Status result = null;
Representation entity = request.isEntityAvailable() ? request
.getEntity() : null;
// Get the connector service to callback
org.restlet.service.ConnectorService connectorService = ConnectorHelper
.getConnectorService();
if (connectorService != null) {
connectorService.beforeSend(entity);
}
try {
if (entity != null) {
// 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 "requestStream"
// reference when manipulating the request stream, otherwise
// "insufficient data sent" exceptions will occur in
// "fixedLengthMode"
OutputStream requestStream = getRequestEntityStream();
java.nio.channels.WritableByteChannel requestChannel = getRequestEntityChannel();
if (requestChannel != null) {
entity.write(requestChannel);
requestChannel.close();
} else if (requestStream != null) {
entity.write(requestStream);
requestStream.flush();
requestStream.close();
}
}
// Now we can access the status code, this MUST happen after closing
// any open request stream.
result = new Status(getStatusCode(), null, getReasonPhrase(), null);
} catch (IOException ioe) {
getHelper()
.getLogger()
.log(Level.FINE,
"An error occured during the communication with the remote HTTP server.",
ioe);
result = new Status(Status.CONNECTOR_ERROR_COMMUNICATION, ioe);
} finally {
if (entity != null) {
entity.release();
}
// Call-back after writing
if (connectorService != null) {
connectorService.afterSend(entity);