0

我正在尝试使用顶部、格式和过滤器查询参数运行 Camel Olingo2 路由到 OData 服务,但是 Olingo 组件没有对参数进行编码,因此它会引发 URISyntaxException,如果我在调用组件之前对参数进行编码,那么参数将返回无效,有什么方法可以将过滤参数与 Olingo2 组件一起使用?

例子:

路线示例

from("timer://camelpoll?period=120000")
    .id("PersonPoll")
    .log("CAMEL_POLLING_IN_PROGRESS")
    .setHeader("CamelOlingo2.$top", constant("5"))
    .setHeader("CamelOlingo2.$format", constant("json"))
    .setHeader("CamelOlingo2.$filter", constant("Timestamp gt datetime'2014-06-26T03:30:00.000'"))
    .to("olingo2://read/Persons");

错误日志

Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 131: https://<hostname>/Persons/?$top=5&$filter=Timestamp gt datetime'2014-06-26T03:30:00.000'&$format=json
    at java.net.URI.create(URI.java:852) ~[na:1.8.0_45]
    at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69) ~[httpclient-4.5.2.jar:4.5.2]
    at org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl.read(Olingo2AppImpl.java:190) ~[camel-olingo2-api-2.17.1.jar:2.17.1]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_45]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_45]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_45]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_45]
    at org.apache.camel.util.component.ApiMethodHelper.invokeMethod(ApiMethodHelper.java:461) ~[camel-core-2.17.1.jar:2.17.1]
    ... 13 common frames omitted
Caused by: java.net.URISyntaxException: Illegal character in query at index 131: https://<hostname>/Persons/?$top=5&$filter=Timestamp gt datetime'2014-06-26T03:30:00.000'&$format=json
    at java.net.URI$Parser.fail(URI.java:2848) ~[na:1.8.0_45]
    at java.net.URI$Parser.checkChars(URI.java:3021) ~[na:1.8.0_45]
    at java.net.URI$Parser.parseHierarchical(URI.java:3111) ~[na:1.8.0_45]
    at java.net.URI$Parser.parse(URI.java:3053) ~[na:1.8.0_45]
    at java.net.URI.<init>(URI.java:588) ~[na:1.8.0_45]
    at java.net.URI.create(URI.java:850) ~[na:1.8.0_45]
    ... 20 common frames omitted
4

1 回答 1

0

好吧,看起来 olingo2 组件有问题,所以我必须创建一个自定义组件来实现这一点。

于 2016-09-21T16:28:35.280 回答