首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >httpcomponents未按文档所述工作

httpcomponents未按文档所述工作
EN

Stack Overflow用户
提问于 2012-10-11 20:24:55
回答 1查看 2.4K关注 0票数 0

使用我在这里找到的代码:http://hc.apache.org/httpcomponents-client-ga/quickstart.html,我创建了一个快速的HTTP客户端应用程序。下面是一个代码片段:

代码语言:javascript
复制
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
log.info("Logging in");
HttpResponse response;
try {
  response = httpclient.execute(httpGet);
}
catch (ClientProtocolException cpe) {
  String msg = "Error logging in with:" + rootUrl;
  log.error(msg, cpe);
  throw new BusinessRuleException(msg, cpe);
}
catch (IOException ioe) {
  String msg = "Error logging in with:" + rootUrl;
  log.error(msg, ioe);
  throw new BusinessRuleException(msg, ioe);
}

try {
  System.out.println(response.getStatusLine());
  HttpEntity entity = response.getEntity();
  // do something useful with the response body
  // and ensure it is fully consumed
  EntityUtils.consume(entity);
}
catch (IOException ioe) {
  String msg = "Error retrieving login response:" + rootUrl;
  log.error(msg, ioe);
  throw new BusinessRuleException(msg, ioe);
}
finally {
  httpGet.releaseConnection();
}

我得到了这个例外:

代码语言:javascript
复制
java.lang.NoSuchMethodError: org.apache.http.client.methods.HttpGet.releaseConnection()V
    at com.xerox.tclg.juror.schedule.RestScheduleRunner.runDailyCheckout(RestScheduleRunner.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)

我发现一些文档说releaseConnection()不是必需的,所以我删除了finally块。然后我得到了这个异常:

代码语言:javascript
复制
java.lang.NoSuchMethodError: org.apache.http.util.EntityUtils.consume(Lorg/apache/http/HttpEntity;)V
    at com.xerox.tclg.juror.schedule.RestScheduleRunner.runDailyCheckout(RestScheduleRunner.java:85)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276)
    at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260)

有没有人看过这个?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-11 20:31:34

在这种情况下,java.lang.NoSuchMethodError很可能意味着您获得了其中一个Http组件JAR文件的错误版本。

如果你能找出"RestScheduleRunner.java:85“到底发生了什么,它可能会帮助你诊断这个问题。

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

https://stackoverflow.com/questions/12839473

复制
相关文章

相似问题

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