App Engine에서 Twilio의 Java 클라이언트 라이브러리를 사용하려고합니다. 있는 그대로 실행되지 않으며 클라이언트 lib에 약간의 변경이 필요할 것입니다. 나는 다음과 같은 변경을했지만 작동하지 않습니다App Engine의 Twilio 클라이언트 라이브러리
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);
}
이 컴파일 및 실행을 얻는다 그러나 나는이 예외를 얻을 : 계획 'HTTPS'하지 : 에 의한 : org.apache.http.HttpException를 등기. 요청이 이루어지면 요청한 내용은 다음과 같습니다 (변경되지 않음).
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 요청 일뿐입니다. 클라이언트 라이브러리를 사용하고 나 자신을 코딩하는 요청을하는 데 시간을 낭비하지 않기를 바랬습니다 ... 어떤 아이디어?