Search in sources :

Example 1 with BindingResultCode

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

the class HttpAppPluginActionHandler method createHTTPResponseFromBindingResult.

private HttpResponse createHTTPResponseFromBindingResult(BindingResult bindingResult) {
    BindingResultCode resultCode = bindingResult.getResultCode();
    LOG.debug("Recieved BindingResult with ResultCode {}", resultCode);
    HttpResponse response;
    switch(resultCode) {
        case OK:
            response = new Http11Response(HttpStatus.SC_OK);
            break;
        case REDIRECT:
            response = new Http11Response(HttpStatus.SC_SEE_OTHER);
            String location = bindingResult.getAuxResultData().get(AuxDataKeys.REDIRECT_LOCATION);
            if (location != null && !location.isEmpty()) {
                response.addHeader(HeaderTypes.LOCATION.fieldName(), location);
            } else {
                // redirect requires a location field
                LOG.error("No redirect address available in given BindingResult instance.");
                response = new Http11Response(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            }
            break;
        case WRONG_PARAMETER:
        case MISSING_PARAMETER:
            response = new Http11Response(HttpStatus.SC_BAD_REQUEST);
            break;
        case INTERNAL_ERROR:
            response = new Http11Response(HttpStatus.SC_INTERNAL_SERVER_ERROR);
            break;
        case RESOURCE_UNAVAILABLE:
        case DEPENDING_HOST_UNREACHABLE:
            response = new Http11Response(HttpStatus.SC_NOT_FOUND);
            break;
        case RESOURCE_LOCKED:
            response = new Http11Response(HttpStatus.SC_LOCKED);
            break;
        case TIMEOUT:
            response = new Http11Response(HttpStatus.SC_GATEWAY_TIMEOUT);
            break;
        case TOO_MANY_REQUESTS:
            // Code for TOO MANY REQUESTS is 429 according to RFC 6585
            response = new Http11Response(429);
            break;
        default:
            LOG.error("Untreated result code: " + resultCode);
            response = new Http11Response(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    addHTTPEntity(response, bindingResult);
    return response;
}
Also used : HttpResponse(org.openecard.apache.http.HttpResponse) BindingResultCode(org.openecard.addon.bind.BindingResultCode) Http11Response(org.openecard.control.binding.http.common.Http11Response)

Aggregations

BindingResultCode (org.openecard.addon.bind.BindingResultCode)1 HttpResponse (org.openecard.apache.http.HttpResponse)1 Http11Response (org.openecard.control.binding.http.common.Http11Response)1