gpt4 book ai didi

java - 无效查询 : URI parse exception in Apache HTTP Client used in Camel

转载 作者:行者123 更新时间:2023-12-02 07:37:19 25 4
gpt4 key购买 nike

我正在尝试使用 Apache Camel 调用 Yahoo API。

雅虎 API 是 http://query.yahooapis.com/v1/public/yql?q=select%20 *%20from%20music.artist.search%20where%20keyword%3D%22麦当娜%22&format=json

我的路线是这样的。

    from("direct:start_yahoo_artist")
.process(new HTTPRequestParamProcessor())
.setHeader(
Exchange.HTTP_QUERY,
simple("select+*+from+music.artist.search+where+keyword%3D%{in.headers.artist}%22&format=json"))
//simple("select * from music.artist.search where keyword=\"{in.headers.artist}\"&format=json"))
.to("http://query.yahooapis.com/v1/public/yql")
.unmarshal()
.json(JsonLibrary.Jackson, YahooMusicArtistResponseObject.class)
/*.bean(EmbeddedDroolsRuleEngine.class, "callRuleEngine")*/
.process(new Processor() {

@Override
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(exchange.getIn().getBody());

}
});

但是,我收到无效查询异常。 URI 的正确编码方式是什么?

[               qtp263093125-29] Tracer                         INFO  ID-server190-tm-rtsslab-64570-1345237236639-0-2 >>> (route6)  --> http://query.yahooapis.com/v1/public/yql <<< Pattern:InOut, Headers:{CamelHttpMethod=GET, artist=Madonna, breadcrumbId=ID-server190-tm-rtsslab-64570-1345237236639-0-1, CamelHttpQuery=select+*+from+music.artist.search+where+keyword%3D%{in.headers.artist}%22&format=json}, BodyType:null, Body:[Body is null]
[ qtp263093125-29] DefaultErrorHandler ERROR Failed delivery for (MessageId: ID-server190-tm-rtsslab-64570-1345237236639-0-3 on ExchangeId: ID-server190-tm-rtsslab-64570-1345237236639-0-2). Exhausted after delivery attempt: 1 caught: org.apache.commons.httpclient.URIException: Invalid query
org.apache.commons.httpclient.URIException: Invalid query
at org.apache.commons.httpclient.URI.parseUriReference(URI.java:2049)[commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.URI.<init>(URI.java:147)[commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpMethodBase.getURI(HttpMethodBase.java:265)[commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:383)[commons-httpclient-3.1.jar:]
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)[commons-httpclient-3.1.jar:]
at org.apache.camel.component.http.HttpProducer.executeMethod(HttpProducer.java:243)[camel-http-2.10.0.jar:2.10.0]

最佳答案

看这部分:

+keyword%3D%{in.headers.artist}%22

简单内联变量的正常方法是 ${in.headers.artist} 而不是 %{in.headers.artist} 但您可能已将其配置为{}?

但是艺术家字符串之前没有引号,只有在之后 - 这与上面的工作 URL 不同。

这部分网址不应该是:+keyword%3D%22${in.headers.artist}%22 (+keyword="madonna") 吗?

关于java - 无效查询 : URI parse exception in Apache HTTP Client used in Camel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12013314/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com