이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 246. Olingo2 Component


Available as of Camel version 2.14

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>

246.1. URI format

    olingo2://endpoint/<resource-path>?[options]

246.2. Olingo2 Options

The Olingo2 component supports 3 options which are listed below.

NameDescriptionDefaultType

configuration (common)

To use the shared configuration

 

Olingo2Configuration

useGlobalSslContext Parameters (security)

Enable usage of global SSL context parameters.

false

boolean

resolveProperty Placeholders (advanced)

Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders.

true

boolean

The Olingo2 endpoint is configured using URI syntax:

olingo2:apiName/methodName

with the following path and query parameters:

246.2.1. Path Parameters (2 parameters):

NameDescriptionDefaultType

apiName

Required What kind of operation to perform

 

Olingo2ApiName

methodName

Required What sub operation to use for the selected operation

 

String

246.2.2. Query Parameters (14 parameters):

NameDescriptionDefaultType

connectTimeout (common)

HTTP connection creation timeout in milliseconds, defaults to 30,000 (30 seconds)

30000

int

contentType (common)

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

httpAsyncClientBuilder (common)

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

httpClientBuilder (common)

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

httpHeaders (common)

Custom HTTP headers to inject into every request, this could include OAuth tokens, etc.

 

Map

inBody (common)

Sets the name of a parameter to be passed in the exchange In Body

 

String

proxy (common)

HTTP proxy server configuration

 

HttpHost

serviceUri (common)

Target OData service base URI, e.g. http://services.odata.org/OData/OData.svc

 

String

socketTimeout (common)

HTTP request timeout in milliseconds, defaults to 30,000 (30 seconds)

30000

int

sslContextParameters (common)

To configure security using SSLContextParameters

 

SSLContextParameters

bridgeErrorHandler (consumer)

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

exceptionHandler (consumer)

To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored.

 

ExceptionHandler

exchangePattern (consumer)

Sets the exchange pattern when the consumer creates an exchange.

 

ExchangePattern

synchronous (advanced)

Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported).

false

boolean

246.3. Producer Endpoints

Producer endpoints can use endpoint names and options listed next. Producer endpoints can also use a special option inBody that in turn should contain the name of the endpoint option whose value will be contained in the Camel Exchange In message. The inBody option defaults to data for endpoints that take that option. 

246.4. Endpoint Options

Any of the endpoint options can be provided in either the endpoint URI, or dynamically in a message header. The message header name must be of the format CamelOlingo2.<option>. Note that the inBody option overrides message header, i.e. the endpoint option inBody=option would override a CamelOlingo2.option header. In addition, query parameters can be specified. 

NameTypeDescription

data

Object

Data with appropriate type used to create or modify the OData resource

keyPredicate

String

Key predicate to create a parameterized OData resource endpoint. Useful for create/update operations where the key predicate value is dynamically provided in a header

queryParams

java.util.Map<String,String>

OData system options and custom query options. For more information see OData 2.0 URI Conventions

resourcePath

String

OData resource path, may or may not contain key predicate

endpointHttpHeaders

java.util.Map<String, String>

Dynamic HTTP Headers to be sent to the endpoint

responseHttpHeaders

java.util.Map<String, String>

Dynamic HTTP Response Headers from the endpoint

Note that the resourcePath option can either in specified in the URI as a part of the URI path, as an endpoint option ?resourcePath=<resource-path> or as a header value CamelOlingo2.resourcePath. The OData entity key predicate can either be a part of the resource path, e.g. Manufacturers('1'), where '__1' is the key predicate, or be specified separately with resource path Manufacturers and keyPredicate option '1'

EndpointOptionsHTTP MethodResult Body Type

batch

data, endpointHttpHeaders

POST with multipart/mixed batch request

java.util.List<org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse>

create

data, resourcePath, endpointHttpHeaders

POST

org.apache.olingo.odata2.api.ep.entry.ODataEntry for new entries org.apache.olingo.odata2.api.commons.HttpStatusCodes for other OData resources

delete

resourcePath, endpointHttpHeaders

DELETE

org.apache.olingo.odata2.api.commons.HttpStatusCodes

merge

data, resourcePath, endpointHttpHeaders

MERGE

org.apache.olingo.odata2.api.commons.HttpStatusCodes

patch

data, resourcePath, endpointHttpHeaders

PATCH

org.apache.olingo.odata2.api.commons.HttpStatusCodes

read

queryParams, resourcePath, endpointHttpHeaders

GET

Depends on OData resource being queried as described next

update

data, resourcePath, endpointHttpHeaders

PUT

org.apache.olingo.odata2.api.commons.HttpStatusCodes

246.5. Endpoint HTTP Headers (Since 2.20)

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>.

246.6. 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 TypeResource URI from resourcePath and keyPredicateIn 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

246.7. Consumer Endpoints

Only the read endpoint can be used as a consumer endpoint. Consumer endpoints can use Scheduled Poll Consumer Options with a consumer. prefix to schedule endpoint invocation. By default consumer endpoints that return an array or collection will generate one exchange per element, and their routes will be executed once for each exchange. This behavior can be disabled by setting the endpoint property consumer.splitResult=false

246.8. Message Headers

Any URI option can be provided in a message header for producer endpoints with a CamelOlingo2. prefix.

246.9. Message Body

All result message bodies utilize objects provided by the underlying Apache Olingo 2.0 API used by the Olingo2Component. Producer endpoints can specify the option name for incoming message body in the inBody endpoint URI parameter. For endpoints that return an array or collection, a consumer endpoint will map every element to distinct messages, unless consumer.splitResult is set to false.

246.10. Use cases

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&consumer.timeUnit=SECONDS&consumer.delay=30")
    .to("bean:blah");
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.