The API package 'remote_socket' or call 'Resolve()' was not found - GAE Java

北慕城南 提交于 2020-01-11 13:54:11

问题


I'm trying to call a Google Service in a GAE application hosted in GAE cloud:

private String doPost(String URL) throws ClientProtocolException, IOException {
    // Params:
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));
    params.add(new BasicNameValuePair("Email", _DEFAULT_USER));
    params.add(new BasicNameValuePair("Passwd", _DEFAULT_PASS));
    params.add(new BasicNameValuePair("service", "ah"));
    // Call
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost post = new HttpPost(URL); // URL:
                                        // https://www.google.com/accounts/ClientLogin
    post.setEntity(new UrlEncodedFormEntity(p_params, HTTP.UTF_8));
    post.getParams().setBooleanParameter(
            CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    HttpResponse response = httpClient.execute(post);
    return _ProcessResponse(response); // Process...
}

The execution throws: com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'remote_socket' or call 'Resolve()' was not found.

Any ideas? I'm totally lost...


回答1:


Can you use a different http client? Such as recommended here:

client = new HttpClient(new SimpleHttpConnectionManager()); 

Or what about using the URLFetchService?

According to this blog post you need a:

"custom connection manager that converts the final requests and feed them into the URL Fetch service, and then feeds the responses back into HttpClient."




回答2:


API package 'remote_socket' or call 'Resolve()' was not found means that InetAddress has been requested to do a name resolution and the undelying API (remote_socket.Resolve) was not found.

The remote_socket API is enabled as part of the trusted tester program for sockets.

Anyhow, your issue is that we don't yet support the resolution of IP addresses (other than localhost etc) in the app engine runtime.

The recommendation to using the urlfetch api directly is one work-around.




回答3:


Thanks!

Solved with...

        URL url = new URL("https://www.google.com/accounts/ClientLogin");

        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
        urlConnection.setRequestMethod("POST");
        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(true);
        urlConnection.setUseCaches(false);
        urlConnection.setRequestProperty("Content-Type",
                                         "application/x-www-form-urlencoded");

        StringBuilder content = new StringBuilder();
        content.append("Email=").append(URLEncoder.encode(_DEFAULT_USER, "UTF-8"));
        content.append("&Passwd=").append(URLEncoder.encode(_DEFAULT_PASS, "UTF-8"));
        content.append("&service=").append(URLEncoder.encode("ah", "UTF-8"));
        OutputStream outputStream = urlConnection.getOutputStream();
        outputStream.write(content.toString().getBytes("UTF-8"));
        outputStream.close();
        // Response....
        int responseCode = urlConnection.getResponseCode();
        InputStream inputStream;
        if (responseCode == HttpURLConnection.HTTP_OK) {
          inputStream = urlConnection.getInputStream();
        } else {
          inputStream = urlConnection.getErrorStream();
        }


来源:https://stackoverflow.com/questions/12710865/the-api-package-remote-socket-or-call-resolve-was-not-found-gae-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!