Created
June 22, 2014 06:10
-
-
Save bobbyjam99-zz/508fa7a137e1a05b0666 to your computer and use it in GitHub Desktop.
AWS CloudSearchの検索APIサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.bobbyjam99; | |
import org.apache.http.HttpEntity; | |
import org.apache.http.HttpStatus; | |
import org.apache.http.client.methods.CloseableHttpResponse; | |
import org.apache.http.client.methods.HttpGet; | |
import org.apache.http.impl.client.CloseableHttpClient; | |
import org.apache.http.impl.client.HttpClients; | |
import org.apache.http.util.EntityUtils; | |
import java.io.IOException; | |
import java.nio.charset.StandardCharsets; | |
/** | |
* AWS CloudSearchの検索API実行サンプル | |
*/ | |
public class CloudSearchSample { | |
/** AWSマネジメントコンソールに記載してある"Search Endpoint" */ | |
static String domain = "http://hoge.ap-northeast-1.cloudsearch.amazonaws.com"; | |
/** バージョン番号? */ | |
static String endpoint = "/2013-01-01/search"; | |
/** 検索ワード("おお"で検索) */ | |
static String query = "?q=%E3%81%8A%E3%81%8A"; | |
public static void main(String[] args) { | |
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { | |
HttpGet getMethod = new HttpGet(domain + endpoint + query); | |
try (CloseableHttpResponse response = httpClient.execute(getMethod)) { | |
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { | |
HttpEntity entity = response.getEntity(); | |
System.out.println(EntityUtils.toString(entity, | |
StandardCharsets.UTF_8)); | |
} | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment