Olingo2
Since Camel 2.14
Both producer and consumer are supported
Starting with Camel 4.0, our project has migrated to JakartaEE. Some parts of Apache Olingo2 may depend on J2EE, which may result in unexpected behavior and other runtime problems. |
The Olingo2 component utilizes Apache Olingo version 2.0 APIs to interact with OData 2.0 compliant services. A number of popular commercial and enterprise vendors and products support the OData protocol. A sample list of supporting products can be found on the OData website.
The Olingo2 component supports reading feeds, delta feeds, entities, simple and complex properties, links, counts, using custom and OData system query parameters. It supports updating entities, properties, and association links. It also supports submitting queries and change requests as a single OData batch operation.
The component supports configuring HTTP connection parameters and headers for OData service connection. This allows configuring use of SSL, OAuth2.0, etc. as required by the target OData service.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-olingo2</artifactId>
<version>${camel-version}</version>
</dependency>
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. For example a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
Component Options
The Olingo2 component supports 18 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
To use the shared configuration. | Olingo2Configuration | ||
HTTP connection creation timeout in milliseconds, defaults to 30,000 (30 seconds). | 30000 | int | |
Content-Type header value can be used to specify JSON or XML message format, defaults to application/json;charset=utf-8. | application/json;charset=utf-8 | String | |
Custom entity provider read properties applied to all read operations. | EntityProviderReadProperties | ||
Custom entity provider write properties applied to create, update, patch, batch and merge operations. For instance users can skip the Json object wrapper or enable content only mode when sending request data. A service URI set in the properties will always be overwritten by the serviceUri configuration parameter. Please consider to using the serviceUri configuration parameter instead of setting the respective write property here. | EntityProviderWriteProperties | ||
Set this to true to filter out results that have already been communicated by this component. | false | boolean | |
Custom HTTP headers to inject into every request, this could include OAuth tokens, etc. | Map | ||
HTTP proxy server configuration. | HttpHost | ||
Target OData service base URI, e.g. http://services.odata.org/OData/OData.svc. | String | ||
HTTP request timeout in milliseconds, defaults to 30,000 (30 seconds). | 30000 | int | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
For endpoints that return an array or collection, a consumer endpoint will map every element to distinct messages, unless splitResult is set to false. | true | boolean | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Custom HTTP async client builder for more complex HTTP client configuration, overrides connectionTimeout, socketTimeout, proxy and sslContext. Note that a socketTimeout MUST be specified in the builder, otherwise OData requests could block indefinitely. | HttpAsyncClientBuilder | ||
Custom HTTP client builder for more complex HTTP client configuration, overrides connectionTimeout, socketTimeout, proxy and sslContext. Note that a socketTimeout MUST be specified in the builder, otherwise OData requests could block indefinitely. | HttpClientBuilder | ||
To configure security using SSLContextParameters. | SSLContextParameters | ||
Enable usage of global SSL context parameters. | false | boolean |
Endpoint Options
The Olingo2 endpoint is configured using URI syntax:
olingo2:apiName/methodName
with the following path and query parameters:
Query Parameters (34 parameters)
Name | Description | Default | Type |
---|---|---|---|
HTTP connection creation timeout in milliseconds, defaults to 30,000 (30 seconds). | 30000 | int | |
Content-Type header value can be used to specify JSON or XML message format, defaults to application/json;charset=utf-8. | application/json;charset=utf-8 | String | |
Custom entity provider read properties applied to all read operations. | EntityProviderReadProperties | ||
Custom entity provider write properties applied to create, update, patch, batch and merge operations. For instance users can skip the Json object wrapper or enable content only mode when sending request data. A service URI set in the properties will always be overwritten by the serviceUri configuration parameter. Please consider to using the serviceUri configuration parameter instead of setting the respective write property here. | EntityProviderWriteProperties | ||
Set this to true to filter out results that have already been communicated by this component. | false | boolean | |
Custom HTTP headers to inject into every request, this could include OAuth tokens, etc. | Map | ||
Sets the name of a parameter to be passed in the exchange In Body. | String | ||
HTTP proxy server configuration. | HttpHost | ||
Target OData service base URI, e.g. http://services.odata.org/OData/OData.svc. | String | ||
HTTP request timeout in milliseconds, defaults to 30,000 (30 seconds). | 30000 | int | |
If the polling consumer did not poll any files, you can enable this option to send an empty message (no body) instead. | false | boolean | |
For endpoints that return an array or collection, a consumer endpoint will map every element to distinct messages, unless splitResult is set to false. | true | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A pluggable org.apache.camel.PollingConsumerPollingStrategy allowing you to provide your custom implementation to control error handling usually occurred during the poll operation before an Exchange have been created and being routed in Camel. | PollingConsumerPollStrategy | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Custom HTTP async client builder for more complex HTTP client configuration, overrides connectionTimeout, socketTimeout, proxy and sslContext. Note that a socketTimeout MUST be specified in the builder, otherwise OData requests could block indefinitely. | HttpAsyncClientBuilder | ||
Custom HTTP client builder for more complex HTTP client configuration, overrides connectionTimeout, socketTimeout, proxy and sslContext. Note that a socketTimeout MUST be specified in the builder, otherwise OData requests could block indefinitely. | HttpClientBuilder | ||
The number of subsequent error polls (failed due some error) that should happen before the backoffMultipler should kick-in. | int | ||
The number of subsequent idle polls that should happen before the backoffMultipler should kick-in. | int | ||
To let the scheduled polling consumer backoff if there has been a number of subsequent idles/errors in a row. The multiplier is then the number of polls that will be skipped before the next actual attempt is happening again. When this option is in use then backoffIdleThreshold and/or backoffErrorThreshold must also be configured. | int | ||
Milliseconds before the next poll. | 500 | long | |
If greedy is enabled, then the ScheduledPollConsumer will run immediately again, if the previous run polled 1 or more messages. | false | boolean | |
Milliseconds before the first poll starts. | 1000 | long | |
Specifies a maximum limit of number of fires. So if you set it to 1, the scheduler will only fire once. If you set it to 5, it will only fire five times. A value of zero or negative means fire forever. | 0 | long | |
The consumer logs a start/complete log line when it polls. This option allows you to configure the logging level for that. Enum values:
| TRACE | LoggingLevel | |
Allows for configuring a custom/shared thread pool to use for the consumer. By default each consumer has its own single threaded thread pool. | ScheduledExecutorService | ||
To use a cron scheduler from either camel-spring or camel-quartz component. Use value spring or quartz for built in scheduler. | none | Object | |
To configure additional properties when using a custom scheduler or any of the Quartz, Spring based scheduler. | Map | ||
Whether the scheduler should be auto started. | true | boolean | |
Time unit for initialDelay and delay options. Enum values:
| MILLISECONDS | TimeUnit | |
Controls if fixed delay or fixed rate is used. See ScheduledExecutorService in JDK for details. | true | boolean | |
To configure security using SSLContextParameters. | SSLContextParameters |
API Parameters (1 APIs)
The Olingo2 endpoint is an API based component and has additional parameters based on which API name and API method is used. The API name and API method is located in the endpoint URI as the apiName/methodName
path parameters:
olingo2:apiName/methodName
There are 1 API names as listed in the table below:
API Name | Type | Description |
---|---|---|
Both | Olingo2 Client Api Interface |
Each API is documented in the following sections to come.
API: DEFAULT
Both producer and consumer are supported
The DEFAULT API is defined in the syntax as follows:
olingo2:DEFAULT/methodName?[parameters]
The 8 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)
Method | Alias | Description |
---|---|---|
Executes a batch request | ||
Creates a new OData resource | ||
Deletes an OData resource and invokes callback with org | ||
Patches/merges an OData resource using HTTP MERGE | ||
Patches/merges an OData resource using HTTP PATCH | ||
Reads an OData resource and invokes callback with appropriate result | ||
Updates an OData resource | ||
Reads an OData resource and invokes callback with the unparsed input stream |
Method batch
Signatures:
-
void batch(org.apache.olingo.odata2.api.edm.Edm edm, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler<java.util.List<org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse>> responseHandler);
The olingo2/batch API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
data | Ordered org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest list | Object |
edm | Service Edm | Edm |
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
responseHandler | Callback handler | Olingo2ResponseHandler |
Method create
Signatures:
-
void create(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler);
The olingo2/create API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
data | Request data | Object |
edm | Service Edm | Edm |
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
resourcePath | Resource path to create | String |
responseHandler | Callback handler | Olingo2ResponseHandler |
Method delete
Signatures:
-
void delete(String resourcePath, java.util.Map<String, String> endpointHttpHeaders, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler<org.apache.olingo.odata2.api.commons.HttpStatusCodes> responseHandler);
The olingo2/delete API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
resourcePath | Resource path for Entry | String |
responseHandler | Org.apache.olingo.odata2.api.commons.HttpStatusCodes callback handler | Olingo2ResponseHandler |
Method merge
Signatures:
-
void merge(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler);
The olingo2/merge API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
data | Patch/merge data | Object |
edm | Service Edm | Edm |
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
resourcePath | Resource path to update | String |
responseHandler | Org.apache.olingo.odata2.api.ep.entry.ODataEntry callback handler | Olingo2ResponseHandler |
Method patch
Signatures:
-
void patch(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler);
The olingo2/patch API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
data | Patch/merge data | Object |
edm | Service Edm | Edm |
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
resourcePath | Resource path to update | String |
responseHandler | Org.apache.olingo.odata2.api.ep.entry.ODataEntry callback handler | Olingo2ResponseHandler |
Method read
Signatures:
-
void read(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> queryParams, java.util.Map<String, String> endpointHttpHeaders, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler);
The olingo2/read API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
edm | Service Edm, read from calling read(null, $metdata, null, responseHandler) | Edm |
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
queryParams | OData query params from http://www.odata.org/documentation/odata-version-2-0/uri-conventions#SystemQueryOptions | Map |
resourcePath | OData Resource path | String |
responseHandler | Callback handler | Olingo2ResponseHandler |
Method update
Signatures:
-
void update(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> endpointHttpHeaders, Object data, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler responseHandler);
The olingo2/update API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
data | Updated data | Object |
edm | Service Edm | Edm |
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
resourcePath | Resource path to update | String |
responseHandler | Org.apache.olingo.odata2.api.ep.entry.ODataEntry callback handler | Olingo2ResponseHandler |
Method uread
Signatures:
-
void uread(org.apache.olingo.odata2.api.edm.Edm edm, String resourcePath, java.util.Map<String, String> queryParams, java.util.Map<String, String> endpointHttpHeaders, org.apache.camel.component.olingo2.api.Olingo2ResponseHandler<java.io.InputStream> responseHandler);
The olingo2/uread API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
edm | Service Edm, read from calling read(null, $metdata, null, responseHandler) | Edm |
endpointHttpHeaders | HTTP Headers to add/override the component versions | Map |
queryParams | OData query params from http://www.odata.org/documentation/odata-version-2-0/uri-conventions#SystemQueryOptions | Map |
resourcePath | OData Resource path | String |
responseHandler | Callback handler | Olingo2ResponseHandler |
In addition to the parameters above, the olingo2 API can also use any of the Query Parameters (34 parameters).
Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelOlingo2.parameter
. The inBody
parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere
would override a CamelOlingo2.myParameterNameHere
header.
Message Headers
The Olingo2 component supports 1 message header(s), which is/are listed below:
Name | Description | Default | Type |
---|---|---|---|
CamelOlingo2.responseHttpHeaders (producer) Constant: | The response Http headers. | Map |
Endpoint HTTP Headers
The component level configuration property httpHeaders supplies static HTTP header information. However, some systems requires dynamic header information to be passed to and received from the endpoint. A sample use case would be systems that require dynamic security tokens. The endpointHttpHeaders and responseHttpHeaders endpoint properties provides this capability. Set headers that need to be passed to the endpoint in the CamelOlingo2.endpointHttpHeaders
property and the response headers will be returned in a CamelOlingo2.responseHttpHeaders
property. Both properties are of the type java.util.Map<String, String>
.
OData Resource Type Mapping
The result of read endpoint and data type of data option depends on the OData resource being queried, created or modified.
OData Resource Type | Resource URI from resourcePath and keyPredicate | In or Out Body Type |
---|---|---|
Entity data model | $metadata | org.apache.olingo.odata2.api.edm.Edm |
Service document | / | org.apache.olingo.odata2.api.servicedocument.ServiceDocument |
OData feed | <entity-set> | org.apache.olingo.odata2.api.ep.feed.ODataFeed |
OData entry | <entity-set>(<key-predicate>) | org.apache.olingo.odata2.api.ep.entry.ODataEntry for Out body (response) java.util.Map<String, Object> for In body (request) |
Simple property | <entity-set>(<key-predicate>)/<simple-property> | Appropriate Java data type as described by Olingo EdmProperty |
Simple property value | <entity-set>(<key-predicate>)/<simple-property>/$value | Appropriate Java data type as described by Olingo EdmProperty |
Complex property | <entity-set>(<key-predicate>)/<complex-property> | java.util.Map<String, Object> |
Zero or one association link | <entity-set>(<key-predicate>/$link/<one-to-one-entity-set-property> | String for response java.util.Map<String, Object> with key property names and values for request |
Zero or many association links | <entity-set>(<key-predicate>/$link/<one-to-many-entity-set-property> | java.util.List<String> for response java.util.List<java.util.Map<String, Object>> containing list of key property names and values for request |
Count | <resource-uri>/$count | java.lang.Long |
Samples
The following route reads top 5 entries from the Manufacturer feed ordered by ascending Name property.
from("direct:...")
.setHeader("CamelOlingo2.$top", "5");
.to("olingo2://read/Manufacturers?orderBy=Name%20asc");
The following route reads Manufacturer entry using the key property value in incoming id header.
from("direct:...")
.setHeader("CamelOlingo2.keyPredicate", header("id"))
.to("olingo2://read/Manufacturers");
The following route creates Manufacturer entry using the java.util.Map<String, Object> in body message.
from("direct:...")
.to("olingo2://create/Manufacturers");
The following route polls Manufacturer delta feed every 30 seconds. The bean blah updates the bean paramsBean to add an updated !deltatoken property with the value returned in the ODataDeltaFeed result. Since the initial delta token is not known, the consumer endpoint will produce an ODataFeed value the first time, and ODataDeltaFeed on subsequent polls.
from("olingo2://read/Manufacturers?queryParams=#paramsBean&timeUnit=SECONDS&delay=30")
.to("bean:blah");
Spring Boot Auto-Configuration
When using olingo2 with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-olingo2-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 19 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | Boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | Boolean | |
To use the shared configuration. The option is a org.apache.camel.component.olingo2.Olingo2Configuration type. | Olingo2Configuration | ||
HTTP connection creation timeout in milliseconds, defaults to 30,000 (30 seconds). | 30000 | Integer | |
Content-Type header value can be used to specify JSON or XML message format, defaults to application/json;charset=utf-8. | application/json;charset=utf-8 | String | |
Whether to enable auto configuration of the olingo2 component. This is enabled by default. | Boolean | ||
Custom entity provider read properties applied to all read operations. The option is a org.apache.olingo.odata2.api.ep.EntityProviderReadProperties type. | EntityProviderReadProperties | ||
Custom entity provider write properties applied to create, update, patch, batch and merge operations. For instance users can skip the Json object wrapper or enable content only mode when sending request data. A service URI set in the properties will always be overwritten by the serviceUri configuration parameter. Please consider to using the serviceUri configuration parameter instead of setting the respective write property here. The option is a org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties type. | EntityProviderWriteProperties | ||
Set this to true to filter out results that have already been communicated by this component. | false | Boolean | |
Custom HTTP async client builder for more complex HTTP client configuration, overrides connectionTimeout, socketTimeout, proxy and sslContext. Note that a socketTimeout MUST be specified in the builder, otherwise OData requests could block indefinitely. The option is a org.apache.http.impl.nio.client.HttpAsyncClientBuilder type. | HttpAsyncClientBuilder | ||
Custom HTTP client builder for more complex HTTP client configuration, overrides connectionTimeout, socketTimeout, proxy and sslContext. Note that a socketTimeout MUST be specified in the builder, otherwise OData requests could block indefinitely. The option is a org.apache.http.impl.client.HttpClientBuilder type. | HttpClientBuilder | ||
Custom HTTP headers to inject into every request, this could include OAuth tokens, etc. | Map | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | Boolean | |
HTTP proxy server configuration. The option is a org.apache.http.HttpHost type. | HttpHost | ||
Target OData service base URI, e.g. http://services.odata.org/OData/OData.svc. | String | ||
HTTP request timeout in milliseconds, defaults to 30,000 (30 seconds). | 30000 | Integer | |
For endpoints that return an array or collection, a consumer endpoint will map every element to distinct messages, unless splitResult is set to false. | true | Boolean | |
To configure security using SSLContextParameters. The option is a org.apache.camel.support.jsse.SSLContextParameters type. | SSLContextParameters | ||
Enable usage of global SSL context parameters. | false | Boolean |