appengine で Twilio の Java クライアント ライブラリを使用しようとしています。そのままでは実行されないようで、クライアント ライブラリに変更を加える必要があります。次の変更を加えましたが、機能しません。
public TwilioRestClient(String accountSid, String authToken, String endpoint) {
validateAccountSid(accountSid);
validateAuthToken(authToken);
this.accountSid = accountSid;
this.authToken = authToken;
if ((endpoint != null) && (!endpoint.equals(""))) {
this.endpoint = endpoint;
}
/* origial code
* ThreadSafeClientConnManager connMgr = new ThreadSafeClientConnManager();
* connMgr.setDefaultMaxPerRoute(10);
* this.httpclient = new DefaultHttpClient(connMgr);
*/
//my changes start HERE
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
BasicHttpParams params = new BasicHttpParams();
ThreadSafeClientConnManager connMgr = new ThreadSafeClientConnManager(params,schemeRegistry);
//my changes END HERE
this.httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter("http.protocol.version",
HttpVersion.HTTP_1_1);
httpclient.getParams().setParameter("http.socket.timeout",
new Integer(CONNECTION_TIMEOUT));
httpclient.getParams().setParameter("http.connection.timeout",
new Integer(CONNECTION_TIMEOUT));
httpclient.getParams().setParameter("http.protocol.content-charset",
"UTF-8");
this.authAccount = new Account(this);
this.authAccount.setSid(this.accountSid);
this.authAccount.setAuthToken(this.authToken);
}
これによりコンパイルして実行できますが、次の例外が発生します: 原因: org.apache.http.HttpException: スキーム 'https' が登録されていません。リクエストが行われたとき。リクエストは、この (変更されていない) コードにあります。
public TwilioRestResponse request(String path, String method,
Map<String, String> vars) throws TwilioRestException {
HttpUriRequest request = setupRequest(path, method, vars);
HttpResponse response;
try {
response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
Header[] contentTypeHeaders = response.getHeaders("Content-Type");
String responseBody = "";
if (entity != null) {
responseBody = EntityUtils.toString(entity);
}
StatusLine status = response.getStatusLine();
int statusCode = status.getStatusCode();
TwilioRestResponse restResponse = new TwilioRestResponse(request
.getURI().toString(), responseBody, statusCode);
// For now we only set the first content type seen
for (Header h : contentTypeHeaders) {
restResponse.setContentType(h.getValue());
break;
}
return restResponse;
} catch (ClientProtocolException e1) {
throw new RuntimeException(e1);
} catch (IOException e1) {
throw new RuntimeException(e1);
}
}
twilio で Java 用の appengine を使用した人はいますか? 基本認証を使用した XML または JSON を使用した単なる RESTful 要求であることはわかっています。私はクライアント ライブラリを使用し、自分でリクエストのコーディングに時間を費やさないようにしたいと考えていました...何かアイデアはありますか?