diff options
author | 2018-07-05 14:23:36 +0200 | |
---|---|---|
committer | 2018-08-07 09:52:51 +0200 | |
commit | e74228673c9c5241a9e901726716f77aacb2711f (patch) | |
tree | d4d9b2a4d85d984ce44b3f146a201416bf8b0343 /prh-dmaap-client/src/main | |
parent | a44fb6f1b9d72ec553ba23038db299b2b8a2016f (diff) |
Bug fixes
Improve UnitTest
Add changes after review in
DmaaPReactiveTasks workflow
Change-Id: I920092235528964758014c2d9d229ccd22e69cae
Issue-ID: DCAEGEN2-563
Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-dmaap-client/src/main')
2 files changed, 15 insertions, 65 deletions
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java index a41ec3a4..ab81bede 100644 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java +++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClient.java @@ -21,6 +21,7 @@ package org.onap.dcaegen2.services.prh.service; import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication; +import org.onap.dcaegen2.services.prh.config.DmaapCustomConfig; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; @@ -35,26 +36,34 @@ public class DMaaPReactiveWebClient { private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private DMaaPReactiveWebClient() { + private String dMaaPContentType; + private String dMaaPUserName; + private String dMaaPUserPassword; + + public DMaaPReactiveWebClient fromConfiguration(DmaapCustomConfig dmaapCustomConfig) { + this.dMaaPUserName = dmaapCustomConfig.dmaapUserName(); + this.dMaaPUserPassword = dmaapCustomConfig.dmaapUserPassword(); + this.dMaaPContentType = dmaapCustomConfig.dmaapContentType(); + return this; } - private WebClient create(WebClientBuilder webClientBuilder) { + public WebClient build() { return WebClient.builder() - .defaultHeader(HttpHeaders.CONTENT_TYPE, webClientBuilder.dMaaPContentType) - .filter(basicAuthentication(webClientBuilder.dMaaPUserName, webClientBuilder.dMaaPUserPassword)) + .defaultHeader(HttpHeaders.CONTENT_TYPE, dMaaPContentType) + .filter(basicAuthentication(dMaaPUserName, dMaaPUserPassword)) .filter(logRequest()) .filter(logResponse()) .build(); } - ExchangeFilterFunction logResponse() { + private ExchangeFilterFunction logResponse() { return ExchangeFilterFunction.ofResponseProcessor(clientResponse -> { logger.info("Response Status {}", clientResponse.statusCode()); return Mono.just(clientResponse); }); } - ExchangeFilterFunction logRequest() { + private ExchangeFilterFunction logRequest() { return ExchangeFilterFunction.ofRequestProcessor(clientRequest -> { logger.info("Request: {} {}", clientRequest.method(), clientRequest.url()); clientRequest.headers() @@ -63,32 +72,4 @@ public class DMaaPReactiveWebClient { }); } - public static class WebClientBuilder { - - private String dMaaPContentType; - private String dMaaPUserName; - private String dMaaPUserPassword; - - public WebClientBuilder() { - } - - public WebClientBuilder dmaapContentType(String dmaapContentType) { - this.dMaaPContentType = dmaapContentType; - return this; - } - - public WebClientBuilder dmaapUserName(String dmaapUserName) { - this.dMaaPUserName = dmaapUserName; - return this; - } - - public WebClientBuilder dmaapUserPassword(String dmaapUserPassword) { - this.dMaaPUserPassword = dmaapUserPassword; - return this; - } - - public WebClient build() { - return new DMaaPReactiveWebClient().create(this); - } - } } diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/HttpUtils.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/HttpUtils.java deleted file mode 100644 index b96f80dd..00000000 --- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/prh/service/HttpUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * PNF-REGISTRATION-HANDLER - * ================================================================================ - * 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.prh.service; - -import org.apache.http.HttpStatus; - -public final class HttpUtils implements HttpStatus { - - private HttpUtils() {} - - public static boolean isSuccessfulResponseCode(Integer statusCode) { - return statusCode >= 200 && statusCode < 300; - } -} |