【发布时间】:2017-11-06 11:21:25
【问题描述】:
我正在使用 java.net 编写一个应该执行 PATCH 请求的休息客户端。但是由于 PATCH 在 java.net 中不是受支持的方法,所以我使用反射来通过更改代码来支持它,例如
private void updateConnectionToSupportPatchRequest(final HttpURLConnection conn)
throws ReflectiveOperationException {
try {
final Object targetConn;
if (conn instanceof HttpsURLConnectionImpl) {
final Field delegateField = HttpsURLConnectionImpl.class.getDeclaredField("delegate");
delegateField.setAccessible(true);
targetConn = delegateField.get(conn);
} else {
targetConn = conn;
}
final Field methodField = HttpURLConnection.class.getDeclaredField("method");
methodField.setAccessible(true);
methodField.set(targetConn, "PATCH");
} catch (final NoSuchFieldException ex) {
LOGGER.error("NoSuchFieldException: {} ", ex.getMessage());
}
}
但是当我在 JBoss 中部署使用我的 rest 客户端的应用程序时,我收到了这个错误 -
java.lang.NoClassDefFoundError: sun/net/www/protocol/https/HttpsURLConnectionImpl
我查看了这个错误并发现了这个帖子http://planet.jboss.org/post/dealing_with_sun_jdk_related_noclassdeffounderror_under_jboss
我尝试了帖子中建议的解决方案,但仍然遇到相同的错误。有关如何通过此问题的任何想法?
附:我不能使用 Apache HttpClient 或 RestEasy(Jboss),因为项目中使用了另一个 3PP,它不支持 Apache HttpClient
【问题讨论】:
标签: java jboss http-patch