diff options
Diffstat (limited to 'sdc-distribution-client/src/main/java/org/openecomp/sdc/http')
-rw-r--r-- | sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java | 21 | ||||
-rw-r--r-- | sdc-distribution-client/src/main/java/org/openecomp/sdc/http/SdcConnectorClient.java (renamed from sdc-distribution-client/src/main/java/org/openecomp/sdc/http/AsdcConnectorClient.java) | 30 |
2 files changed, 17 insertions, 34 deletions
diff --git a/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java b/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java index 7ace38f..c3a486a 100644 --- a/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java +++ b/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/HttpAsdcClient.java @@ -60,7 +60,6 @@ import org.apache.http.message.BasicHeader; import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.TrustStrategy; import org.openecomp.sdc.api.consumer.IConfiguration; -import org.openecomp.sdc.impl.DistributionClientImpl; import org.openecomp.sdc.utils.Pair; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,19 +74,19 @@ public class HttpAsdcClient implements IHttpAsdcClient { private String serverFqdn = null; private String authHeaderValue = ""; - public HttpAsdcClient(IConfiguration configuraion/* String serverFqdn, String username, String password */) { + public HttpAsdcClient(IConfiguration configuraion) { this.serverFqdn = configuraion.getAsdcAddress(); + String username = configuraion.getUser(); String password = configuraion.getPassword(); - - initSSL(serverFqdn, username, password, configuraion.getKeyStorePath(), configuraion.getKeyStorePassword(), configuraion.activateServerTLSAuth()); + initSSL(username, password, configuraion.getKeyStorePath(), configuraion.getKeyStorePassword(), configuraion.activateServerTLSAuth()); String userNameAndPassword = username + ":" + password; this.authHeaderValue = "Basic " + Base64.encodeBase64String(userNameAndPassword.getBytes()); } // @SuppressWarnings("deprecation") - private void initSSL(String serverFqdn, String username, String password, String keyStorePath, String keyStoePass, boolean isSupportSSLVerification) { + private void initSSL(String username, String password, String keyStorePath, String keyStoePass, boolean isSupportSSLVerification) { try { HostnameVerifier hostnameVerifier = new HostnameVerifier() { @@ -245,9 +244,9 @@ public class HttpAsdcClient implements IHttpAsdcClient { log.error("failed to close http response"); } } - ret = new Pair<HttpAsdcResponse, CloseableHttpResponse>(response, null); + ret = new Pair<>(response, null); } else { - ret = new Pair<HttpAsdcResponse, CloseableHttpResponse>(response, httpResponse); + ret = new Pair<>(response, httpResponse); } } @@ -264,7 +263,7 @@ public class HttpAsdcClient implements IHttpAsdcClient { Pair<HttpAsdcResponse, CloseableHttpResponse> ret; CloseableHttpResponse httpResponse = null; String url = HTTPS + serverFqdn + requestUrl; - log.debug("url to send " + url); + log.debug("url to send {}", url); HttpGet httpGet = new HttpGet(url); List<Header> headers = addHeadersToHttpRequest(headersMap); for (Header header : headers) { @@ -277,16 +276,16 @@ public class HttpAsdcClient implements IHttpAsdcClient { try { httpResponse = httpClient.execute(httpGet); - log.debug("GET Response Status " + httpResponse.getStatusLine().getStatusCode()); + log.debug("GET Response Status {}", httpResponse.getStatusLine().getStatusCode()); Header[] headersRes = httpResponse.getAllHeaders(); - Map<String, String> headersResMap = new HashMap<String, String>(); + Map<String, String> headersResMap = new HashMap<>(); for (Header header : headersRes) { headersResMap.put(header.getName(), header.getValue()); } response = new HttpAsdcResponse(httpResponse.getStatusLine().getStatusCode(), httpResponse.getEntity(), headersResMap); } catch (UnknownHostException | ConnectException e) { - log.error("failed to connect to url: " + requestUrl, e); + log.error("failed to connect to url: {}", requestUrl, e); StringEntity errorEntity = null; try { errorEntity = new StringEntity("failed to connect"); diff --git a/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/AsdcConnectorClient.java b/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/SdcConnectorClient.java index 0ef1711..2ae78af 100644 --- a/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/AsdcConnectorClient.java +++ b/sdc-distribution-client/src/main/java/org/openecomp/sdc/http/SdcConnectorClient.java @@ -57,9 +57,9 @@ import com.google.gson.reflect.TypeToken; import fj.data.Either; -public class AsdcConnectorClient { +public class SdcConnectorClient { String contentDispositionHeader = "Content-Disposition"; - private static Logger log = LoggerFactory.getLogger(AsdcConnectorClient.class.getName()); + private static Logger log = LoggerFactory.getLogger(SdcConnectorClient.class.getName()); private IConfiguration configuration; private HttpAsdcClient httpClient = null; @@ -90,22 +90,6 @@ public class AsdcConnectorClient { this.httpClient = httpClient; } - public Either<List<String>, IDistributionClientResult> getServerList() { - Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair = performAsdcServerRequest(AsdcUrls.GET_CLUSTER_SERVER_LIST); - HttpAsdcResponse getServersResponse = getServersResponsePair.getFirst(); - - Either<List<String>, IDistributionClientResult> response; - if (getServersResponse.getStatus() == HttpStatus.SC_OK) { - response = parseGetServersResponse(getServersResponse); - } else { - IDistributionClientResult asdcError = handleAsdcError(getServersResponse); - response = Either.right(asdcError); - - } - handeAsdcConnectionClose(getServersResponsePair); - return response; - - } public Either<List<String>, IDistributionClientResult> getValidArtifactTypesList() { Pair<HttpAsdcResponse, CloseableHttpResponse> getServersResponsePair = performAsdcServerRequest(AsdcUrls.GET_VALID_ARTIFACT_TYPES); @@ -151,7 +135,7 @@ public class AsdcConnectorClient { String requestId = UUID.randomUUID().toString(); Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId); - RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName()); + RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress()); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonRequest = gson.toJson(registrationRequest); StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON); @@ -183,7 +167,7 @@ public class AsdcConnectorClient { HttpAsdcClient httpClient = new HttpAsdcClient(configuration); Map<String, String> requestHeaders = addHeadersToHttpRequest(requestId); - RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName()); + RegistrationRequest registrationRequest = new RegistrationRequest(credential.getApiKey(), configuration.getEnvironmentName(), configuration.isConsumeProduceStatusTopic(), configuration.getMsgBusAddress()); Gson gson = new GsonBuilder().setPrettyPrinting().create(); String jsonRequest = gson.toJson(registrationRequest); StringEntity body = new StringEntity(jsonRequest, ContentType.APPLICATION_JSON); @@ -275,7 +259,7 @@ public class AsdcConnectorClient { return result; } - private Either<TopicRegistrationResponse, DistributionClientResultImpl> parseRegistrationResponse(HttpAsdcResponse registerResponse) { + Either<TopicRegistrationResponse, DistributionClientResultImpl> parseRegistrationResponse(HttpAsdcResponse registerResponse) { String jsonMessage; try { @@ -302,8 +286,8 @@ public class AsdcConnectorClient { } } - private Map<String, String> addHeadersToHttpRequest(String requestId) { - Map<String, String> requestHeaders = new HashMap<String, String>(); + protected Map<String, String> addHeadersToHttpRequest(String requestId) { + Map<String, String> requestHeaders = new HashMap<>(); requestHeaders.put(DistributionClientConstants.HEADER_REQUEST_ID, requestId); requestHeaders.put(DistributionClientConstants.HEADER_INSTANCE_ID, configuration.getConsumerID()); requestHeaders.put(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); |