NIFI-300, NIFI-298: Fixed bugs causing failures when sending to non-https addresses and sending as flowfile

This commit is contained in:
Mark Payne 2015-01-23 12:00:21 -05:00
parent 8b3f3c75cd
commit c8ecdd9ddf
1 changed files with 22 additions and 12 deletions

View File

@ -319,21 +319,27 @@ public class PostHTTP extends AbstractProcessor {
return config; return config;
} }
final PoolingHttpClientConnectionManager conMan;
final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class); final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
final SSLContext sslContext; if ( sslContextService == null ) {
try { conMan = new PoolingHttpClientConnectionManager();
sslContext = createSSLContext(sslContextService); } else {
} catch (final Exception e) { final SSLContext sslContext;
throw new ProcessException(e); try {
sslContext = createSSLContext(sslContextService);
} catch (final Exception e) {
throw new ProcessException(e);
}
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslsf).build();
conMan = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
} }
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null,
SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", sslsf).build();
final PoolingHttpClientConnectionManager conMan = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
conMan.setDefaultMaxPerRoute(context.getMaxConcurrentTasks()); conMan.setDefaultMaxPerRoute(context.getMaxConcurrentTasks());
conMan.setMaxTotal(context.getMaxConcurrentTasks()); conMan.setMaxTotal(context.getMaxConcurrentTasks());
config = new Config(conMan); config = new Config(conMan);
@ -428,6 +434,10 @@ public class PostHTTP extends AbstractProcessor {
public void process(final HttpResponse response, final HttpContext httpContext) throws HttpException, IOException { public void process(final HttpResponse response, final HttpContext httpContext) throws HttpException, IOException {
HttpCoreContext coreContext = HttpCoreContext.adapt(httpContext); HttpCoreContext coreContext = HttpCoreContext.adapt(httpContext);
ManagedHttpClientConnection conn = coreContext.getConnection(ManagedHttpClientConnection.class); ManagedHttpClientConnection conn = coreContext.getConnection(ManagedHttpClientConnection.class);
if ( !conn.isOpen() ) {
return;
}
SSLSession sslSession = conn.getSSLSession(); SSLSession sslSession = conn.getSSLSession();
if ( sslSession != null ) { if ( sslSession != null ) {