From 273da4f9e57cb5376f3612b7b691ec61bf07689b Mon Sep 17 00:00:00 2001 From: Timothy Spann <18673814+tspannhw@users.noreply.github.com> Date: Tue, 28 Apr 2020 16:49:38 -0400 Subject: [PATCH] Add files via upload --- .../ExecuteClouderaML/HTTPPostUtility.java | 77 +++++++++++-------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/nifi-ExecuteClouderaML-processors/src/main/java/dev/datainmotion/processors/ExecuteClouderaML/HTTPPostUtility.java b/nifi-ExecuteClouderaML-processors/src/main/java/dev/datainmotion/processors/ExecuteClouderaML/HTTPPostUtility.java index f01d56a..11805b1 100644 --- a/nifi-ExecuteClouderaML-processors/src/main/java/dev/datainmotion/processors/ExecuteClouderaML/HTTPPostUtility.java +++ b/nifi-ExecuteClouderaML-processors/src/main/java/dev/datainmotion/processors/ExecuteClouderaML/HTTPPostUtility.java @@ -28,42 +28,57 @@ public static HTTPPostResults postToCML(String urlName, String accessKey, String } HTTPPostResults results = new HTTPPostResults(); + UnirestInstance unirest = Unirest.spawnInstance(); - Unirest.config().reset(); - Unirest.config() - .socketTimeout( 90000 ) - .connectTimeout( 180000 ) - .concurrency( 10, 5 ) - .setDefaultHeader( "Accept", "application/json" ) - .followRedirects( true ) - .verifySsl(false) - .enableCookieManagement( true ); - - CMLPost cmlPost = new CMLPost(); - cmlPost.setAccessKey( accessKey ); - cmlPost.setRequest( request ); - - HttpResponse resp = Unirest.post( urlName ) - .header( "accept", "application/json" ) - .header("Content-Type", "application/json") - .body(cmlPost.getAsJSON()) - .asJson(); - - if (resp.getBody() != null ) { - results.setJsonResultBody(resp.getBody().toPrettyString()); + if ( unirest == null) { + unirest = Unirest.primaryInstance(); } - - if ( resp.getHeaders() != null) { - results.setHeader( resp.getHeaders().toString() ); - } - if ( resp.getStatusText() != null ) { - results.setStatus(resp.getStatusText()); + if (unirest == null) + { + return results; } - results.setStatusCode(resp.getStatus()); + try { + unirest.config() + .socketTimeout( 90000 ) + .connectTimeout( 180000 ) + .concurrency( 2, 2 ) + .setDefaultHeader( "Accept", "application/json" ) + .followRedirects( true ) + .verifySsl(false) + .enableCookieManagement( true ); + +// CMLPost cmlPost = new CMLPost(); +// cmlPost.setAccessKey( accessKey ); +// cmlPost.setRequest( request ); + + // .body(cmlPost.getAsJSON()) + HttpResponse resp = unirest.post( urlName ) + .header( "accept", "application/json" ) + .header("Content-Type", "application/json") + .body("{\"accessKey\":\"" + accessKey + "\",\"request\":{" + request + "}}") + .asJson(); + + if (resp.getBody() != null ) { + results.setJsonResultBody(resp.getBody().toPrettyString()); + } + + if ( resp.getHeaders() != null) { + results.setHeader( resp.getHeaders().toString() ); + } + if ( resp.getStatusText() != null ) { + results.setStatus(resp.getStatusText()); + } + + results.setStatusCode(resp.getStatus()); + } catch (Exception e) { + e.printStackTrace(); + } - try { - Unirest.shutDown(); + try { + unirest.close(); + unirest.shutDown(); + unirest = null; } catch (Exception e) { e.printStackTrace(); }