* The high-level request.
* @return The result status.
*/
@Override
public Status sendRequest(Request request) {
Status result = null;
try {
final Representation entity = request.getEntity();
// Set the request headers
for (Parameter header : getRequestHeaders()) {
if (!header.getName().equals(
HeaderConstants.HEADER_CONTENT_LENGTH)) {
getHttpRequest().addHeader(header.getName(),
header.getValue());
}
}
// For those method that accept enclosing entities, provide it
if ((entity != null)
&& (getHttpRequest() instanceof HttpEntityEnclosingRequestBase)) {
final HttpEntityEnclosingRequestBase eem = (HttpEntityEnclosingRequestBase) getHttpRequest();
eem.setEntity(new AbstractHttpEntity() {
public InputStream getContent() throws IOException,
IllegalStateException {
return entity.getStream();
}
public long getContentLength() {
return entity.getSize();
}
public Header getContentType() {
return new BasicHeader(
HeaderConstants.HEADER_CONTENT_TYPE, (entity
.getMediaType() != null) ? entity
.getMediaType().toString() : null);
}
public boolean isRepeatable() {
return !entity.isTransient();
}
public boolean isStreaming() {
return (entity.getSize() == Representation.UNKNOWN_SIZE);
}
public void writeTo(OutputStream os) throws IOException {
entity.write(os);
}
});
}
// Ensure that the connection is active
this.httpResponse = this.clientHelper.getHttpClient().execute(
getHttpRequest());
// 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) {
this.clientHelper
.getLogger()
.log(Level.WARNING,
"An error occurred during the communication with the remote HTTP server.",
ioe);
result = new Status(Status.CONNECTOR_ERROR_COMMUNICATION, ioe);
// Release the connection
getHttpRequest().abort();
}