java 在JRE 1.7.4+中扩展SocketChannel

x6yk4ghg  于 12个月前  发布在  Java
关注(0)|答案(1)|浏览(103)

我刚刚尝试扩展SocketChannel,但似乎SocketChannel从JRE 1.7.4(SocketChannel)开始有一些新的API方法可用。

Exception in thread "Thread-24" java.lang.NoClassDefFoundError: java/nio/channels/NetworkChannel

字符串
现在我明白了为什么会有一个与java/nio/channels/NetworkChannel相关的错误,看起来SocketChannel在JRE 1.7上实现了接口NetworkChannel
现在,当我使用JRE 1.7.4+时,会出现一些运行时错误。实际上奇怪的是,即使我实现了这些新的API方法,当我调用unwrap方法时,也会出现运行时错误:

Exception in thread "Thread-27" java.lang.RuntimeException: Delegated task threw Exception/Error
    at sun.security.ssl.Handshaker.checkThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.checkTaskThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.readNetRecord(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.unwrap(Unknown Source)
    at javax.net.ssl.SSLEngine.unwrap(Unknown Source)
    at CustomSocketChannel.unwrap(CustomSocketChannel.java:565)


在这一行,我只调用sslEngine.unwrap方法。
我如何使我的SocketChannel与JRE 1.6和1.7兼容,同时扩展SocketChannel类?

idfiyjo8

idfiyjo81#

好的,看起来我已经找到了JRE 1.7.4+上运行时错误的问题。看起来它并不是真正的解包错误,而是证书错误。同样,当我调用SSLEngine.unwrap时,每当我得到运行时错误时,我都会得到以下错误:

Exception in thread "Thread-24" java.lang.RuntimeException: Delegated task threw Exception/Error
    at sun.security.ssl.Handshaker.checkThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.checkTaskThrown(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.readNetRecord(Unknown Source)
    at sun.security.ssl.SSLEngineImpl.unwrap(Unknown Source)
    at javax.net.ssl.SSLEngine.unwrap(Unknown Source)
    .....
Caused by: java.lang.UnsupportedOperationException
    at ....RTMPSTrustManager.getAcceptedIssuers(....)

字符串
愚蠢的我,我应该注意到“由”短语引起,因为我下面有这个代码,所以似乎从JRE 1.7.4开始。如果我在getAcceptedIssuers()内部抛出异常,那么我就会有这个问题,所以我最终没有抛出异常,而是返回null
我不确定1.7.4+版本的问题是否与此修复(JDK-7142172)有关,但似乎确实如此。

public java.security.cert.X509Certificate[] getAcceptedIssuers()
{
    return null;
    //throw new UnsupportedOperationException();
}

相关问题