use of org.apache.olingo.client.core.serialization.JsonDeserializer in project teiid by teiid.
the class ODataProcedureExecution method handleResponse.
private void handleResponse(final Procedure procedure, final String baseUri, final InputStream payload) throws TranslatorException, ODataDeserializerException {
if (procedure.getResultSet() != null) {
ODataType type = ODataType.valueOf(procedure.getResultSet().getProperty(ODataMetadataProcessor.ODATA_TYPE, false));
this.response = new ODataResponse(payload, type, new DocumentNode()) {
@Override
public InputStream nextBatch(java.net.URI uri) throws TranslatorException {
return executeSkipToken(uri, baseUri, new HttpStatusCode[] { HttpStatusCode.OK });
}
};
} else if (getReturnParameter() != null) {
// this is scalar result
JsonDeserializer parser = new JsonDeserializer(false);
Property property = parser.toProperty(payload).getPayload();
if (property.isCollection()) {
this.returnValue = property.asCollection();
} else {
this.returnValue = property.asPrimitive();
}
}
}
use of org.apache.olingo.client.core.serialization.JsonDeserializer in project teiid by teiid.
the class ODataResponse method parsePayload.
private Iterator<ODataDocument> parsePayload(InputStream payload) throws TranslatorException {
try {
JsonDeserializer parser = new JsonDeserializer(false);
if (this.resultsType == ODataType.ENTITY) {
Entity entity = parser.toEntity(payload).getPayload();
ODataDocument document = ODataDocument.createDocument(entity);
return Arrays.asList(document).iterator();
} else if (this.resultsType == ODataType.ENTITY_COLLECTION) {
EntityCollection entityCollection = parser.toEntitySet(payload).getPayload();
this.nextUri = entityCollection.getNext();
ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
for (Entity entity : entityCollection.getEntities()) {
documents.add(ODataDocument.createDocument(entity));
}
return documents.iterator();
} else {
// complex
Property property = parser.toProperty(payload).getPayload();
if (property.isCollection()) {
ArrayList<ODataDocument> documents = new ArrayList<ODataDocument>();
for (Object obj : property.asCollection()) {
ComplexValue complexValue = (ComplexValue) obj;
documents.add(ODataDocument.createDocument(complexValue));
}
return documents.iterator();
} else {
ODataDocument document = ODataDocument.createDocument(property.asComplex());
return Arrays.asList(document).iterator();
}
}
} catch (ODataDeserializerException e) {
throw new TranslatorException(e);
}
}
use of org.apache.olingo.client.core.serialization.JsonDeserializer 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);
}
}
use of org.apache.olingo.client.core.serialization.JsonDeserializer in project teiid by teiid.
the class ODataUpdateExecution method handleInsert.
private void handleInsert(ODataUpdateQuery odataQuery) throws TranslatorException {
try {
Map<String, List<String>> headers = getDefaultUpdateHeaders();
// $NON-NLS-1$
headers.put("Prefer", Arrays.asList("return=representation"));
String uri = odataQuery.buildInsertURL("");
InputStream response = null;
BinaryWSProcedureExecution execution = invokeHTTP(odataQuery.getInsertMethod(), uri, odataQuery.getPayload(null), headers);
// 201 - the created entity returned
if (HttpStatusCode.CREATED.getStatusCode() == execution.getResponseCode()) {
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
response = blob.getBinaryStream();
} else if (HttpStatusCode.NO_CONTENT.getStatusCode() == execution.getResponseCode()) {
// get Location header and get content
String entityUri = (String) execution.getResponseHeader("Location");
if (entityUri != null) {
// in the cases of property update there will be no Location header
response = executeQuery("GET", entityUri, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
}
} else {
throw buildError(execution);
}
if (response != null) {
JsonDeserializer serializer = new JsonDeserializer(false);
this.createdEntity = serializer.toEntity(response).getPayload();
}
} catch (ODataDeserializerException e) {
throw new TranslatorException(e);
} catch (SQLException e) {
throw new TranslatorException(e);
}
}
Aggregations