diff --git a/src/main/java/com/hpe/adm/octane/ideplugins/services/TestService.java b/src/main/java/com/hpe/adm/octane/ideplugins/services/TestService.java index f03c43f..d4e477d 100644 --- a/src/main/java/com/hpe/adm/octane/ideplugins/services/TestService.java +++ b/src/main/java/com/hpe/adm/octane/ideplugins/services/TestService.java @@ -28,11 +28,10 @@ ******************************************************************************/ package com.hpe.adm.octane.ideplugins.services; -import com.google.api.client.http.GenericUrl; -import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpTransport; -import com.google.api.client.http.javanet.NetHttpTransport; import com.hpe.adm.nga.sdk.Octane; +import com.hpe.adm.nga.sdk.network.OctaneHttpClient; +import com.hpe.adm.nga.sdk.network.OctaneHttpRequest; +import com.hpe.adm.nga.sdk.network.OctaneHttpResponse; import com.hpe.adm.nga.sdk.query.Query; import com.hpe.adm.nga.sdk.query.QueryMethod; import com.hpe.adm.octane.ideplugins.services.connection.ConnectionSettings; @@ -40,6 +39,7 @@ import com.hpe.adm.octane.ideplugins.services.connection.granttoken.GrantTokenAuthentication; import com.hpe.adm.octane.ideplugins.services.exception.ServiceException; import com.hpe.adm.octane.ideplugins.services.filtering.Entity; +import com.hpe.adm.octane.ideplugins.services.nonentity.OctaneVersionService; import com.hpe.adm.octane.ideplugins.services.util.ClientType; /** @@ -61,13 +61,13 @@ public Octane getOctane(ConnectionSettings connectionSettings) { public void testHttpConnection(ConnectionSettings connectionSettings) throws ServiceException { try { - HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); - HttpRequest httpRequest = HTTP_TRANSPORT.createRequestFactory() - .buildGetRequest(new GenericUrl(connectionSettings.getBaseUrl() + "/admin/server/version")); - int statusCode = httpRequest.execute().getStatusCode(); - if (httpRequest.execute().getStatusCode() >= 300) { - throw new ServiceException( - "HTTP connection to url: " + connectionSettings.getBaseUrl() + " failed: http response code: + " + statusCode); + OctaneHttpClient octaneHttpClient = new IdePluginsOctaneHttpClient(connectionSettings.getBaseUrl(), ClientType.OCTANE_IDE_PLUGIN); + OctaneHttpRequest request = new OctaneHttpRequest.GetOctaneHttpRequest(OctaneVersionService.getServerVersionUrl(connectionSettings)); + + OctaneHttpResponse response = octaneHttpClient.execute(request); + + if (!response.isSuccessStatusCode()) { + throw new ServiceException("HTTP connection to url: " + connectionSettings.getBaseUrl() + " failed"); } } catch (Exception e) { throw new ServiceException("HTTP connection to url: " + connectionSettings.getBaseUrl() + " failed: " + e.getMessage()); diff --git a/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/ImageService.java b/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/ImageService.java index 6fecab8..06dc030 100644 --- a/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/ImageService.java +++ b/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/ImageService.java @@ -28,13 +28,13 @@ ******************************************************************************/ package com.hpe.adm.octane.ideplugins.services.nonentity; -import com.google.api.client.http.*; -import com.google.api.client.http.javanet.NetHttpTransport; -import com.google.api.client.util.IOUtils; +import com.google.common.io.ByteStreams; import com.google.inject.Inject; +import com.hpe.adm.nga.sdk.network.OctaneHttpClient; +import com.hpe.adm.nga.sdk.network.OctaneHttpRequest; +import com.hpe.adm.nga.sdk.network.OctaneHttpResponse; import com.hpe.adm.octane.ideplugins.services.connection.ConnectionSettingsProvider; import com.hpe.adm.octane.ideplugins.services.connection.HttpClientProvider; -import com.hpe.adm.octane.ideplugins.services.connection.IdePluginsOctaneHttpClient; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -43,7 +43,6 @@ import org.slf4j.LoggerFactory; import java.io.*; -import java.net.HttpCookie; public class ImageService { @@ -72,11 +71,11 @@ private File saveImageToTempFile(String pictureLink) throws Exception { imgFile = new File(octanePhotosDir, pictureName); } - HttpResponse httpResponse = downloadImage(pictureLink, 2); + OctaneHttpResponse httpResponse = downloadImage(pictureLink, 2); - try (InputStream is = httpResponse.getContent(); + try (InputStream is = httpResponse.getInputStream(); OutputStream os = new FileOutputStream(imgFile)) { - IOUtils.copy(is, os); + ByteStreams.copy(is, os); } catch (IOException e) { logger.error(e.getMessage()); } @@ -88,30 +87,23 @@ private File saveImageToTempFile(String pictureLink) throws Exception { * @param pictureLink - src link to the image from server * @return */ - private HttpResponse downloadImage(String pictureLink, int tryCount) throws Exception { - - HttpResponse httpResponse; - HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); - HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(); - try { - HttpRequest httpRequest = requestFactory.buildGetRequest(new GenericUrl(pictureLink)); - HttpCookie lwssoCookie = ((IdePluginsOctaneHttpClient) httpClientProvider.getOctaneHttpClient()).getSessionHttpCookie(); - httpRequest.getHeaders().setCookie(lwssoCookie.toString()); - httpResponse = httpRequest.execute(); - } catch (IOException e) { - if(e instanceof HttpResponseException && ((HttpResponseException)e).getStatusCode() == 401 && tryCount > 0) { - //means that the cookie expired - logger.error("Cookie expired, retrying: " + e.getMessage()); - ((IdePluginsOctaneHttpClient) httpClientProvider.getOctaneHttpClient()) - .setLastUsedAuthentication(connectionSettingsProvider.getConnectionSettings().getAuthentication()); - httpClientProvider.getOctaneHttpClient().authenticate(); + private OctaneHttpResponse downloadImage(String pictureLink, int tryCount) throws Exception { + + OctaneHttpClient octaneHttpClient = httpClientProvider.getOctaneHttpClient(); + OctaneHttpRequest request = new OctaneHttpRequest.GetOctaneHttpRequest(pictureLink); + + OctaneHttpResponse response = octaneHttpClient.execute(request); + + if (!response.isSuccessStatusCode()) { + if (tryCount > 0) { return downloadImage(pictureLink, --tryCount); } else { - logger.error(e.getMessage()); + logger.error("Failed to load image from ValueEdge"); throw new Exception("Failed to load image from ValueEdge"); } } - return httpResponse; + + return response; } public String downloadPictures(String descriptionField) throws Exception{ diff --git a/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/OctaneVersionService.java b/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/OctaneVersionService.java index c949fb6..32a2274 100644 --- a/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/OctaneVersionService.java +++ b/src/main/java/com/hpe/adm/octane/ideplugins/services/nonentity/OctaneVersionService.java @@ -33,10 +33,11 @@ import com.hpe.adm.nga.sdk.network.OctaneHttpClient; import com.hpe.adm.nga.sdk.network.OctaneHttpRequest; import com.hpe.adm.nga.sdk.network.OctaneHttpResponse; -import com.hpe.adm.nga.sdk.network.google.GoogleHttpClient; import com.hpe.adm.octane.ideplugins.services.connection.ConnectionSettings; import com.hpe.adm.octane.ideplugins.services.connection.ConnectionSettingsProvider; +import com.hpe.adm.octane.ideplugins.services.connection.IdePluginsOctaneHttpClient; import com.hpe.adm.octane.ideplugins.services.exception.ServiceRuntimeException; +import com.hpe.adm.octane.ideplugins.services.util.ClientType; import com.hpe.adm.octane.ideplugins.services.util.OctaneVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,8 +59,9 @@ public class OctaneVersionService { private static String getVersionString(ConnectionSettings connectionSettings) { try { + System.setProperty("jdk.http.auth.tunneling.disabledSchemes", ""); OctaneHttpRequest request = new OctaneHttpRequest.GetOctaneHttpRequest(getServerVersionUrl(connectionSettings)); - OctaneHttpClient octaneHttpClient = new GoogleHttpClient(connectionSettings.getBaseUrl(), connectionSettings.getAuthentication()); + OctaneHttpClient octaneHttpClient = new IdePluginsOctaneHttpClient(connectionSettings.getBaseUrl(), ClientType.OCTANE_IDE_PLUGIN); OctaneHttpResponse response = octaneHttpClient.execute(request); String jsonString = response.getContent(); return new JsonParser().parse(jsonString).getAsJsonObject().get("display_version").getAsString();