You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sm...@apache.org on 2018/07/05 23:42:13 UTC

directory-fortress-core git commit: FC-234 - Close the connection in http get

Repository: directory-fortress-core
Updated Branches:
  refs/heads/master 4c1053b31 -> 5aa751751


FC-234 - Close the connection in http get


Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/5aa75175
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/5aa75175
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/5aa75175

Branch: refs/heads/master
Commit: 5aa75175133fe54ef4566ac009a6462f39e7eab6
Parents: 4c1053b
Author: Shawn McKinney <sm...@apache.org>
Authored: Thu Jul 5 07:43:23 2018 -0500
Committer: Shawn McKinney <sm...@apache.org>
Committed: Thu Jul 5 07:43:23 2018 -0500

----------------------------------------------------------------------
 .../directory/fortress/core/rest/RestUtils.java | 36 +++++++++++++++++---
 1 file changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/5aa75175/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java b/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
index 06f532e..beb471f 100644
--- a/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
+++ b/src/main/java/org/apache/directory/fortress/core/rest/RestUtils.java
@@ -131,10 +131,12 @@ public final class RestUtils
         fortressRestVersion = System.getProperty( "version" );
         serviceName = "fortress-rest-" + fortressRestVersion;
         uri = httpProtocol + "://" + httpHost + ":" + httpPort + "/" + serviceName + "/";
+        LOG.info("HTTP Connect Properties: host:{}, port:{}, protocol:{}, version:{}, service:{}, uri:{}", httpHost, httpPort, httpProtocol, fortressRestVersion, serviceName, uri);
         LOG.info( "Set JSSE truststore properties:" );
         LOG.info( "javax.net.ssl.trustStore: {}", trustStore );
         System.setProperty( "javax.net.ssl.trustStore", trustStore );
         System.setProperty( "javax.net.ssl.trustStorePassword", trustStorePw );
+        System.setProperty( "http.maxConnections", "50" );
     }
 
     private RestUtils(){
@@ -228,10 +230,36 @@ public final class RestUtils
             url += "/" + id3;
         }
         LOG.debug( "get function1:{}, id1:{}, id2:{}, id3:{}, url:{}", function, id, id2, id3, url );
-        HttpGet get = new HttpGet(url);
-        setMethodHeaders( get );
-        return handleHttpMethod( get ,HttpClientBuilder.create().useSystemProperties()
-            .setDefaultCredentialsProvider(getCredentialProvider(userId, password)).build() );
+
+        String szResponse;
+        HttpGet get = null;
+        try
+        {
+            get = new HttpGet(url);
+            setMethodHeaders( get );
+            szResponse = handleHttpMethod( get ,HttpClientBuilder.create().useSystemProperties()
+                .setDefaultCredentialsProvider(getCredentialProvider(userId, password)).build() );
+        }
+        catch ( WebApplicationException we )
+        {
+            String error = generateErrorMessage( uri,function, "caught WebApplicationException=" + we.getMessage() );
+            LOG.error( error, we);
+            throw new RestException( GlobalErrIds.REST_WEB_ERR, error, we );
+        }
+        catch ( java.lang.NoSuchMethodError e )
+        {
+            String error = generateErrorMessage( uri, function, "caught NoSuchMethodError = "+ e.getMessage() );
+            LOG.error( error, e );
+            throw new RestException( GlobalErrIds.REST_UNKNOWN_ERR, error);
+        }
+        finally
+        {
+            // Release current connection to the connection pool.
+            if ( get != null )
+                get.releaseConnection();
+        }
+
+        return szResponse;
     }