AXIS2-5959 replace org.apache.commons.httpclient with org.apache.http in the integration unit tests
diff --git a/modules/integration/pom.xml b/modules/integration/pom.xml
index b57160c..f8e7120 100644
--- a/modules/integration/pom.xml
+++ b/modules/integration/pom.xml
@@ -126,11 +126,6 @@
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
<scope>test</scope>
diff --git a/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java b/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java
index 2ce2373..7f2191a 100644
--- a/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java
+++ b/modules/integration/test/org/apache/axis2/mtom/EchoRawMTOMFaultReportTest.java
@@ -31,18 +31,30 @@
import org.apache.axis2.integration.UtilServerBasedTestCase;
import org.apache.axis2.receivers.RawXMLINOutMessageReceiver;
import org.apache.axis2.wsdl.WSDLConstants;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.HttpMethodRetryHandler;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.NoHttpResponseException;
-import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
-import org.apache.commons.httpclient.methods.PostMethod;
-import org.apache.commons.httpclient.params.HttpMethodParams;
+
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpRequestRetryHandler;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHeaders;
+import org.apache.http.NoHttpResponseException;
+import org.apache.http.entity.InputStreamEntity;
+import org.apache.http.HttpStatus;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.ArrayList;
import java.io.FileInputStream;
import java.io.IOException;
+import java.io.InterruptedIOException;
public class EchoRawMTOMFaultReportTest extends UtilServerBasedTestCase {
@@ -82,50 +94,52 @@
}
public void testEchoFaultSync() throws Exception {
- HttpClient client = new HttpClient();
+ HttpPost httpPost = new HttpPost("http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/EchoService/mtomSample");
- PostMethod httppost = new PostMethod("http://127.0.0.1:"
- + (UtilServer.TESTING_PORT)
- + "/axis2/services/EchoService/mtomSample");
-
- HttpMethodRetryHandler myretryhandler = new HttpMethodRetryHandler() {
- public boolean retryMethod(final HttpMethod method,
- final IOException exception,
- int executionCount) {
- if (executionCount >= 10) {
- return false;
- }
- if (exception instanceof NoHttpResponseException) {
- return true;
- }
- if (!method.isRequestSent()) {
- return true;
- }
- // otherwise do not retry
- return false;
- }
- };
- httppost.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
- myretryhandler);
- httppost.setRequestEntity(new InputStreamRequestEntity(
+ httpPost.setEntity(new InputStreamEntity(
new FileInputStream(TestingUtils.prefixBaseDirectory("test-resources/mtom/wmtom.bin"))));
- httppost.setRequestHeader("Content-Type",
- "multipart/related; boundary=--MIMEBoundary258DE2D105298B756D; type=\"application/xop+xml\"; start=\"<0.15B50EF49317518B01@apache.org>\"; start-info=\"application/soap+xml\"");
- try {
- client.executeMethod(httppost);
+ Header header = new BasicHeader(HttpHeaders.CONTENT_TYPE, "multipart/related; boundary=--MIMEBoundary258DE2D105298B756D; type=\"application/xop+xml\"; start=\"<0.15B50EF49317518B01@apache.org>\"; start-info=\"application/soap+xml\"");
- if (httppost.getStatusCode() ==
- HttpStatus.SC_INTERNAL_SERVER_ERROR) {
+ List<Header> headers = new ArrayList();
+ headers.add(header);
+
+ CloseableHttpClient httpclient = HttpClients.custom().setDefaultHeaders(headers).setRetryHandler(new HttpRequestRetryHandler() {
+ @Override
+ public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
+ if (executionCount >= 10) {
+ return false;
+ }
+ if (exception instanceof NoHttpResponseException) {
+ return true;
+ }
+ if (exception instanceof InterruptedIOException) {
+ return true;
+ }
+ HttpClientContext clientContext = HttpClientContext.adapt(context);
+ if (!clientContext.isRequestSent()) {
+ return true;
+ }
+ // otherwise do not retry
+ return false;
+ }
+ }).build();
+
+
+ try {
+ CloseableHttpResponse hcResponse = httpclient.execute(httpPost);
+ int status = hcResponse.getStatusLine().getStatusCode();
+ if (status == HttpStatus.SC_INTERNAL_SERVER_ERROR) {
// TODO: There is a missing wsa:Action header in the SOAP message. Fix or look for correct fault text!
// assertEquals("HTTP/1.1 500 Internal server error",
// httppost.getStatusLine().toString());
}
- } catch (NoHttpResponseException e) {
- } finally {
- httppost.releaseConnection();
+ System.out.println("\ntestEchoFaultSync() result status: " + status + " , statusLine: " + hcResponse.getStatusLine());
+
+ }finally {
+ httpclient.close();
}
- }
+ }
}
diff --git a/modules/integration/test/org/apache/axis2/rest/RESTfulServiceTest.java b/modules/integration/test/org/apache/axis2/rest/RESTfulServiceTest.java
index a6fed47..4ba2973 100644
--- a/modules/integration/test/org/apache/axis2/rest/RESTfulServiceTest.java
+++ b/modules/integration/test/org/apache/axis2/rest/RESTfulServiceTest.java
@@ -34,11 +34,19 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.integration.UtilServer;
import org.apache.axis2.integration.UtilServerBasedTestCase;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.methods.GetMethod;
+
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpStatus;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
import javax.xml.namespace.QName;
+import java.io.InterruptedIOException;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
@@ -132,43 +140,59 @@
axisConfig.addService(axisService);
assertEquals("StockService", axisService.getName());
- HttpClient httpClient = new HttpClient();
-
String url1 = "http://127.0.0.1:" + (UtilServer.TESTING_PORT)
+ "/axis2/services/StockService/add/IBM/value/34.7";
- GetMethod method1 = new GetMethod(url1);
+ HttpGet httpGet = new HttpGet(url1);
+
+ CloseableHttpClient httpclient = HttpClients.createDefault();
try {
- int statusCode = httpClient.executeMethod(method1);
- if (statusCode != HttpStatus.SC_OK) {
- System.err.println("Method failed: " + method1.getStatusLine());
+ CloseableHttpResponse hcResponse = httpclient.execute(httpGet);
+ int status = hcResponse.getStatusLine().getStatusCode();
+ if (status != HttpStatus.SC_OK) {
+ throw new ClientProtocolException("url request failed: " + hcResponse.getStatusLine());
}
- OMElement response = AXIOMUtil.stringToOM(new String(method1.getResponseBody()));
- OMElement returnElem = response.getFirstChildWithName(new QName("return"));
+ HttpEntity responseEntity = hcResponse.getEntity();
+ if(responseEntity==null) {
+ throw new ClientProtocolException("url request returned null entity: " + hcResponse.getStatusLine());
+ }
+ String responseStr = EntityUtils.toString(responseEntity);
+ OMElement axisResponse = AXIOMUtil.stringToOM(responseStr);
+ OMElement returnElem = axisResponse.getFirstChildWithName(new QName("return"));
assertEquals("IBM stock added with value : 34.7", returnElem.getText());
- } finally {
- method1.releaseConnection();
+ }finally {
+ httpclient.close();
}
+ String url2 = "http://127.0.0.1:" + (UtilServer.TESTING_PORT) + "/axis2/services/StockService/get/IBM";
- String url2 = "http://127.0.0.1:" + (UtilServer.TESTING_PORT)
- + "/axis2/services/StockService/get/IBM";
- GetMethod method2 = new GetMethod(url2);
+ httpGet = null;
+ httpclient = null;
+
+ httpGet = new HttpGet(url2);
+
+ httpclient = HttpClients.createDefault();
try {
- int statusCode = httpClient.executeMethod(method2);
-
- if (statusCode != HttpStatus.SC_OK) {
- System.err.println("Method failed: " + method2.getStatusLine());
+ CloseableHttpResponse hcResponse = httpclient.execute(httpGet);
+ int status = hcResponse.getStatusLine().getStatusCode();
+ if (status != HttpStatus.SC_OK) {
+ throw new ClientProtocolException("url request failed: " + hcResponse.getStatusLine());
}
- OMElement response = AXIOMUtil.stringToOM(new String(method2.getResponseBody()));
- OMElement returnElem = response.getFirstChildWithName(new QName("return"));
+ HttpEntity responseEntity = hcResponse.getEntity();
+ if(responseEntity==null) {
+ throw new ClientProtocolException("url request returned null entity: " + hcResponse.getStatusLine());
+ }
+
+ String responseStr = EntityUtils.toString(responseEntity);
+ OMElement axisResponse = AXIOMUtil.stringToOM(responseStr);
+ OMElement returnElem = axisResponse.getFirstChildWithName(new QName("return"));
assertEquals("34.7", returnElem.getText());
- } finally {
- method2.releaseConnection();
+ }finally {
+ httpclient.close();
}
}