ARTEMIS-3433 - allow null return and throw error only startup usage paths

This commit is contained in:
gtully 2021-10-20 15:00:57 +01:00 committed by Gary Tully
parent 6bd76386f1
commit 925ceadffa
3 changed files with 12 additions and 6 deletions

View File

@ -115,6 +115,7 @@ import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ssl.OpenSSLContextFactory;
import org.apache.activemq.artemis.spi.core.remoting.ssl.OpenSSLContextFactoryProvider;
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig;
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextFactoryProvider;
@ -760,8 +761,11 @@ public class NettyConnector extends AbstractConnector {
}
private SSLEngine loadOpenSslEngine(final ByteBufAllocator alloc, final SSLContextConfig sslContextConfig) throws Exception {
final SslContext context = OpenSSLContextFactoryProvider.getOpenSSLContextFactory()
.getClientSslContext(sslContextConfig, configuration);
final OpenSSLContextFactory factory = OpenSSLContextFactoryProvider.getOpenSSLContextFactory();
if (factory == null) {
throw new IllegalStateException("No OpenSSLContextFactory registered!");
}
final SslContext context = factory.getClientSslContext(sslContextConfig, configuration);
if (host != null && port != -1) {
return context.newEngine(alloc, host, port);

View File

@ -31,9 +31,6 @@ public class OpenSSLContextFactoryProvider {
}
}
if (factoryWithHighestPrio == null)
throw new IllegalStateException("No OpenSSLContextFactory registered!");
FACTORY = factoryWithHighestPrio;
}

View File

@ -89,6 +89,7 @@ import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager;
import org.apache.activemq.artemis.spi.core.remoting.BufferHandler;
import org.apache.activemq.artemis.spi.core.remoting.Connection;
import org.apache.activemq.artemis.spi.core.remoting.ServerConnectionLifeCycleListener;
import org.apache.activemq.artemis.spi.core.remoting.ssl.OpenSSLContextFactory;
import org.apache.activemq.artemis.spi.core.remoting.ssl.OpenSSLContextFactoryProvider;
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig;
import org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextFactoryProvider;
@ -381,7 +382,11 @@ public class NettyAcceptor extends AbstractAcceptor {
checkSSLConfiguration();
try {
if (TransportConstants.OPENSSL_PROVIDER.equals(sslProvider)) {
return OpenSSLContextFactoryProvider.getOpenSSLContextFactory().getServerSslContext(sslContextConfig, configuration);
OpenSSLContextFactory factory = OpenSSLContextFactoryProvider.getOpenSSLContextFactory();
if (factory != null) {
return factory.getServerSslContext(sslContextConfig, configuration);
}
throw new IllegalStateException("No OpenSSLContextFactory registered!");
} else {
return SSLContextFactoryProvider.getSSLContextFactory().getSSLContext(sslContextConfig, configuration);
}