mirror of https://github.com/apache/nifi.git
NIFI-310: Fixed NPE
This commit is contained in:
parent
be16371b20
commit
102e3cb093
|
@ -68,6 +68,7 @@ import org.apache.http.conn.HttpClientConnectionManager;
|
||||||
import org.apache.http.conn.ManagedHttpClientConnection;
|
import org.apache.http.conn.ManagedHttpClientConnection;
|
||||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||||
|
import org.apache.http.conn.ssl.SSLContextBuilder;
|
||||||
import org.apache.http.conn.ssl.SSLContexts;
|
import org.apache.http.conn.ssl.SSLContexts;
|
||||||
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||||
import org.apache.http.entity.ContentProducer;
|
import org.apache.http.entity.ContentProducer;
|
||||||
|
@ -352,21 +353,26 @@ public class PostHTTP extends AbstractProcessor {
|
||||||
private SSLContext createSSLContext(final SSLContextService service) throws KeyStoreException, IOException, NoSuchAlgorithmException,
|
private SSLContext createSSLContext(final SSLContextService service) throws KeyStoreException, IOException, NoSuchAlgorithmException,
|
||||||
CertificateException, KeyManagementException, UnrecoverableKeyException
|
CertificateException, KeyManagementException, UnrecoverableKeyException
|
||||||
{
|
{
|
||||||
|
SSLContextBuilder builder = SSLContexts.custom();
|
||||||
|
final String trustFilename = service.getTrustStoreFile();
|
||||||
|
if ( trustFilename != null ) {
|
||||||
final KeyStore truststore = KeyStore.getInstance(service.getTrustStoreType());
|
final KeyStore truststore = KeyStore.getInstance(service.getTrustStoreType());
|
||||||
try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) {
|
try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) {
|
||||||
truststore.load(in, service.getTrustStorePassword().toCharArray());
|
truststore.load(in, service.getTrustStorePassword().toCharArray());
|
||||||
}
|
}
|
||||||
|
builder = builder.loadTrustMaterial(truststore, new TrustSelfSignedStrategy());
|
||||||
|
}
|
||||||
|
|
||||||
|
final String keyFilename = service.getKeyStoreFile();
|
||||||
|
if ( keyFilename != null ) {
|
||||||
final KeyStore keystore = KeyStore.getInstance(service.getKeyStoreType());
|
final KeyStore keystore = KeyStore.getInstance(service.getKeyStoreType());
|
||||||
try (final InputStream in = new FileInputStream(new File(service.getKeyStoreFile()))) {
|
try (final InputStream in = new FileInputStream(new File(service.getKeyStoreFile()))) {
|
||||||
keystore.load(in, service.getKeyStorePassword().toCharArray());
|
keystore.load(in, service.getKeyStorePassword().toCharArray());
|
||||||
}
|
}
|
||||||
|
builder = builder.loadKeyMaterial(keystore, service.getKeyStorePassword().toCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
SSLContext sslContext = SSLContexts.custom()
|
SSLContext sslContext = builder.build();
|
||||||
.loadTrustMaterial(truststore, new TrustSelfSignedStrategy())
|
|
||||||
.loadKeyMaterial(keystore, service.getKeyStorePassword().toCharArray())
|
|
||||||
.build();
|
|
||||||
|
|
||||||
return sslContext;
|
return sslContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue