Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
tspannhw authored Apr 28, 2020
1 parent b2a9083 commit 273da4f
Showing 1 changed file with 46 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<JsonNode> 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<JsonNode> 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();
}
Expand Down

0 comments on commit 273da4f

Please sign in to comment.