Apache Camel を使用して Yahoo API を呼び出そうとしています。
Yahoo API は http://query.yahooapis.com/v1/public/yql?q=select%20 *%20from%20music.artist.search%20where%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]