0

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]
4

1 に答える 1

2

この部分を見てください:

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

シンプルに変数をインライン化する通常の方法はそうではあり${in.headers.artist}ません%{in.headers.artist}が、これを次のように構成した可能性があります{ } ?

ただし、アーティスト文字列の前には引用符がなく、後にのみあります。これは、上記の作業 URL とは異なります。

URL のこの部分は次のようにすべきではありません: +keyword%3D%22${in.headers.artist}%22 (+keyword="madonna")?

于 2012-08-18T06:28:18.330 に答える