This is an automated email from the ASF dual-hosted git repository.
robertlazarski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/axis-axis2-java-core.git
The following commit(s) were added to refs/heads/master by this push:
new 91be03f AXIS2-5959 replace org.apache.commons.httpclient with
org.apache.http in the json samples and unit tests
91be03f is described below
commit 91be03fe100c63ea7e611be08aa8510c3b29abfa
Author: robert lazarski
AuthorDate: Wed Apr 7 09:15:48 2021 -1000
AXIS2-5959 replace org.apache.commons.httpclient with org.apache.http in
the json samples and unit tests
---
.../axis2/json/gson/JSONXMLStreamAPITest.java | 6 +-
.../test/org/apache/axis2/json/gson/UtilTest.java | 36
.../json/gson/rpc/JSONRPCIntegrationTest.java | 7 +--
.../json/src/sample/json/client/JsonClient.java| 64 +-
4 files changed, 66 insertions(+), 47 deletions(-)
diff --git
a/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
b/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
index bb11e97..348ab23 100644
--- a/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
+++ b/modules/json/test/org/apache/axis2/json/gson/JSONXMLStreamAPITest.java
@@ -32,8 +32,6 @@ public class JSONXMLStreamAPITest {
public void xmlStreamAPITest()throws Exception{
String getLibURL = server.getEndpoint("LibraryService") + "getLibrary";
String echoLibURL = server.getEndpoint("LibraryService") +
"echoLibrary";
-String contentType = "application/json";
-String charSet = "UTF-8";
String echoLibrary =
"{\"echoLibrary\":{\"args0\":{\"admin\":{\"address\":{\"city\":\"My
City\",\"country\":" +
"\"My Country\",\"street\":\"My
Street\",\"zipCode\":\"0\"},\"age\":24,\"name\":\"micheal\"," +
@@ -67,11 +65,11 @@ public class JSONXMLStreamAPITest {
"{\"author\":\"Jhon_4\",\"numOfPages\":175,\"publisher\":\"Foxier\",\"reviewers\":[\"rev1\",\"rev2\","
+
"\"rev3\"]}],\"staff\":50}}}";
-String actualResponse = UtilTest.post(echoLibrary, echoLibURL,
contentType, charSet);
+String actualResponse = UtilTest.post(echoLibrary, echoLibURL);
Assert.assertNotNull(actualResponse);
Assert.assertEquals(echoLibraryResponse , actualResponse);
-String actualRespose_2 = UtilTest.post(getLibrary, getLibURL,
contentType, charSet);
+String actualRespose_2 = UtilTest.post(getLibrary, getLibURL);
Assert.assertNotNull(actualRespose_2);
Assert.assertEquals(getLibraryResponse, actualRespose_2);
diff --git a/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
b/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
index ac1df45..c70937b 100644
--- a/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
+++ b/modules/json/test/org/apache/axis2/json/gson/UtilTest.java
@@ -19,26 +19,38 @@
package org.apache.axis2.json.gson;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.methods.RequestEntity;
-import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.HttpEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
import java.io.IOException;
public class UtilTest {
-public static String post(String jsonString, String strURL, String
contentType, String charSet)
+public static String post(String jsonString, String strURL)
throws IOException {
-PostMethod post = new PostMethod(strURL);
-RequestEntity entity = new StringRequestEntity(jsonString,
contentType, charSet);
-post.setRequestEntity(entity);
-HttpClient httpclient = new HttpClient();
+HttpEntity stringEntity = new
StringEntity(jsonString,ContentType.APPLICATION_JSON);
+ HttpPost httpPost = new HttpPost(strURL);
+httpPost.setEntity(stringEntity);
+ CloseableHttpClient httpclient = HttpClients.createDefault();
+
try {
-int result = httpclient.executeMethod(post);
-return post.getResponseBodyAsString();
+CloseableHttpResponse response = httpclient.execute(httpPost);
+ int status = response.getStatusLine().getStatusCode();
+if (status >= 200 && status < 300) {
+HttpEntity entity = response.getEntity();
+return entity != null ? EntityUtils.toString(entity,"UTF-8") :
null;
+} else {
+