use of org.apache.olingo.commons.api.http.HttpStatusCode in project wildfly-camel by wildfly-extras.
the class Olingo4IntegrationTest method testCreateUpdateDelete.
@Test
public void testCreateUpdateDelete() throws Exception {
CamelContext camelctx = createCamelContext();
camelctx.addRoutes(new RouteBuilder() {
public void configure() {
from("direct://create-entity").to("olingo4://create/People");
from("direct://update-entity").to("olingo4://update/People('lewisblack')");
from("direct://delete-entity").to("olingo4://delete/People('lewisblack')");
from("direct://read-deleted-entity").to("olingo4://delete/People('lewisblack')");
from("direct://batch").to("olingo4://batch");
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
final ClientEntity clientEntity = createEntity();
ClientEntity entity = template.requestBody("direct://create-entity", clientEntity, ClientEntity.class);
Assert.assertNotNull(entity);
Assert.assertEquals("Lewis", entity.getProperty("FirstName").getValue().toString());
Assert.assertEquals("", entity.getProperty("MiddleName").getValue().toString());
// update
clientEntity.getProperties().add(objFactory.newPrimitiveProperty("MiddleName", objFactory.newPrimitiveValueBuilder().buildString("Lewis")));
HttpStatusCode status = template.requestBody("direct://update-entity", clientEntity, HttpStatusCode.class);
Assert.assertNotNull("Update status", status);
Assert.assertEquals("Update status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
LOG.info("Update entity status: {}", status);
// delete
status = template.requestBody("direct://delete-entity", null, HttpStatusCode.class);
Assert.assertNotNull("Delete status", status);
Assert.assertEquals("Delete status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode());
LOG.info("Delete status: {}", status);
// check for delete
try {
template.requestBody("direct://read-deleted-entity", null, HttpStatusCode.class);
} catch (CamelExecutionException e) {
Assert.assertEquals("Resource Not Found [HTTP/1.1 404 Not Found]", e.getCause().getMessage());
}
} finally {
camelctx.stop();
}
}
use of org.apache.olingo.commons.api.http.HttpStatusCode in project teiid by teiid.
the class BaseQueryExecution method executeQuery.
protected InputStream executeQuery(String method, String uri, String payload, String eTag, HttpStatusCode[] expectedStatus) throws TranslatorException {
Map<String, List<String>> headers = getDefaultHeaders();
if (eTag != null) {
// $NON-NLS-1$
headers.put("If-Match", Arrays.asList(eTag));
}
if (payload != null) {
headers.put("Content-Type", // $NON-NLS-1$
Arrays.asList(ContentType.APPLICATION_JSON.toContentTypeString()));
}
BinaryWSProcedureExecution execution;
try {
execution = invokeHTTP(method, uri, payload, headers);
for (HttpStatusCode status : expectedStatus) {
if (status.getStatusCode() == execution.getResponseCode()) {
if (execution.getResponseCode() != HttpStatusCode.NO_CONTENT.getStatusCode() && execution.getResponseCode() != HttpStatusCode.NOT_FOUND.getStatusCode()) {
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
return blob.getBinaryStream();
}
// this is success with no-data
return null;
}
}
} catch (SQLException e) {
throw new TranslatorException(e);
}
// throw an error
throw buildError(execution);
}
use of org.apache.olingo.commons.api.http.HttpStatusCode 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.commons.api.http.HttpStatusCode 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.commons.api.http.HttpStatusCode in project teiid by teiid.
the class ODataQueryExecution method execute.
@Override
public void execute() throws TranslatorException {
final String URI = this.visitor.buildURL("");
if (isCount) {
Map<String, List<String>> headers = new TreeMap<String, List<String>>();
// $NON-NLS-1$ //$NON-NLS-2$
headers.put("Accept", Arrays.asList("text/plain"));
// $NON-NLS-1$
BinaryWSProcedureExecution execution = invokeHTTP("GET", URI, null, headers);
if (execution.getResponseCode() != HttpStatusCode.OK.getStatusCode()) {
throw buildError(execution);
}
Blob blob = (Blob) execution.getOutputParameterValues().get(0);
try {
this.countResponse = Integer.parseInt(ObjectConverterUtil.convertToString(blob.getBinaryStream()));
} catch (IOException e) {
throw new TranslatorException(e);
} catch (SQLException e) {
throw new TranslatorException(e);
}
} else {
InputStream payload = executeQuery(// //$NON-NLS-1$
"GET", // //$NON-NLS-1$
URI, // //$NON-NLS-1$
null, // //$NON-NLS-1$
null, new HttpStatusCode[] { HttpStatusCode.OK, HttpStatusCode.NO_CONTENT, HttpStatusCode.NOT_FOUND });
this.response = new ODataResponse(payload, ODataType.ENTITY_COLLECTION, this.visitor.getODataQuery().getRootDocument()) {
@Override
public InputStream nextBatch(java.net.URI uri) throws TranslatorException {
return executeSkipToken(uri, URI.toString(), new HttpStatusCode[] { HttpStatusCode.OK, HttpStatusCode.NO_CONTENT, HttpStatusCode.NOT_FOUND });
}
};
}
}
Aggregations