Change in ovirt-engine-sdk-java[master]: sdk: Don't call DefaultHttpClient.execute

juan.hernandez at redhat.com juan.hernandez at redhat.com
Thu Aug 20 16:46:51 UTC 2015


Juan Hernandez has submitted this change and it was merged.

Change subject: sdk: Don't call DefaultHttpClient.execute
......................................................................


sdk: Don't call DefaultHttpClient.execute

Thte DefaultHttpClient class has been deprecated in version 4.3 of
HttpCoponents, and the "execute" method signature has changed from this:

  HttpResponse execute(HttpUriRequest, HttpContext)

To this:

  CloseableHttpResponse execute(HttpUriRequest, HttpContext)

This means that the result of compiling calls to this method depends on
the version of HttpComponents used during the build. When using version
4.2 or older the result is this:

  invokevirtual #14 // Method
  org/apache/http/impl/client/DefaultHttpClient.execute:(
    Lorg/apache/http/client/methods/HttpUriRequest;
    Lorg/apache/http/protocol/HttpContext;
  )Lorg/apache/http/HttpResponse;

When using version 4.3 or newer the result is this:

  invokevirtual #14 // Method
  org/apache/http/impl/client/DefaultHttpClient.execute:(
    Lorg/apache/http/client/methods/HttpUriRequest;
    Lorg/apache/http/protocol/HttpContext;
  )Lorg/apache/http/client/methods/CloseableHttpResponse;

Note that with 4.2 the return type is "HttpResponse" but with 4.3 the
return type is "CloseableHttpResponse".

This shouldn't be a problem when building with maven, as we explicitly
specify version 4.2 in the POM of the project, but it can be a problem
in other build environments that don't use maven.

When built with the newer HttpComponents version execution will fail if
the older version is used, with the following error message:

  Exception in thread "main" java.lang.NoSuchMethodError:
  org.apache.http.impl.client.DefaultHttpClient.execute(
    Lorg/apache/http/client/methods/HttpUriRequest;
    Lorg/apache/http/protocol/HttpContext;
  )Lorg/apache/http/client/methods/CloseableHttpResponse;

The right solution to this problem is to modify the SDK so that it
doesn't use the deprecated "DefaultHttpClient" class at all, but this
requires many changes. Instead of that this patch changes the SDK
minimally, so that the "DefaultHttpClient" class is used, but not for
calling the "execute" method, the "HttpClient" interface is used for
that instead. This way the result of compiling the calls to "execute" is
the same regardless of the version used. The changes required to stop
using "DefaultHttpClient" will be included in other patches.

Change-Id: I06f99256566f67034bbeff843eaf959cf4a87760
Bug-Url: https://bugzilla.redhat.com/1255078
Signed-off-by: Juan Hernandez <juan.hernandez at redhat.com>
---
M sdk/src/main/java/org/ovirt/engine/sdk/web/ConnectionsPool.java
1 file changed, 4 insertions(+), 3 deletions(-)

Approvals:
  Ori Liel: Looks good to me, but someone else must approve
  Juan Hernandez: Verified; Looks good to me, approved; Passed CI tests



-- 
To view, visit https://gerrit.ovirt.org/45102
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I06f99256566f67034bbeff843eaf959cf4a87760
Gerrit-PatchSet: 2
Gerrit-Project: ovirt-engine-sdk-java
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernandez at redhat.com>
Gerrit-Reviewer: Juan Hernandez <juan.hernandez at redhat.com>
Gerrit-Reviewer: Ori Liel <oliel at redhat.com>
Gerrit-Reviewer: automation at ovirt.org



More information about the Engine-commits mailing list