use of org.openecard.apache.http.entity.BasicHttpEntity in project open-ecard by ecsec.
the class StreamHttpClientConnection method prepareInput.
protected HttpEntity prepareInput(final HttpMessage message) throws HttpException {
final BasicHttpEntity entity = new BasicHttpEntity();
final long len = this.incomingContentStrategy.determineLength(message);
final InputStream instream = createInputStream(len);
if (len == ContentLengthStrategy.CHUNKED) {
entity.setChunked(true);
entity.setContentLength(-1);
entity.setContent(instream);
} else if (len == ContentLengthStrategy.IDENTITY) {
entity.setChunked(false);
entity.setContentLength(-1);
entity.setContent(instream);
} else {
entity.setChunked(false);
entity.setContentLength(len);
entity.setContent(instream);
}
final Header contentTypeHeader = message.getFirstHeader(HTTP.CONTENT_TYPE);
if (contentTypeHeader != null) {
entity.setContentType(contentTypeHeader);
}
final Header contentEncodingHeader = message.getFirstHeader(HTTP.CONTENT_ENCODING);
if (contentEncodingHeader != null) {
entity.setContentEncoding(contentEncodingHeader);
}
return entity;
}
use of org.openecard.apache.http.entity.BasicHttpEntity in project open-ecard by ecsec.
the class FileHandler method handleFile.
private void handleFile(Http11Response httpResponse, URL file) throws Exception {
String fileName = file.toString();
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
MimeType mimeType = MimeType.fromFilenameExtension(fileExtension);
String typeName = (mimeType != null) ? mimeType.getMimeType() : MimeType.TEXT_PLAIN.getMimeType();
httpResponse.setStatusCode(HttpStatus.SC_OK);
BasicHttpEntity entity = new BasicHttpEntity();
entity.setContent(file.openStream());
entity.setContentType(ContentType.create(typeName, "UTF-8").toString());
httpResponse.setEntity(entity);
}
Aggregations