自从我使用 Java 特别是异常以来已经有一段时间了。我正在将 ektorp couchdb 集成添加到我正在做的事情中。但是我遇到了内容消耗异常。
有问题的程序使用 twitter4j,我正在获取我的状态并将它们写入 couchdb 实例。
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;
public CouchTwitter()
{
//create the db connection etc
}
导致错误的是 db.create(doc) 或 flushBulkBuffer。这是堆栈跟踪:
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 库以及当前的库吗?