use of org.apache.olingo.commons.api.format.ContentType in project teiid by teiid.
the class ODataFilter method writeError.
static void writeError(ServletRequest request, TeiidProcessingException e, HttpServletResponse httpResponse, int statusCode) throws IOException {
httpResponse.setStatus(statusCode);
ContentType contentType = ContentType.parse(request.getContentType());
PrintWriter writer = httpResponse.getWriter();
// $NON-NLS-1$
String code = e.getCode() == null ? "" : e.getCode();
// $NON-NLS-1$
String message = e.getMessage() == null ? "" : e.getMessage();
if (contentType == null || contentType.isCompatible(ContentType.APPLICATION_JSON)) {
httpResponse.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_JSON.toContentTypeString());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
writer.write("{ \"error\": { \"code\": \"" + StringEscapeUtils.escapeJson(code) + "\", \"message\": \"" + StringEscapeUtils.escapeJson(message) + "\" } }");
} else {
httpResponse.setHeader(HttpHeader.CONTENT_TYPE, ContentType.APPLICATION_XML.toContentTypeString());
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
writer.write("<m:error xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"><m:code>" + StringEscapeUtils.escapeXml10(code) + "</m:code><m:message>" + StringEscapeUtils.escapeXml10(message) + "</m:message></m:error>");
}
writer.close();
}
use of org.apache.olingo.commons.api.format.ContentType 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);
}
}
Aggregations