From 318c2405310ad369983c169e3b7b4443b2049253 Mon Sep 17 00:00:00 2001 From: andrzejszukuc Date: Thu, 28 Mar 2019 06:16:08 +0100 Subject: Modified CloudHttpClient in order to be more generic New AaiClients and AaiModels have been added Change-Id: I80151e8296482e39f7f36123210861702c205b7b Signed-off-by: andrzejszukuc Issue-ID: DCAEGEN2-1059 --- .../services/adapters/http/CloudHttpClient.java | 52 +++++++++++----------- .../model/AaiServiceInstanceQueryModel.java | 31 +++++++++++++ .../services/adapters/http/CloudHttpClientIT.java | 36 +++++++-------- 3 files changed, 76 insertions(+), 43 deletions(-) create mode 100644 rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiServiceInstanceQueryModel.java (limited to 'rest-services/common-dependency/src') 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 Przemysław Wąsala on 11/15/18 @@ -65,25 +63,32 @@ public class CloudHttpClient { return get(url, context, Collections.emptyMap(), bodyClass); } - public Mono get( - String url, - RequestDiagnosticContext context, - Map customHeaders, - Class bodyClass) { + public Mono get( + String url, + RequestDiagnosticContext context, + Map 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 Mono get( + String url, + RequestDiagnosticContext context, + Map customHeaders, + Class bodyClass) { + return get(url, context, customHeaders) + .doOnNext(HttpResponse::throwIfUnsuccessful) + .map(HttpResponse::bodyAsString) + .map(body -> gson.fromJson(body, bodyClass)); } - public Mono post( + public Mono post( String url, RequestDiagnosticContext context, Map customHeaders, @@ -92,7 +97,7 @@ public class CloudHttpClient { return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.POST); } - public Mono patch( + public Mono patch( String url, RequestDiagnosticContext context, Map customHeaders, @@ -101,7 +106,7 @@ public class CloudHttpClient { return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PATCH); } - public Mono put( + public Mono put( String url, RequestDiagnosticContext context, Map customHeaders, @@ -110,7 +115,7 @@ public class CloudHttpClient { return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PUT); } - private Mono callForRawResponse( + private Mono callForRawResponse( String url, RequestDiagnosticContext context, Map 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 content = cloudHttpClient + Mono 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 content = cloudHttpClient + Mono 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 content = cloudHttpClient + Mono 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 content = cloudHttpClient + Mono 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 content = cloudHttpClient + Mono 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 content = cloudHttpClient + Mono 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(); } -- cgit 1.2.3-korg