java.lang.reflect.InvocationTargetException at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:204)

I run this code:

    private void notify(String date, int space) throws IOException {

        String ACCOUNT_SID = "dddddd";
        String AUTH_TOKEN = "ggggggg";
        String TWILIO_PHONE = "+my twilio project";
        String ELAD_PHONE = "+my real number";

        TwilioRestClient client;
        client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

        // Build a filter for the CallList
        Map<String, String> params = new HashMap<String, String>();
        params.put("Url", "http://demo.twilio.com/docs/voice.xml");
        params.put("To", ELAD_PHONE);
        params.put("From", TWILIO_PHONE);


        CallFactory callFactory = client.getAccount().getCallFactory();
        Call call;
        try {
            call = callFactory.create(params);
            call.getSid();
        } catch (TwilioRestException e) {
            String a = e.toString();
//            log("******** Failed to call", e);
        }

when I run this line:

call = callFactory.create(params);

I get this exception:

 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:498)
        at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:204)
        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:404)
        at com.twilio.sdk.TwilioRestClient.safeRequest(TwilioRestClient.java:534)
        at com.twilio.sdk.resource.list.CallList.create(CallList.java:68)
        at Runner.notify(Runner.java:152)
        at Runner.run(Runner.java:40)
        at Runner.main(Runner.java:25)
    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:109)
        at com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:38)
        ... 18 more
    Oct 01, 2016 2:39:43 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
    Oct 01, 2016 2:39:43 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:498)
        at com.twilio.sdk.AppEngineClientConnection.flush(AppEngineClientConnection.java:204)
        at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:258)

Answer

I was answered that:

It looks like you are trying to test from your local dev environment.

With Google App Engine, if you want to test in local dev environment, I think you need to use App Engine SDK for Java. This should work when deployed to Google App Engine. Let me know if this solves this issue!

Leave a Reply

Your email address will not be published. Required fields are marked *