X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-interactions%2Fmodel-impl%2Frest%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Frest%2FRestManager.java;h=855dc92f669912fd52ec3396d3f2eab62592a89e;hb=938005505883cf7a636a8840e20e3dc8a0ad9176;hp=4f37e9592b2a1aee57ed682d5c786b9fac2b52be;hpb=21607022333b8d3917754d071d5e4c259308edef;p=policy%2Fmodels.git diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java index 4f37e9592..855dc92f6 100644 --- a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java +++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * rest * ================================================================================ - * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,10 @@ package org.onap.policy.rest; +import jakarta.xml.bind.DatatypeConverter; import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Map.Entry; -import javax.xml.bind.DatatypeConverter; import org.apache.commons.lang3.tuple.Pair; import org.apache.http.HttpHeaders; import org.apache.http.HttpResponse; @@ -52,7 +52,7 @@ public class RestManager { * Perform REST PUT. * * @param url the url - * @param username the user name + * @param username the user * @param password the password * @param headers any headers * @param contentType what the content type is @@ -61,11 +61,11 @@ public class RestManager { */ public Pair put(String url, String username, String password, Map headers, String contentType, String body) { - HttpPut put = new HttpPut(url); + var put = new HttpPut(url); addHeaders(put, username, password, headers); put.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); put.setEntity(input); } catch (Exception e) { @@ -79,7 +79,7 @@ public class RestManager { * Perform REST Post. * * @param url the url - * @param username the user name + * @param username the user * @param password the password * @param headers any headers * @param contentType what the content type is @@ -88,11 +88,11 @@ public class RestManager { */ public Pair post(String url, String username, String password, Map headers, String contentType, String body) { - HttpPost post = new HttpPost(url); + var post = new HttpPost(url); addHeaders(post, username, password, headers); post.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); post.setEntity(input); } catch (Exception e) { @@ -106,13 +106,13 @@ public class RestManager { * Do a REST get. * * @param url URL - * @param username user name + * @param username user * @param password password * @param headers any headers to add * @return a Pair for the response status and the body */ public Pair get(String url, String username, String password, Map headers) { - HttpGet get = new HttpGet(url); + var get = new HttpGet(url); addHeaders(get, username, password, headers); return sendRequest(get); } @@ -122,7 +122,7 @@ public class RestManager { * Note: Many REST endpoints will return a 400 error for delete requests with a non-empty body * * @param url the url - * @param username the user name + * @param username the user * @param password the password * @param headers any headers * @param contentType what the content type is @@ -131,12 +131,12 @@ public class RestManager { */ public Pair delete(String url, String username, String password, Map headers, String contentType, String body) { - HttpDeleteWithBody delete = new HttpDeleteWithBody(url); + var delete = new HttpDeleteWithBody(url); addHeaders(delete, username, password, headers); if (body != null && !body.isEmpty()) { delete.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); delete.setEntity(input); } catch (Exception e) { @@ -151,13 +151,13 @@ public class RestManager { * Perform REST Delete. * * @param url the url - * @param username the user name + * @param username the user * @param password the password * @param headers any headers * @return the response status code and the body */ public Pair delete(String url, String username, String password, Map headers) { - HttpDelete delete = new HttpDelete(url); + var delete = new HttpDelete(url); addHeaders(delete, username, password, headers); return sendRequest(delete); } @@ -166,7 +166,7 @@ public class RestManager { * Perform REST Patch. * * @param url the url - * @param username the user name + * @param username the user * @param password the password * @param headers any headers * @param body body to send @@ -174,12 +174,12 @@ public class RestManager { */ public Pair patch(String url, String username, String password, Map headers, String body) { - String contentType = "application/merge-patch+json"; - HttpPatch patch = new HttpPatch(url); + var contentType = "application/merge-patch+json"; + var patch = new HttpPatch(url); addHeaders(patch, username, password, headers); patch.addHeader(CONTENT_TYPE, contentType); try { - StringEntity input = new StringEntity(body); + var input = new StringEntity(body); input.setContentType(contentType); patch.setEntity(input); } catch (Exception e) { @@ -204,7 +204,7 @@ public class RestManager { HttpClientBuilder.create().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build()) { HttpResponse response = client.execute(request); if (response != null) { - String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); + var returnBody = EntityUtils.toString(response.getEntity(), "UTF-8"); logger.debug("HTTP Response Status Code: {}", response.getStatusLine().getStatusCode()); logger.debug("HTTP Response Body:"); logger.debug(returnBody); @@ -224,7 +224,7 @@ public class RestManager { * Add header to the request. * * @param request http request to send - * @param username the user name + * @param username the user * @param password the password * @param headers any headers */