Search in sources :

Example 1 with ODataError

use of org.apache.olingo.commons.api.ex.ODataError in project teiid by teiid.

the class BaseQueryExecution method buildError.

protected TranslatorException buildError(BinaryWSProcedureExecution execution) {
    // do some error handling
    try {
        Blob blob = (Blob) execution.getOutputParameterValues().get(0);
        if (blob != null) {
            boolean json = false;
            // $NON-NLS-1$
            String contentTypeString = getHeader(execution, "Content-Type");
            if (contentTypeString != null) {
                ContentType contentType = ContentType.parse(contentTypeString);
                if (contentType != null && ContentType.APPLICATION_JSON.isCompatible(contentType)) {
                    json = true;
                }
            }
            ODataDeserializer parser = null;
            if (json) {
                parser = new JsonDeserializer(false);
            } else {
                // TODO: it may not be atom, it could just be xml/html
                parser = new AtomDeserializer();
            }
            ODataError error = parser.toError(blob.getBinaryStream());
            return new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17013, execution.getResponseCode(), error.getCode(), error.getMessage(), error.getInnerError()));
        }
        return new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17031, execution.getResponseCode()));
    } catch (Throwable t) {
        return new TranslatorException(t);
    }
}
Also used : Blob(java.sql.Blob) ContentType(org.apache.olingo.commons.api.format.ContentType) ODataDeserializer(org.apache.olingo.client.api.serialization.ODataDeserializer) TranslatorException(org.teiid.translator.TranslatorException) AtomDeserializer(org.apache.olingo.client.core.serialization.AtomDeserializer) ODataError(org.apache.olingo.commons.api.ex.ODataError) JsonDeserializer(org.apache.olingo.client.core.serialization.JsonDeserializer)

Aggregations

Blob (java.sql.Blob)1 ODataDeserializer (org.apache.olingo.client.api.serialization.ODataDeserializer)1 AtomDeserializer (org.apache.olingo.client.core.serialization.AtomDeserializer)1 JsonDeserializer (org.apache.olingo.client.core.serialization.JsonDeserializer)1 ODataError (org.apache.olingo.commons.api.ex.ODataError)1 ContentType (org.apache.olingo.commons.api.format.ContentType)1 TranslatorException (org.teiid.translator.TranslatorException)1