use of org.apache.olingo.client.api.serialization.ODataSerializer in project tdi-studio-se by Talend.
the class DynamicsCRMClient method convertToHttpEntity.
/**
* Convert OData entity to HttpEntity type
*
* @param entity OData entity.
*
* @return An entity that can be sent or received with an HTTP message.
* @throws
*/
protected HttpEntity convertToHttpEntity(ClientEntity entity) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
OutputStreamWriter writer = null;
try {
writer = new OutputStreamWriter(output, Constants.UTF8);
final ODataSerializer serializer = odataClient.getSerializer(org.apache.olingo.commons.api.format.ContentType.JSON);
serializer.write(writer, odataClient.getBinder().getEntity(entity));
HttpEntity httpEntity = new ByteArrayEntity(output.toByteArray(), org.apache.http.entity.ContentType.APPLICATION_JSON);
return httpEntity;
} catch (Exception e) {
throw new HttpClientException(e);
} finally {
IOUtils.closeQuietly(writer);
}
}
use of org.apache.olingo.client.api.serialization.ODataSerializer in project syndesis by syndesisio.
the class AbstractODataConnector method createEndpointUri.
@Override
public String createEndpointUri(final String scheme, final Map<String, String> options) throws URISyntaxException {
// set serviceUri on delegate component
Olingo4Component delegate = getCamelContext().getComponent(scheme, Olingo4Component.class);
Olingo4Configuration configuration = new Olingo4Configuration();
configuration.setServiceUri(this.serviceUri);
delegate.setConfiguration(configuration);
setAfterProducer(exchange -> {
if (!exchange.isFailed()) {
ClientEntity clientEntity = exchange.getIn().getBody(ClientEntity.class);
if (clientEntity != null) {
// convert client entity to JSON
final StringWriter writer = new StringWriter();
final Entity entity = odataClient.getBinder().getEntity(clientEntity);
final ODataSerializer serializer = odataClient.getSerializer(APPLICATION_JSON);
serializer.write(writer, entity);
exchange.getIn().setBody(writer.toString());
}
}
// TODO handle failure on missing resource 404
});
return super.createEndpointUri(scheme, options);
}
Aggregations