Search in sources :

Example 1 with ParseException

use of org.openecard.apache.http.ParseException in project open-ecard by ecsec.

the class HttpAppPluginActionHandler method getRequestBody.

private RequestBody getRequestBody(HttpRequest httpRequest, String resourceName) throws IOException {
    try {
        HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) httpRequest;
        HttpEntity entity = entityRequest.getEntity();
        InputStream is = entity.getContent();
        // TODO: This assumes the content is UTF-8. Evaluate what is actually sent.
        String value = FileUtils.toString(is);
        String mimeType = ContentType.get(entity).getMimeType();
        // TODO: find out if we have a Base64 coded value
        boolean base64Content = false;
        RequestBody body = new RequestBody(resourceName, null);
        body.setValue(value, mimeType, base64Content);
        return body;
    } catch (UnsupportedCharsetException | ParseException e) {
        LOG.error("Failed to create request body.", e);
    }
    return null;
}
Also used : HttpEntity(org.openecard.apache.http.HttpEntity) InputStream(java.io.InputStream) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) HttpEntityEnclosingRequest(org.openecard.apache.http.HttpEntityEnclosingRequest) ParseException(org.openecard.apache.http.ParseException) RequestBody(org.openecard.addon.bind.RequestBody)

Aggregations

InputStream (java.io.InputStream)1 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)1 RequestBody (org.openecard.addon.bind.RequestBody)1 HttpEntity (org.openecard.apache.http.HttpEntity)1 HttpEntityEnclosingRequest (org.openecard.apache.http.HttpEntityEnclosingRequest)1 ParseException (org.openecard.apache.http.ParseException)1