越来越奇怪的异常试图在谷歌应用程序引擎为Java实现异步HTTP [英] getting strange exception trying to implement asynchronous http in google app engine for java

查看:110
本文介绍了越来越奇怪的异常试图在谷歌应用程序引擎为Java实现异步HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在java中实现异步http。以下是代码中重要的
部分:

$ p $ for(String urlString:url)
{
// TODO:尝试去掉这两个堆分配
url = new URL(urlString);
request = new HTTPRequest(url);
request.addHeader(userAgentHeader);
request.addHeader(authorizationHeader);
request.addHeader(acceptEncodingHeader);
request.addHeader(acceptCharsetHeader);
responses.add(URLFetchServiceFactory.getURLFetchService()。fetchAsync(reques t));
apiCallsMade ++; (未来< HTTPResponse> futureResponse:响应)
}

parseResponse(new String(futureResponse.get()。getContent()));
}

我一直收到这个错误:


com.google.apphosting.api.ApiProxy $ CallNotFoundException:未找到API包'urlfetch'或调用'Fetch()'


我环顾四周缺少
类路径的任何jar,但没有看到任何缺失。你知道代码在哪个jar
吗?我搜索了这个错误,并搜索了这个
组,但什么也没找到。
Thanks,
David

解决方案

使用Google appengine,您无法在本地Java应用程序中使用这些api 。这只适用于使用google appengine sdk开发和部署Web应用程序的情况。这只是为了这样工作。



当你使用这个api时,它会利用http客户端,并且在应用引擎环境的情况下,它将利用谷歌基础设施如果你仍然想单元测试为google appengine设计的应用程序,你可以考虑使用LocalURLServiceFactory。


I'm trying to implement async http in java. Here is the important part of the code:

for (String urlString : urls) 
{ 
    // TODO: try and get rid of these two heap allocations 
    url = new URL(urlString); 
    request = new HTTPRequest(url); 
    request.addHeader(userAgentHeader); 
    request.addHeader(authorizationHeader); 
    request.addHeader(acceptEncodingHeader); 
    request.addHeader(acceptCharsetHeader); 
    responses.add(URLFetchServiceFactory.getURLFetchService().fetchAsync(reques t)); 
    apiCallsMade++; 
} 
for (Future<HTTPResponse> futureResponse : responses) 
{ 
    parseResponse(new String(futureResponse.get().getContent())); 
} 

I keep getting this error:

com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'urlfetch' or call 'Fetch()' was not found.

I looked around for any jars that were missing from the classpath but didn't see anything missing. Do you know which jar that code is in? I googled the error and also searched through this group but found nothing. Thanks, David

解决方案

With Google appengine, you cannot use those api's in the local java applications. This will work only when you develop and deploy web application using google appengine sdk. This is designed to work this way only.

When you use this api, it will make use of http client and in case of app engine environment, it will make use of google infrastructure. If you still want to unit test the application designed for google appengine you might consider using LocalURLServiceFactory.

这篇关于越来越奇怪的异常试图在谷歌应用程序引擎为Java实现异步HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆