This is an automated email from the ASF dual-hosted git repository.

vavrtom pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-broker-j.git


The following commit(s) were added to refs/heads/main by this push:
     new f7b3ca9a85 QPID-8686: [Broker-J] Upgrade Apache httpclient to version 
5.x (#286)
f7b3ca9a85 is described below

commit f7b3ca9a85d7f45d2e78e5b859433b9cd0f4f55e
Author: Daniil Kirilyuk <daniel.kiril...@gmail.com>
AuthorDate: Thu Jun 5 15:53:33 2025 +0200

    QPID-8686: [Broker-J] Upgrade Apache httpclient to version 5.x (#286)
---
 joramtests/pom.xml                                 |  8 +-
 .../qpid/joramtests/admin/JavaBrokerAdmin.java     | 93 ++++++++++------------
 perftests/pom.xml                                  |  4 +-
 .../dependency-verification/DEPENDENCIES_REFERENCE | 18 ++---
 .../qpid/disttest/jms/QpidRestAPIQueueCreator.java | 68 ++++++++--------
 pom.xml                                            | 11 ++-
 tck/pom.xml                                        |  4 +-
 .../apache/qpid/tck/ManageQpidJMSResources.java    | 53 ++++++------
 8 files changed, 126 insertions(+), 133 deletions(-)

diff --git a/joramtests/pom.xml b/joramtests/pom.xml
index 4d87952a1e..2322f33fe6 100644
--- a/joramtests/pom.xml
+++ b/joramtests/pom.xml
@@ -63,8 +63,12 @@
             <version>${joram-jms-tests-version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient</artifactId>
+            <groupId>org.apache.httpcomponents.client5</groupId>
+            <artifactId>httpclient5</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents.client5</groupId>
+            <artifactId>httpclient5-fluent</artifactId>
         </dependency>
 
     </dependencies>
diff --git 
a/joramtests/src/main/java/org/apache/qpid/joramtests/admin/JavaBrokerAdmin.java
 
b/joramtests/src/main/java/org/apache/qpid/joramtests/admin/JavaBrokerAdmin.java
index 28a82b3c1d..167d6d8175 100644
--- 
a/joramtests/src/main/java/org/apache/qpid/joramtests/admin/JavaBrokerAdmin.java
+++ 
b/joramtests/src/main/java/org/apache/qpid/joramtests/admin/JavaBrokerAdmin.java
@@ -22,7 +22,7 @@
 package org.apache.qpid.joramtests.admin;
 
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
+import java.net.URISyntaxException;
 import java.util.Hashtable;
 
 import javax.jms.ConnectionFactory;
@@ -34,21 +34,23 @@ import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.CredentialsProvider;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.auth.BasicScheme;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ClassicHttpRequest;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.client5.http.classic.methods.HttpDelete;
+import org.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.objectweb.jtests.jms.admin.Admin;
 
 public class JavaBrokerAdmin implements Admin
@@ -64,7 +66,7 @@ public class JavaBrokerAdmin implements Admin
     private final String _queueApiUrl;
     private final String _topicApiUrl;
 
-    public JavaBrokerAdmin() throws NamingException
+    public JavaBrokerAdmin() throws NamingException, URISyntaxException
     {
         final Hashtable<String, String> env = new Hashtable<>();
         _context = new InitialContext(env);
@@ -91,7 +93,7 @@ public class JavaBrokerAdmin implements Admin
     }
 
     @Override
-    public Context createContext() throws NamingException
+    public Context createContext()
     {
         return _context;
     }
@@ -113,7 +115,6 @@ public class JavaBrokerAdmin implements Admin
     public void createTopicConnectionFactory(final String name)
     {
         checkObjectExistsInContext(name, TopicConnectionFactory.class);
-
     }
 
     @Override
@@ -121,7 +122,6 @@ public class JavaBrokerAdmin implements Admin
     {
         checkObjectExistsInContext(name, Queue.class);
         managementCreateQueue(name);
-
     }
 
     @Override
@@ -162,25 +162,25 @@ public class JavaBrokerAdmin implements Admin
     }
 
     @Override
-    public void startServer() throws Exception
+    public void startServer()
     {
 
     }
 
     @Override
-    public void stopServer() throws Exception
+    public void stopServer()
     {
 
     }
 
     @Override
-    public void start() throws Exception
+    public void start()
     {
 
     }
 
     @Override
-    public void stop() throws Exception
+    public void stop()
     {
 
     }
@@ -207,53 +207,44 @@ public class JavaBrokerAdmin implements Admin
 
     private void managementCreateQueue(final String name)
     {
-        HttpPut put = new HttpPut(String.format(_queueApiUrl, 
_virtualhostnode, _virtualhost, name));
-
-        StringEntity input = new StringEntity("{}", StandardCharsets.UTF_8);
-        input.setContentType("application/json");
+        final HttpPut put = new HttpPut(String.format(_queueApiUrl, 
_virtualhostnode, _virtualhost, name));
+        final StringEntity input = new StringEntity("{}", 
ContentType.APPLICATION_JSON, "UTF_8", false);
         put.setEntity(input);
-
         executeManagement(put);
     }
 
     private void managementCreateTopic(final String name)
     {
-        HttpPut put = new HttpPut(String.format(_topicApiUrl, 
_virtualhostnode, _virtualhost, name));
-
-        StringEntity input = new StringEntity("{\"type\" : \"fanout\"}", 
StandardCharsets.UTF_8);
-        input.setContentType("application/json");
-
+        final HttpPut put = new HttpPut(String.format(_topicApiUrl, 
_virtualhostnode, _virtualhost, name));
+        final StringEntity input = new StringEntity("{\"type\" : \"fanout\"}", 
ContentType.APPLICATION_JSON, "UTF_8", false);
         put.setEntity(input);
-
         executeManagement(put);
     }
 
     private void managementDeleteQueue(final String name)
     {
-        HttpDelete delete = new HttpDelete(String.format(_queueApiUrl, 
_virtualhostnode, _virtualhost, name));
+        final HttpDelete delete = new HttpDelete(String.format(_queueApiUrl, 
_virtualhostnode, _virtualhost, name));
         executeManagement(delete);
     }
 
     private void managementDeleteTopic(final String name)
     {
-        HttpDelete delete = new HttpDelete(String.format(_topicApiUrl, 
_virtualhostnode, _virtualhost, name));
+        final HttpDelete delete = new HttpDelete(String.format(_topicApiUrl, 
_virtualhostnode, _virtualhost, name));
         executeManagement(delete);
     }
 
-    private void executeManagement(final HttpRequest httpRequest)
+    private void executeManagement(final ClassicHttpRequest httpRequest)
     {
-        try(CloseableHttpClient httpClient = 
HttpClients.custom().setDefaultCredentialsProvider(_credentialsProvider).build())
+        try (final CloseableHttpClient httpClient = 
HttpClients.custom().setDefaultCredentialsProvider(_credentialsProvider).build();
+             final CloseableHttpResponse response = 
httpClient.execute(_management, httpRequest, _httpClientContext))
         {
-            try (CloseableHttpResponse response = 
httpClient.execute(_management, httpRequest, _httpClientContext))
+            final int status = response.getCode();
+            final ProtocolVersion version = response.getVersion();
+            final String reason = response.getReasonPhrase();
+            if (status != 200 && status != 201)
             {
-
-                int statusCode = response.getStatusLine().getStatusCode();
-                if (statusCode != 200 && statusCode != 201)
-                {
-                    throw new RuntimeException(String.format("Failed : HTTP 
error code : %d  status line : %s",
-                                                             statusCode,
-                                                             
response.getStatusLine()));
-                }
+                final String msg = String.format("Failed: HTTP error code: %d, 
Version: %s, Reason: %s", status, version, reason);
+                throw new RuntimeException(msg);
             }
         }
         catch (IOException e)
@@ -266,15 +257,15 @@ public class JavaBrokerAdmin implements Admin
     {
         final BasicAuthCache authCache = new BasicAuthCache();
         authCache.put(management, new BasicScheme());
-        HttpClientContext localContext = HttpClientContext.create();
+        final HttpClientContext localContext = HttpClientContext.create();
         localContext.setAuthCache(authCache);
         return localContext;
     }
 
     private CredentialsProvider getCredentialsProvider(final String 
managementUser, final String managementPassword)
     {
-        final CredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
-        credentialsProvider.setCredentials(AuthScope.ANY, new 
UsernamePasswordCredentials(managementUser, managementPassword));
+        final BasicCredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
+        credentialsProvider.setCredentials(new AuthScope("localhost", 8080), 
new UsernamePasswordCredentials(managementUser, 
managementPassword.toCharArray()));
         return credentialsProvider;
     }
 }
diff --git a/perftests/pom.xml b/perftests/pom.xml
index d5a412dd7e..cb1da8a5ae 100644
--- a/perftests/pom.xml
+++ b/perftests/pom.xml
@@ -94,8 +94,8 @@
     </dependency>
 
     <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpclient</artifactId>
+      <groupId>org.apache.httpcomponents.client5</groupId>
+      <artifactId>httpclient5</artifactId>
     </dependency>
 
     <dependency>
diff --git 
a/perftests/src/main/assembly/dependency-verification/DEPENDENCIES_REFERENCE 
b/perftests/src/main/assembly/dependency-verification/DEPENDENCIES_REFERENCE
index 135e208a22..716c6e1e7d 100644
--- a/perftests/src/main/assembly/dependency-verification/DEPENDENCIES_REFERENCE
+++ b/perftests/src/main/assembly/dependency-verification/DEPENDENCIES_REFERENCE
@@ -80,21 +80,15 @@ From: 'QOS.ch' (http://www.qos.ch)
     License: MIT License  (http://www.opensource.org/licenses/mit-license.php)
 
 
-From: 'The Apache Software Foundation' (http://www.apache.org/)
-
-  - Apache Commons Logging (http://commons.apache.org/proper/commons-logging/) 
commons-logging:commons-logging:jar:1.2
-    License: The Apache Software License, Version 2.0  
(http://www.apache.org/licenses/LICENSE-2.0.txt)
-
-  - Apache HttpClient (http://hc.apache.org/httpcomponents-client) 
org.apache.httpcomponents:httpclient:jar:4.5.13
-    License: Apache License, Version 2.0  
(http://www.apache.org/licenses/LICENSE-2.0.txt)
-
-  - Apache HttpCore (http://hc.apache.org/httpcomponents-core-ga) 
org.apache.httpcomponents:httpcore:jar:4.4.13
-    License: Apache License, Version 2.0  
(http://www.apache.org/licenses/LICENSE-2.0.txt)
+From: 'The Apache Software Foundation' (https://www.apache.org/)
 
+  - Apache HttpClient 
(https://hc.apache.org/httpcomponents-client-5.4.x/5.4.4/httpclient5/) 
org.apache.httpcomponents.client5:httpclient5:jar:5.4.4
+    License: Apache License, Version 2.0  
(https://www.apache.org/licenses/LICENSE-2.0.txt)
 
-From: 'The Apache Software Foundation' (https://www.apache.org/)
+  - Apache HttpComponents Core HTTP/1.1 
(https://hc.apache.org/httpcomponents-core-5.3.x/5.3.4/httpcore5/) 
org.apache.httpcomponents.core5:httpcore5:jar:5.3.4
+    License: Apache License, Version 2.0  
(https://www.apache.org/licenses/LICENSE-2.0.txt)
 
-  - Apache Commons Codec (http://commons.apache.org/proper/commons-codec/) 
commons-codec:commons-codec:jar:1.11
+  - Apache HttpComponents Core HTTP/2 
(https://hc.apache.org/httpcomponents-core-5.3.x/5.3.4/httpcore5-h2/) 
org.apache.httpcomponents.core5:httpcore5-h2:jar:5.3.4
     License: Apache License, Version 2.0  
(https://www.apache.org/licenses/LICENSE-2.0.txt)
 
 
diff --git 
a/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java
 
b/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java
index b6d4ccb620..37fdb5fbb9 100644
--- 
a/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java
+++ 
b/perftests/src/main/java/org/apache/qpid/disttest/jms/QpidRestAPIQueueCreator.java
@@ -23,7 +23,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
+import java.net.URISyntaxException;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -37,22 +37,24 @@ import javax.jms.QueueBrowser;
 import javax.jms.Session;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.CredentialsProvider;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.classic.methods.HttpDelete;
+import org.apache.hc.client5.http.classic.methods.HttpGet;
+import org.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
+import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.auth.BasicScheme;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.ProtocolVersion;
+import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -75,7 +77,7 @@ public class QpidRestAPIQueueCreator implements QueueCreator
 
     private final CredentialsProvider _credentialsProvider;
 
-    public QpidRestAPIQueueCreator()
+    public QpidRestAPIQueueCreator() throws URISyntaxException
     {
         final String managementUser = 
System.getProperty("perftests.manangement-user", "guest");
         final String managementPassword = 
System.getProperty("perftests.manangement-password", "guest");
@@ -271,11 +273,8 @@ public class QpidRestAPIQueueCreator implements 
QueueCreator
     private void managementCreateQueue(final String name, final 
HttpClientContext context)
     {
         HttpPut put = new HttpPut(String.format(_queueApiUrl, 
_virtualhostnode, _virtualhost, name));
-
-        StringEntity input = new StringEntity("{}", StandardCharsets.UTF_8);
-        input.setContentType("application/json");
+        StringEntity input = new StringEntity("{}", 
ContentType.APPLICATION_JSON, "UTF_8", false);
         put.setEntity(input);
-
         executeManagement(put, context);
     }
 
@@ -285,18 +284,20 @@ public class QpidRestAPIQueueCreator implements 
QueueCreator
         executeManagement(delete, context);
     }
 
-    private Object executeManagement(final HttpRequest httpRequest, final 
HttpClientContext context)
+    private Object executeManagement(final HttpUriRequest httpRequest, final 
HttpClientContext context)
     {
-        try(CloseableHttpClient httpClient = HttpClients.custom()
-                                                        
.setDefaultCredentialsProvider(_credentialsProvider)
-                                                        .build();
-            CloseableHttpResponse response = httpClient.execute(_management, 
httpRequest, context))
+        try (final CloseableHttpClient httpClient = HttpClients.custom()
+                    .setDefaultCredentialsProvider(_credentialsProvider)
+                    .build();
+             final CloseableHttpResponse response = 
httpClient.execute(_management, httpRequest, context))
         {
-            int statusCode = response.getStatusLine().getStatusCode();
-            if (statusCode != 200 && statusCode != 201)
+            final int status = response.getCode();
+            final ProtocolVersion version = response.getVersion();
+            final String reason = response.getReasonPhrase();
+            if (status != 200 && status != 201)
             {
-                throw new RuntimeException(String.format("Failed : HTTP error 
code : %d  status line : %s", statusCode,
-                                                         
response.getStatusLine()));
+                final String msg = String.format("Failed: HTTP error code: %d, 
Version: %s, Reason: %s", status, version, reason);
+                throw new RuntimeException(msg);
             }
 
             if (response.getEntity() != null)
@@ -311,7 +312,6 @@ public class QpidRestAPIQueueCreator implements QueueCreator
                 }
             }
             return null;
-
         }
         catch (IOException e)
         {
@@ -330,8 +330,8 @@ public class QpidRestAPIQueueCreator implements QueueCreator
 
     private CredentialsProvider getCredentialsProvider(final String 
managementUser, final String managementPassword)
     {
-        final CredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
-        credentialsProvider.setCredentials(AuthScope.ANY, new 
UsernamePasswordCredentials(managementUser, managementPassword));
+        final BasicCredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
+        credentialsProvider.setCredentials(new AuthScope("localhost", 8080), 
new UsernamePasswordCredentials(managementUser, 
managementPassword.toCharArray()));
         return credentialsProvider;
     }
 
diff --git a/pom.xml b/pom.xml
index ade3a5a50d..88b59923bf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -135,7 +135,7 @@
     <hamcrest-version>3.0</hamcrest-version>
     <maven-resolver-provider-version>3.8.6</maven-resolver-provider-version>
     <maven-resolver-version>1.9.22</maven-resolver-version>
-    <httpclient-version>4.5.13</httpclient-version>
+    <httpclient-version>5.4.4</httpclient-version>
     <qpid-jms-client-version>1.13.0</qpid-jms-client-version>
     <qpid-jms-client-amqp-0-x-version>6.4.0</qpid-jms-client-amqp-0-x-version>
     <nashorn-version>15.6</nashorn-version>
@@ -690,8 +690,13 @@
         <version>${jfreechart-version}</version>
       </dependency>
       <dependency>
-        <groupId>org.apache.httpcomponents</groupId>
-        <artifactId>httpclient</artifactId>
+        <groupId>org.apache.httpcomponents.client5</groupId>
+        <artifactId>httpclient5</artifactId>
+        <version>${httpclient-version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.httpcomponents.client5</groupId>
+        <artifactId>httpclient5-fluent</artifactId>
         <version>${httpclient-version}</version>
       </dependency>
       <dependency>
diff --git a/tck/pom.xml b/tck/pom.xml
index d9ae62837d..058c4b9b0f 100644
--- a/tck/pom.xml
+++ b/tck/pom.xml
@@ -61,8 +61,8 @@
             <artifactId>slf4j-api</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient</artifactId>
+            <groupId>org.apache.httpcomponents.client5</groupId>
+            <artifactId>httpclient5</artifactId>
         </dependency>
         <dependency>
             <groupId>com.fasterxml.jackson.core</groupId>
diff --git a/tck/src/main/java/org/apache/qpid/tck/ManageQpidJMSResources.java 
b/tck/src/main/java/org/apache/qpid/tck/ManageQpidJMSResources.java
index cf709be830..c96885ad1f 100644
--- a/tck/src/main/java/org/apache/qpid/tck/ManageQpidJMSResources.java
+++ b/tck/src/main/java/org/apache/qpid/tck/ManageQpidJMSResources.java
@@ -18,34 +18,35 @@
  * under the License.
  *
  */
+
 package org.apache.qpid.tck;
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.net.URISyntaxException;
 import java.util.List;
 import java.util.Map;
 
 import com.fasterxml.jackson.core.JsonParser;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpRequest;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.CredentialsProvider;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpPut;
-import org.apache.http.client.protocol.HttpClientContext;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.auth.BasicScheme;
-import org.apache.http.impl.client.BasicAuthCache;
-import org.apache.http.impl.client.BasicCredentialsProvider;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
+import org.apache.hc.client5.http.auth.AuthScope;
+import org.apache.hc.client5.http.auth.CredentialsProvider;
+import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
+import org.apache.hc.client5.http.classic.methods.HttpDelete;
+import org.apache.hc.client5.http.classic.methods.HttpPost;
+import org.apache.hc.client5.http.classic.methods.HttpPut;
+import org.apache.hc.client5.http.classic.methods.HttpUriRequest;
+import org.apache.hc.client5.http.impl.auth.BasicAuthCache;
+import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
+import org.apache.hc.client5.http.impl.auth.BasicScheme;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
+import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
+import org.apache.hc.client5.http.impl.classic.HttpClients;
+import org.apache.hc.client5.http.protocol.HttpClientContext;
+import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.http.HttpHost;
+import org.apache.hc.core5.http.io.entity.StringEntity;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -88,11 +89,10 @@ public class ManageQpidJMSResources
         else
         {
             manageQpidJMSResources.createResources();
-
         }
     }
 
-    public ManageQpidJMSResources()
+    public ManageQpidJMSResources() throws URISyntaxException
     {
         _objectMapper = new ObjectMapper();
         _objectMapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
@@ -213,10 +213,9 @@ public class ManageQpidJMSResources
         executeManagement(delete);
     }
 
-    private void management(final HttpEntityEnclosingRequestBase request, 
final Object obj) throws IOException
+    private void management(final HttpUriRequest request, final Object obj) 
throws IOException
     {
-        StringEntity input = new 
StringEntity(_objectMapper.writeValueAsString(obj), StandardCharsets.UTF_8);
-        input.setContentType("application/json");
+        StringEntity input = new 
StringEntity(_objectMapper.writeValueAsString(obj), 
ContentType.APPLICATION_JSON, "UTF_8", false);
         request.setEntity(input);
 
         int statusCode = executeManagement(request);
@@ -226,7 +225,7 @@ public class ManageQpidJMSResources
         }
     }
 
-    private int executeManagement(final HttpRequest httpRequest)
+    private int executeManagement(final HttpUriRequest httpRequest)
     {
 
         try(CloseableHttpClient httpClient = HttpClients.custom()
@@ -235,7 +234,7 @@ public class ManageQpidJMSResources
         {
             try (CloseableHttpResponse response = 
httpClient.execute(_management, httpRequest, _httpClientContext))
             {
-                return response.getStatusLine().getStatusCode();
+                return response.getCode();
             }
         }
         catch (IOException e)
@@ -255,8 +254,8 @@ public class ManageQpidJMSResources
 
     private CredentialsProvider getCredentialsProvider(final String 
managementUser, final String managementPassword)
     {
-        final CredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
-        credentialsProvider.setCredentials(AuthScope.ANY, new 
UsernamePasswordCredentials(managementUser, managementPassword));
+        final BasicCredentialsProvider credentialsProvider = new 
BasicCredentialsProvider();
+        credentialsProvider.setCredentials(new AuthScope("localhost", 8080), 
new UsernamePasswordCredentials(managementUser, 
managementPassword.toCharArray()));
         return credentialsProvider;
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to