Search in sources :

Example 1 with ODataErrorContext

use of org.apache.olingo.odata2.api.processor.ODataErrorContext in project camel by apache.

the class AbstractFutureCallback method checkStatus.

public static HttpStatusCodes checkStatus(HttpResponse response) throws ODataApplicationException {
    final StatusLine statusLine = response.getStatusLine();
    HttpStatusCodes httpStatusCode = HttpStatusCodes.fromStatusCode(statusLine.getStatusCode());
    if (400 <= httpStatusCode.getStatusCode() && httpStatusCode.getStatusCode() <= 599) {
        if (response.getEntity() != null) {
            try {
                final ContentType responseContentType = ContentType.parse(response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
                final String mimeType = responseContentType.getMimeType();
                if (ODATA_MIME_TYPE.matcher(mimeType).matches()) {
                    final ODataErrorContext errorContext = EntityProvider.readErrorDocument(response.getEntity().getContent(), responseContentType.toString());
                    throw new ODataApplicationException(errorContext.getMessage(), errorContext.getLocale(), httpStatusCode, errorContext.getErrorCode(), errorContext.getException());
                }
            } catch (EntityProviderException e) {
                throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e);
            } catch (IOException e) {
                throw new ODataApplicationException(e.getMessage(), response.getLocale(), httpStatusCode, e);
            }
        }
        throw new ODataApplicationException(statusLine.getReasonPhrase(), response.getLocale(), httpStatusCode);
    }
    return httpStatusCode;
}
Also used : StatusLine(org.apache.http.StatusLine) ODataErrorContext(org.apache.olingo.odata2.api.processor.ODataErrorContext) EntityProviderException(org.apache.olingo.odata2.api.ep.EntityProviderException) ContentType(org.apache.http.entity.ContentType) HttpStatusCodes(org.apache.olingo.odata2.api.commons.HttpStatusCodes) IOException(java.io.IOException) ODataApplicationException(org.apache.olingo.odata2.api.exception.ODataApplicationException)

Aggregations

IOException (java.io.IOException)1 StatusLine (org.apache.http.StatusLine)1 ContentType (org.apache.http.entity.ContentType)1 HttpStatusCodes (org.apache.olingo.odata2.api.commons.HttpStatusCodes)1 EntityProviderException (org.apache.olingo.odata2.api.ep.EntityProviderException)1 ODataApplicationException (org.apache.olingo.odata2.api.exception.ODataApplicationException)1 ODataErrorContext (org.apache.olingo.odata2.api.processor.ODataErrorContext)1