[英]Apache Camel: URI Escaping in HTTP (and other Producers)
[英]Invalid query : URI parse exception in Apache HTTP Client used in Camel
我正在尝试使用Apache Camel调用Yahoo API。
Yahoo API是http://query.yahooapis.com/v1/public/yql?q=select%20 *%20from%20music.artist.search%20 where%20keyword%3D%22Madonna%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")
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.