3.12. 文字セットの設定

POST を使用してデータを送信している場合は、Exchange プロパティーを使用して charset を設定できます。

exchange.setProperty(Exchange.CHARSET_NAME, "iso-8859-1");

3.12.1. エンドポイント URI からの URI パラメーター

このサンプルには、Web ブラウザーに入力したものとまったく同じ完全な URI エンドポイントがあります。もちろん、Web ブラウザーと同じように & 文字を区切り文字として使用して、複数の URI パラメーターを設定できます。Camel はここでトリックを行いません。

// we query for Camel at the Google page
template.sendBody("ahc:http://www.google.com/search?q=Camel", null);

3.12.2. メッセージからの URI パラメーター

Map headers = new HashMap();
headers.put(Exchange.HTTP_QUERY, "q=Camel&lr=lang_en");
// we query for Camel and English language at Google
template.sendBody("ahc:http://www.google.com/search", null, headers);

上記のヘッダー値では、? を接頭辞として付けるべきでは ない ことに注意してください。& 文字を使用して、通常どおりパラメーターを区切ることができます。

3.12.3. 応答コードの取得

Exchange.HTTP_RESPONSE_CODE を使用して Out メッセージヘッダーから値を取得して、AHC コンポーネントから HTTP 応答コードを取得できます。

Exchange exchange = template.send("ahc:http://www.google.com/search", new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader(Exchange.HTTP_QUERY, constant("hl=en&q=activemq"));
            }
   });
   Message out = exchange.getOut();
   int responseCode = out.getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class);