我正在使用 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
我尝试了帖子中建议的解决方案,但仍然遇到相同的错误。关于如何通过这个问题的任何想法?
PS 我不能使用 Apache HttpClient 或 RestEasy(Jboss) 因为项目中使用了另一个不支持 Apache HttpClient 的 3PP