【发布时间】:2014-07-19 01:11:50
【问题描述】:
即使我没有使用 Base64,也会发生这种情况。
我确实在 Glassfish 中我的域的 lib 目录中引用了 commons-codec-1.9,并且在 httpclient-4.3.4 和 lib 目录中也引用了导致错误的代码。
try {
Authenticator.setDefault(new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("myusername", "mypassword".toCharArray());
}
});
String xmlRequestString = formatXMLRequest((Exception) exception);
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost("http://mysite.org/post.xml");
StringEntity entity = new StringEntity(xmlRequestString);
entity.setContentType("text/xml");
post.setEntity(entity);
client.execute(post); // <--- HERE is where the error is thrown
} catch (Exception ex) {
Logger.getLogger(LogManagerBean.class.getName()).log(Level.SEVERE, null, ex);
}
有什么想法吗?
【问题讨论】:
-
当您在构建路径中使用第三方 jar 的一个版本编译代码,并在库路径中使用该 jar 的不同版本运行代码时,通常会发生此错误。
-
是的,我想到了。我非常小心地确保它不是。我从 Glassfish 中取消部署我的耳朵,停止 glassfish,摆脱旧版本,将新版本放在 lib 目录中,删除所有缓存,重新启动 glassfish,并在构建完所有内容后重新部署。还是被难住了。
-
但是您在构建路径中使用的是相同版本的 jar 吗?
-
没有。我正在使用 Maven,我的命令行路径中没有任何特定的库。 Maven 声明构建版本。 Glassfish 域库具有运行版本。它们是一样的。
标签: java post glassfish httpclient apache-commons