Search in sources :

Example 1 with BasicHttpEntity

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;
}
Also used : Header(org.openecard.apache.http.Header) BasicHeader(org.openecard.apache.http.message.BasicHeader) ContentLengthInputStream(org.openecard.apache.http.impl.io.ContentLengthInputStream) IdentityInputStream(org.openecard.apache.http.impl.io.IdentityInputStream) ChunkedInputStream(org.openecard.apache.http.impl.io.ChunkedInputStream) InputStream(java.io.InputStream) BasicHttpEntity(org.openecard.apache.http.entity.BasicHttpEntity)

Example 2 with BasicHttpEntity

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);
}
Also used : BasicHttpEntity(org.openecard.apache.http.entity.BasicHttpEntity) MimeType(org.openecard.control.binding.http.common.MimeType)

Aggregations

BasicHttpEntity (org.openecard.apache.http.entity.BasicHttpEntity)2 InputStream (java.io.InputStream)1 Header (org.openecard.apache.http.Header)1 ChunkedInputStream (org.openecard.apache.http.impl.io.ChunkedInputStream)1 ContentLengthInputStream (org.openecard.apache.http.impl.io.ContentLengthInputStream)1 IdentityInputStream (org.openecard.apache.http.impl.io.IdentityInputStream)1 BasicHeader (org.openecard.apache.http.message.BasicHeader)1 MimeType (org.openecard.control.binding.http.common.MimeType)1