Search in sources :

Example 1 with ResponseBody

use of org.openecard.addon.bind.ResponseBody in project open-ecard by ecsec.

the class HttpAppPluginActionHandler method addHTTPEntity.

private void addHTTPEntity(HttpResponse response, BindingResult bindingResult) {
    ResponseBody responseBody = bindingResult.getBody();
    if (responseBody != null && responseBody.hasValue()) {
        LOG.debug("BindingResult contains a body.");
        // determine content type
        ContentType ct = ContentType.create(responseBody.getMimeType(), Charset.forName("UTF-8"));
        StringEntity entity = new StringEntity(responseBody.getValue(), ct);
        response.setEntity(entity);
        // evaluate Base64 flag
        if (responseBody.isBase64()) {
            response.setHeader("Content-Transfer-Encoding", "Base64");
        }
    } else {
        LOG.debug("BindingResult contains no body.");
        if (bindingResult.getResultMessage() != null) {
            ContentType ct = ContentType.create("text/plain", Charset.forName("UTF-8"));
            StringEntity entity = new StringEntity(bindingResult.getResultMessage(), ct);
            response.setEntity(entity);
        }
    }
}
Also used : StringEntity(org.openecard.apache.http.entity.StringEntity) ContentType(org.openecard.apache.http.entity.ContentType) ResponseBody(org.openecard.addon.bind.ResponseBody)

Aggregations

ResponseBody (org.openecard.addon.bind.ResponseBody)1 ContentType (org.openecard.apache.http.entity.ContentType)1 StringEntity (org.openecard.apache.http.entity.StringEntity)1