@Override
public Status sendRequest(Request request) {
Status result = null;
try {
final Representation entity = request.getEntity();
// Set the request headers
for (final Parameter header : getRequestHeaders()) {
if ("Content-Length".equalsIgnoreCase(header.getName())) {
// HC4 is picky about duplicate content-length header
continue;
}
getHttpMethod().setHeader(header.getName(),
header.getValue());
}
// For those method that accept enclosing entities, provide it if there is any
if ((entity != null)
&& (getHttpMethod() instanceof HttpEntityEnclosingRequestBase)) {
final HttpEntityEnclosingRequestBase eem = (HttpEntityEnclosingRequestBase) getHttpMethod();
eem.setEntity(new HttpEntity()
{
@Override
public void writeTo(final OutputStream outstream)
throws IOException
{
entity.write(outstream);
}
@Override
public boolean isStreaming() {
return entity.isTransient();
}
@Override
public boolean isRepeatable() {
return !entity.isTransient();
}
@Override
public boolean isChunked() {
return false;
}
@Override
public Header getContentType() {
final String contentType = (entity.getMediaType() != null) ? entity
.getMediaType().toString() : null;
if (contentType != null) {
return new BasicHeader("Content-Type", contentType);
}
else {
return null;
}
}
@Override
public long getContentLength() {
return entity.getSize();
}
@Override
public Header getContentEncoding() {
return null;
}
@Override
public InputStream getContent()
throws IOException, IllegalStateException
{
return entity.getStream();
}
@Override
@Deprecated
public void consumeContent()