Search in sources :

Example 1 with ODataSerializer

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);
    }
}
Also used : ODataSerializer(org.apache.olingo.client.api.serialization.ODataSerializer) HttpClientException(org.apache.olingo.client.api.http.HttpClientException) HttpEntity(org.apache.http.HttpEntity) ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) URISyntaxException(java.net.URISyntaxException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) ODataClientErrorException(org.apache.olingo.client.api.communication.ODataClientErrorException) HttpClientException(org.apache.olingo.client.api.http.HttpClientException)

Example 2 with ODataSerializer

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);
}
Also used : ClientEntity(org.apache.olingo.client.api.domain.ClientEntity) Entity(org.apache.olingo.commons.api.data.Entity) ClientEntity(org.apache.olingo.client.api.domain.ClientEntity) ODataSerializer(org.apache.olingo.client.api.serialization.ODataSerializer) Olingo4Configuration(org.apache.camel.component.olingo4.Olingo4Configuration) StringWriter(java.io.StringWriter) Olingo4Component(org.apache.camel.component.olingo4.Olingo4Component)

Aggregations

ODataSerializer (org.apache.olingo.client.api.serialization.ODataSerializer)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 StringWriter (java.io.StringWriter)1 URISyntaxException (java.net.URISyntaxException)1 ServiceUnavailableException (javax.naming.ServiceUnavailableException)1 Olingo4Component (org.apache.camel.component.olingo4.Olingo4Component)1 Olingo4Configuration (org.apache.camel.component.olingo4.Olingo4Configuration)1 HttpEntity (org.apache.http.HttpEntity)1 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)1 ODataClientErrorException (org.apache.olingo.client.api.communication.ODataClientErrorException)1 ClientEntity (org.apache.olingo.client.api.domain.ClientEntity)1 HttpClientException (org.apache.olingo.client.api.http.HttpClientException)1 Entity (org.apache.olingo.commons.api.data.Entity)1