summaryrefslogtreecommitdiffstats
path: root/rest-services/common-dependency
diff options
context:
space:
mode:
authorandrzejszukuc <andrzej.szukuc@nokia.com>2019-03-28 06:16:08 +0100
committerandrzejszukuc <andrzej.szukuc@nokia.com>2019-03-28 16:05:21 +0100
commit318c2405310ad369983c169e3b7b4443b2049253 (patch)
treee5ac6a9b57f22a77f8f31eb8a44a648aaaa17198 /rest-services/common-dependency
parent999a1d92f3f30156501186bc4b9407bb6913db67 (diff)
Modified CloudHttpClient in order to be more generic
New AaiClients and AaiModels have been added Change-Id: I80151e8296482e39f7f36123210861702c205b7b Signed-off-by: andrzejszukuc <andrzej.szukuc@nokia.com> Issue-ID: DCAEGEN2-1059
Diffstat (limited to 'rest-services/common-dependency')
-rw-r--r--rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java52
-rw-r--r--rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java31
-rw-r--r--rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java36
3 files changed, 76 insertions, 43 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 132d3d83..7b87511b 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
@@ -31,8 +31,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnos
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;
-import reactor.netty.http.client.HttpClientResponse;
-
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 11/15/18
@@ -65,25 +63,32 @@ public class CloudHttpClient {
return get(url, context, Collections.emptyMap(), bodyClass);
}
- public <T> Mono<T> get(
- String url,
- RequestDiagnosticContext context,
- Map<String, String> customHeaders,
- Class<T> bodyClass) {
+ public Mono<HttpResponse> get(
+ String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders) {
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());
+ }
+
+ public <T> Mono<T> get(
+ String url,
+ RequestDiagnosticContext context,
+ Map<String, String> customHeaders,
+ Class<T> bodyClass) {
+ return get(url, context, customHeaders)
+ .doOnNext(HttpResponse::throwIfUnsuccessful)
+ .map(HttpResponse::bodyAsString)
+ .map(body -> gson.fromJson(body, bodyClass));
}
- public Mono<HttpClientResponse> post(
+ public Mono<HttpResponse> post(
String url,
RequestDiagnosticContext context,
Map<String, String> customHeaders,
@@ -92,7 +97,7 @@ public class CloudHttpClient {
return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.POST);
}
- public Mono<HttpClientResponse> patch(
+ public Mono<HttpResponse> patch(
String url,
RequestDiagnosticContext context,
Map<String, String> customHeaders,
@@ -101,7 +106,7 @@ public class CloudHttpClient {
return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PATCH);
}
- public Mono<HttpClientResponse> put(
+ public Mono<HttpResponse> put(
String url,
RequestDiagnosticContext context,
Map<String, String> customHeaders,
@@ -110,7 +115,7 @@ public class CloudHttpClient {
return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PUT);
}
- private Mono<HttpClientResponse> callForRawResponse(
+ private Mono<HttpResponse> callForRawResponse(
String url,
RequestDiagnosticContext context,
Map<String, String> customHeaders,
@@ -123,17 +128,14 @@ public class CloudHttpClient {
LOGGER.debug("CloudHttpClient url: {}", url);
LOGGER.debug("CloudHttpClient customHeaders: {}", customHeaders);
- return httpClient.prepareRequest(
+ return httpClient.call(
ImmutableHttpRequest.builder()
.url(url)
.customHeaders(HashMap.ofAll(customHeaders))
.diagnosticContext(context)
.body(RequestBody.fromString(jsonBody))
.method(method)
- .build())
- .responseSingle((httpClientResponse, byteBufMono) -> Mono.just(httpClientResponse));
+ .build());
}
-
-
}
diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java
new file mode 100644
index 00000000..bb4493e8
--- /dev/null
+++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java
@@ -0,0 +1,31 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.services.sdk.rest.services.model;
+
+import org.immutables.value.Value;
+
+@Value.Style(stagedBuilder = true)
+@Value.Immutable
+public interface AaiServiceInstanceQueryModel extends ClientModel {
+ String customerId();
+ String serviceType();
+ String serviceInstanceId();
+}
diff --git a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java
index 9844ef1d..d221a809 100644
--- a/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java
+++ b/rest-services/common-dependency/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClientIT.java
@@ -61,12 +61,12 @@ class CloudHttpClientIT {
CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY);
- Mono<HttpClientResponse> content = cloudHttpClient
+ Mono<HttpResponse> content = cloudHttpClient
.patch(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(),
jsonBodyBuilder, dmaapModel);
- HttpClientResponse httpClientResponse = content.block();
+ HttpResponse httpClientResponse = content.block();
- assertEquals(HttpResponseStatus.OK, httpClientResponse.status());
+ assertEquals(HttpResponseStatus.OK.code(), httpClientResponse.statusCode());
server.disposeNow();
}
@@ -77,12 +77,12 @@ class CloudHttpClientIT {
CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY);
- Mono<HttpClientResponse> content = cloudHttpClient
+ Mono<HttpResponse> content = cloudHttpClient
.patch(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(),
jsonBodyBuilder, dmaapModel);
- HttpClientResponse httpClientResponse = content.block();
+ HttpResponse httpClientResponse = content.block();
- assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, httpClientResponse.status());
+ assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), httpClientResponse.statusCode());
server.disposeNow();
}
@@ -93,12 +93,12 @@ class CloudHttpClientIT {
CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY);
- Mono<HttpClientResponse> content = cloudHttpClient
+ Mono<HttpResponse> content = cloudHttpClient
.post(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(),
jsonBodyBuilder, dmaapModel);
- HttpClientResponse httpClientResponse = content.block();
+ HttpResponse httpClientResponse = content.block();
- assertEquals(HttpResponseStatus.OK, httpClientResponse.status());
+ assertEquals(HttpResponseStatus.OK.code(), httpClientResponse.statusCode());
server.disposeNow();
}
@@ -109,12 +109,12 @@ class CloudHttpClientIT {
CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY);
- Mono<HttpClientResponse> content = cloudHttpClient
+ Mono<HttpResponse> content = cloudHttpClient
.post(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(),
jsonBodyBuilder, dmaapModel);
- HttpClientResponse httpClientResponse = content.block();
+ HttpResponse httpClientResponse = content.block();
- assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, httpClientResponse.status());
+ assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), httpClientResponse.statusCode());
server.disposeNow();
}
@@ -161,12 +161,12 @@ class CloudHttpClientIT {
CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY);
- Mono<HttpClientResponse> content = cloudHttpClient
+ Mono<HttpResponse> content = cloudHttpClient
.put(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(),
jsonBodyBuilder, dmaapModel);
- HttpClientResponse httpClientResponse = content.block();
+ HttpResponse httpClientResponse = content.block();
- assertEquals(HttpResponseStatus.OK, httpClientResponse.status());
+ assertEquals(HttpResponseStatus.OK.code(), httpClientResponse.statusCode());
server.disposeNow();
}
@@ -177,12 +177,12 @@ class CloudHttpClientIT {
CloudHttpClient cloudHttpClient = new CloudHttpClient(httpClient);
when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(JSON_BODY);
- Mono<HttpClientResponse> content = cloudHttpClient
+ Mono<HttpResponse> content = cloudHttpClient
.put(SAMPLE_URL, createRequestDiagnosticContext(), createCustomHeaders(),
jsonBodyBuilder, dmaapModel);
- HttpClientResponse httpClientResponse = content.block();
+ HttpResponse httpClientResponse = content.block();
- assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, httpClientResponse.status());
+ assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(), httpClientResponse.statusCode());
server.disposeNow();
}