Search in sources :

Example 1 with Olingo4Configuration

use of org.apache.camel.component.olingo4.Olingo4Configuration in project wildfly-camel by wildfly-extras.

the class Olingo4IntegrationTest method createCamelContext.

private CamelContext createCamelContext() throws Exception {
    final CamelContext context = new DefaultCamelContext();
    Map<String, Object> options = new HashMap<String, Object>();
    options.put("serviceUri", getRealServiceUrl(TEST_SERVICE_BASE_URL));
    options.put("contentType", "application/json;charset=utf-8");
    final Olingo4Configuration configuration = new Olingo4Configuration();
    IntrospectionSupport.setProperties(configuration, options);
    // add OlingoComponent to Camel context
    final Olingo4Component component = new Olingo4Component(context);
    component.setConfiguration(configuration);
    context.addComponent("olingo4", component);
    return context;
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Olingo4Configuration(org.apache.camel.component.olingo4.Olingo4Configuration) HashMap(java.util.HashMap) Olingo4Component(org.apache.camel.component.olingo4.Olingo4Component) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Example 2 with Olingo4Configuration

use of org.apache.camel.component.olingo4.Olingo4Configuration 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

Olingo4Component (org.apache.camel.component.olingo4.Olingo4Component)2 Olingo4Configuration (org.apache.camel.component.olingo4.Olingo4Configuration)2 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 CamelContext (org.apache.camel.CamelContext)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 ClientEntity (org.apache.olingo.client.api.domain.ClientEntity)1 ODataSerializer (org.apache.olingo.client.api.serialization.ODataSerializer)1 Entity (org.apache.olingo.commons.api.data.Entity)1