简体   繁体   English

ektorp couchdb IllegalStateException的内容已消耗

[英]ektorp couchdb IllegalStateException content consumed

Its been a while since i've worked with Java especially exceptions. 自从我使用Java特别是异常以来已经有一段时间了。 I'm in the process of adding ektorp couchdb intergration into something i'm working on. 我正在将ektorp couchdb集成添加到我正在研究的东西中。 However i'm encountering content consumed exceptions. 但是我遇到内容消耗异常。

The program in question uses twitter4j and i'm getting my statuses and writing them to a couchdb instance. 有问题的程序使用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);
}

At first i tried db.create(newTweetDoc) as well. 起初,我还尝试了db.create(newTweetDoc)。 Does the couchdbConnector need to be recreated every time i try this? 每次尝试此操作时是否都需要重新创建couchdbConnector吗?

db is a global CouchDbConnector: public CouchDbConnector db = null; db是全局CouchDbConnector:public CouchDbConnector db = null;

public CouchTwitter()
{
    //create the db connection etc
}

It's the db.create(doc) or flushBulkBuffer that results in the error. 导致错误的是db.create(doc)或flushBulkBuffer。 Here is the stacktrace: 这是堆栈跟踪:

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)

I see in the above that two seperate Entity classes both call .getContent(), i've been playing around with my referenced libraries recently is it possible that its calling an old apache Http lib as well as the current? 我在上面看到两个单独的Entity类都调用.getContent(),我最近一直在使用我引用的库,是否有可能调用旧的apache Http lib以及当前的apache?

CouchDbConnector is thread safe so you don't need recreate it for each operation. CouchDbConnector是线程安全的,因此您无需为每个操作重新创建它。

I have never encountered your problem, your use case is pretty simple and there should not be any problem saving a basic doc. 我从未遇到过您的问题,您的用例非常简单,保存基本文档应该没有任何问题。

Verify that httpclient-4.1.1 or above is in the classpath. 验证httpclient-4.1.1或更高版本是否在类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM