首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用的ektorp couchdb IllegalStateException内容

使用的ektorp couchdb IllegalStateException内容
EN

Stack Overflow用户
提问于 2012-03-23 06:41:50
回答 1查看 306关注 0票数 0

我已经有一段时间没有使用Java了,尤其是异常。我正在将ektorp couchdb集成添加到我正在开发的项目中。然而,我遇到了内容消费异常。

这个程序使用twitter4j,我正在获取状态并将它们写入到couchdb实例中。

代码语言:javascript
复制
public void putTweet(Status status)
{
    Map<String, Object> newTweetDoc = new HashMap<String, Object>();
    String docname = status.getUser().getName() + " "
            + status.getCreatedAt().toString();
    newTweetDoc.put("_id", docname);
    newTweetDoc.put("User", status.getUser().getName());
    newTweetDoc.put("Contents", status.getText());
    newTweetDoc.put("Created", status.getCreatedAt().toString());
    newTweetDoc.put("RetweetCount", status.getRetweetCount());
    UserMentionEntity[] mentions = status.getUserMentionEntities();
    Map<String, HashMap<String, String>> formattedMentions = formatMentions(mentions);
    newTweetDoc.put("Mentions", formattedMentions);
    db.addToBulkBuffer(newTweetDoc);
}

起初,我也尝试了db.create(newTweetDoc)。每次尝试时都需要重新创建couchdbConnector吗?

db为全局CouchDbConnector: public CouchDbConnector db = null;

代码语言:javascript
复制
public CouchTwitter()
{
    //create the db connection etc
}

导致错误的是db.create(文档)或flushBulkBuffer。下面是堆栈跟踪:

代码语言:javascript
复制
Exception in thread "main" java.lang.IllegalStateException: Content has been consumed
at org.apache.http.entity.BasicHttpEntity.getContent(BasicHttpEntity.java:84)
at org.apache.http.conn.BasicManagedEntity.getContent(BasicManagedEntity.java:88)
at org.ektorp.http.StdHttpResponse.releaseConnection(StdHttpResponse.java:82)
at org.ektorp.http.RestTemplate.handleResponse(RestTemplate.java:111)
at org.ektorp.http.RestTemplate.post(RestTemplate.java:66)
at org.ektorp.impl.StdCouchDbConnector.executeBulk(StdCouchDbConnector.java:638)
at org.ektorp.impl.StdCouchDbConnector.executeBulk(StdCouchDbConnector.java:596)
at org.ektorp.impl.StdCouchDbConnector.flushBulkBuffer(StdCouchDbConnector.java:617)

我在上面看到了两个独立的实体类都调用了.getContent(),我最近一直在玩弄我的被引用的库,有没有可能它调用了一个旧的apache Http库以及当前的?

EN

回答 1

Stack Overflow用户

发布于 2012-03-23 16:35:07

CouchDbConnector是线程安全的,所以你不需要为每个操作重新创建它。

我从来没有遇到过你的问题,你的用例非常简单,保存一个基本的文档应该不会有任何问题。

验证httpclient-4.1.1或更高版本是否在类路径中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9831628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档