使用twilio发送短信:API包' urlfetch'或致电' Fetch()'没找到

时间:2016-04-01 19:25:32

标签: java google-app-engine sms twilio

我正在运行此代码:

ACCOUNT_SID, AUTH_TOKEN =来自我的帐户

public static void main(String[] args) throws TwilioRestException {

    TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

    Account account = client.getAccount();

    MessageFactory messageFactory = account.getMessageFactory();
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("To", ...my number...));
    params.add(new BasicNameValuePair("From", ...my twilio number..));
    params.add(new BasicNameValuePair("Body", "Where's Wallace?"));
    Message sms = messageFactory.create(params);

    String a = "1";
}

但在运行messageFactory.create

时会遇到此异常

我跑了:

mvn appengine:devserver

任何想法如何解决这个问题?

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:197)
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:258)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at com.twilio.sdk.TwilioRestClient.request(TwilioRestClient.java:410)
    at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:581)
    at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)
    at com.waze.beacon.inline.server.services.SmsSenderImp.main(SmsSenderImp.java:33)
Caused by: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:111)
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:38)
    ... 16 more
Apr 01, 2016 10:07:51 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.io.IOException) caught when processing request: Error flushing content in Google App Engine fetch
Apr 01, 2016 10:07:51 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:197)
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:258)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at com.twilio.sdk.TwilioRestClient.request(TwilioRestClient.java:410)
    at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:581)
    at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)
    at com.waze.beacon.inline.server.services.SmsSenderImp.main(SmsSenderImp.java:33)
Caused by: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:111)
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:38)
    ... 16 more
Apr 01, 2016 10:07:51 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.io.IOException) caught when processing request: Error flushing content in Google App Engine fetch
Apr 01, 2016 10:07:51 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:197)
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:258)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at com.twilio.sdk.TwilioRestClient.request(TwilioRestClient.java:410)
    at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:581)
    at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)
    at com.waze.beacon.inline.server.services.SmsSenderImp.main(SmsSenderImp.java:33)
Caused by: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:111)
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:38)
    ... 16 more
Apr 01, 2016 10:07:51 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: I/O exception (java.io.IOException) caught when processing request: Error flushing content in Google App Engine fetch
Apr 01, 2016 10:07:51 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute
INFO: Retrying request
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:197)
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:258)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at com.twilio.sdk.TwilioRestClient.request(TwilioRestClient.java:410)
    at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:581)
    at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)
    at com.waze.beacon.inline.server.services.SmsSenderImp.main(SmsSenderImp.java:33)
Caused by: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.
    at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:111)
    at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:38)
    ... 16 more
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Error flushing content in Google App Engine fetch
    at com.twilio.sdk.TwilioRestClient.request(TwilioRestClient.java:437)
    at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:581)
    at com.twilio.sdk.resource.list.MessageList.create(MessageList.java:70)
    at com.waze.beacon.inline.server.services.SmsSenderImp.main(SmsSenderImp.java:33)
Caused by: java.io.IOException: Error flushing content in Google App Engine fetch
    at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:201)
    at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:258)
    at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:123)
    at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:645)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:464)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)
    at com.twilio.sdk.TwilioRestClient.request(TwilioRestClient.java:410)
    ... 3 more
Disconnected from the target VM, address: '127.0.0.1:61151', transport: 'socket'

Process finished with exit code 1

2 个答案:

答案 0 :(得分:2)

There's this question here that seems to be similar: getting strange exception trying to implement asynchronous http in google app engine for java

According to the accepted answer by @Antony, the issue is that these APIs are not available in the local dev server, but they will be when deployed in Google App Engine.

答案 1 :(得分:1)

来自Twilio的梅根在这里。

我对App Engine不太熟悉,但您的应用正在寻找URLFetchService的具体实现,但无法找到它。

有一些issues关于在GitHub上使用Twilio-Java App Engine可能是相关的。

预期班级的例子:

Class.forName("com.google.appengine.api.urlfetch.HTTPRequest");

让我知道这是否有帮助。