use of org.apache.olingo.client.api.serialization.ODataDeserializerException in project teiid by teiid.
the class ODataProcedureExecution method execute.
@Override
public void execute() throws TranslatorException {
try {
String parameters = getQueryParameters(this.command);
InputStream response = null;
Procedure procedure = this.command.getMetadataObject();
if (isFunction(procedure)) {
String URI = buildFunctionURL(this.command, parameters);
response = executeQuery("GET", URI, null, null, new HttpStatusCode[] { HttpStatusCode.OK });
handleResponse(procedure, URI, response);
} else {
String URI = this.command.getProcedureName();
response = executeQuery("POST", URI, parameters, null, new HttpStatusCode[] { HttpStatusCode.OK });
handleResponse(procedure, URI, response);
}
} catch (ODataDeserializerException e) {
throw new TranslatorException(e);
} catch (EdmPrimitiveTypeException e) {
throw new TranslatorException(e);
}
}
use of org.apache.olingo.client.api.serialization.ODataDeserializerException 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.api.serialization.ODataDeserializerException 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