aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services
diff options
context:
space:
mode:
Diffstat (limited to 'rest-services')
-rw-r--r--rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java85
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java11
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java11
3 files changed, 59 insertions, 48 deletions
diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java
index 8e317f8b..132d3d83 100644
--- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java
+++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java
@@ -28,8 +28,9 @@ import java.util.Map;
import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
-import reactor.netty.http.client.HttpClient;
import reactor.netty.http.client.HttpClientResponse;
@@ -40,6 +41,7 @@ import reactor.netty.http.client.HttpClientResponse;
@Deprecated
public class CloudHttpClient {
+ private static final Logger LOGGER = LoggerFactory.getLogger(CloudHttpClient.class);
private final Gson gson = new Gson();
private final RxHttpClient httpClient;
@@ -64,38 +66,38 @@ public class CloudHttpClient {
}
public <T> Mono<T> get(
- String url,
- RequestDiagnosticContext context,
- Map<String, String> customHeaders,
- Class<T> bodyClass) {
+ String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ Class<T> bodyClass) {
return httpClient.call(
- ImmutableHttpRequest.builder()
- .method(HttpMethod.GET)
- .url(url)
- .customHeaders(HashMap.ofAll(customHeaders))
- .diagnosticContext(context)
- .build())
- .doOnNext(HttpResponse::throwIfUnsuccessful)
- .map(HttpResponse::bodyAsString)
- .map(body -> gson.fromJson(body, bodyClass));
+ ImmutableHttpRequest.builder()
+ .method(HttpMethod.GET)
+ .url(url)
+ .customHeaders(HashMap.ofAll(customHeaders))
+ .diagnosticContext(context)
+ .build())
+ .doOnNext(HttpResponse::throwIfUnsuccessful)
+ .map(HttpResponse::bodyAsString)
+ .map(body -> gson.fromJson(body, bodyClass));
}
public Mono<HttpClientResponse> post(
- String url,
- RequestDiagnosticContext context,
- Map<String, String> customHeaders,
- JsonBodyBuilder jsonBodyBuilder,
- ClientModel clientModel) {
+ String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel) {
return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.POST);
}
public Mono<HttpClientResponse> patch(
- String url,
- RequestDiagnosticContext context,
- Map<String, String> customHeaders,
- JsonBodyBuilder jsonBodyBuilder,
- ClientModel clientModel) {
+ String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel) {
return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PATCH);
}
@@ -109,22 +111,29 @@ public class CloudHttpClient {
}
private Mono<HttpClientResponse> callForRawResponse(
- String url,
- RequestDiagnosticContext context,
- Map<String, String> customHeaders,
- JsonBodyBuilder jsonBodyBuilder,
- ClientModel clientModel,
- HttpMethod method) {
+ String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ JsonBodyBuilder jsonBodyBuilder,
+ ClientModel clientModel,
+ HttpMethod method) {
+
+ String jsonBody = jsonBodyBuilder.createJsonBody(clientModel);
+ LOGGER.debug("CloudHttpClient JSon body:: {}", jsonBody);
+ LOGGER.debug("CloudHttpClient url: {}", url);
+ LOGGER.debug("CloudHttpClient customHeaders: {}", customHeaders);
+
return httpClient.prepareRequest(
- ImmutableHttpRequest.builder()
- .url(url)
- .customHeaders(HashMap.ofAll(customHeaders))
- .diagnosticContext(context)
- .body(RequestBody.fromString(jsonBodyBuilder.createJsonBody(clientModel)))
- .method(method)
- .build())
- .responseSingle((httpClientResponse, byteBufMono) -> Mono.just(httpClientResponse));
+ ImmutableHttpRequest.builder()
+ .url(url)
+ .customHeaders(HashMap.ofAll(customHeaders))
+ .diagnosticContext(context)
+ .body(RequestBody.fromString(jsonBody))
+ .method(method)
+ .build())
+ .responseSingle((httpClientResponse, byteBufMono) -> Mono.just(httpClientResponse));
}
+
}
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java
index b37ac3dc..81a62eba 100644
--- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java
+++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClient.java
@@ -20,7 +20,7 @@
package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer;
-import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import java.net.URI;
import java.util.Map;
import java.util.Optional;
@@ -60,15 +60,16 @@ public class DMaaPConsumerReactiveHttpClient extends DMaaPAbstractReactiveHttpCl
*
* @return reactive response from DMaaP in string format
*/
- public Mono<JsonArray> getDMaaPConsumerResponse(Optional<RequestDiagnosticContext> requestDiagnosticContextOptional) {
- Map<String,String> headers = DMaaPClientServiceUtils.getHeaders(consumerConfiguration.dmaapContentType());
+ public Mono<JsonElement> getDMaaPConsumerResponse(
+ Optional<RequestDiagnosticContext> requestDiagnosticContextOptional) {
+ Map<String, String> headers = DMaaPClientServiceUtils.getHeaders(consumerConfiguration.dmaapContentType());
if (requestDiagnosticContextOptional.isPresent()) {
return cloudHttpClient
- .get(getUri().toString(), requestDiagnosticContextOptional.get(), headers, JsonArray.class);
+ .get(getUri().toString(), requestDiagnosticContextOptional.get(), headers, JsonElement.class);
}
RequestDiagnosticContext requestDiagnosticContext = ImmutableRequestDiagnosticContext.builder()
.invocationId(UUID.randomUUID()).requestId(UUID.randomUUID()).build();
- return cloudHttpClient.get(getUri().toString(), requestDiagnosticContext, headers, JsonArray.class);
+ return cloudHttpClient.get(getUri().toString(), requestDiagnosticContext, headers, JsonElement.class);
}
URI getUri() {
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
index c37514eb..5a29fff0 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
@@ -23,7 +23,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consum
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
import java.net.URI;
import java.util.Optional;
import org.apache.http.entity.ContentType;
@@ -45,7 +45,7 @@ class DMaaPConsumerReactiveHttpClientTest {
private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\"}";
private DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient;
private DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class);
- private Mono<JsonArray> expectedResult;
+ private Mono<JsonElement> expectedResult;
private CloudHttpClient httpClient = mock(CloudHttpClient.class);
private URI exampleTestUri = URI
.create("https://54.45.33.2:1234/unauthenticated.SEC_OTHER_OUTPUT/OpenDCAE-c12/c12");
@@ -68,11 +68,12 @@ class DMaaPConsumerReactiveHttpClientTest {
@Test
void getHttpResponse_Success() {
//given
- expectedResult = Mono.just(mock(JsonArray.class));
- when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext, DMaaPClientServiceUtils.getHeaders(ContentType.APPLICATION_JSON.getMimeType()), JsonArray.class))
+ expectedResult = Mono.just(mock(JsonElement.class));
+ when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext,
+ DMaaPClientServiceUtils.getHeaders(ContentType.APPLICATION_JSON.getMimeType()), JsonElement.class))
.thenReturn(expectedResult);
//when
- Mono<JsonArray> response = dmaapConsumerReactiveHttpClient
+ Mono<JsonElement> response = dmaapConsumerReactiveHttpClient
.getDMaaPConsumerResponse(Optional.of(requestDiagnosticContext));
//then
StepVerifier.create(response).expectSubscription()