aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSORESTClient/src/main/java/org
diff options
context:
space:
mode:
authorBenjamin, Max (mb388a) <mb388a@us.att.com>2018-07-30 15:56:09 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2018-07-31 11:09:25 -0400
commit5a6a6de6f1a26a1897e4917a0df613e25a24eb70 (patch)
tree59a968f27b4b603aacc9d5e7b51fb598aeec5321 /bpmn/MSORESTClient/src/main/java/org
parentb6dc38501f3b746426b42d9de4cc883d894149e8 (diff)
Containerization feature of SO
Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18 Issue-ID: SO-670 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'bpmn/MSORESTClient/src/main/java/org')
-rw-r--r--bpmn/MSORESTClient/src/main/java/org/onap/so/rest/APIResponse.java (renamed from bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/APIResponse.java)2
-rw-r--r--bpmn/MSORESTClient/src/main/java/org/onap/so/rest/HostNameVerifier.java (renamed from bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/HostNameVerifier.java)6
-rw-r--r--bpmn/MSORESTClient/src/main/java/org/onap/so/rest/HttpHeader.java (renamed from bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/HttpHeader.java)2
-rw-r--r--bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTClient.java (renamed from bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTClient.java)147
-rw-r--r--bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTConfig.java (renamed from bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTConfig.java)2
-rw-r--r--bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTException.java (renamed from bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTException.java)2
6 files changed, 85 insertions, 76 deletions
diff --git a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/APIResponse.java b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/APIResponse.java
index d85a790841..b77c90b215 100644
--- a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/APIResponse.java
+++ b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/APIResponse.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.rest;
+package org.onap.so.rest;
import java.io.IOException;
import java.util.Arrays;
diff --git a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/HostNameVerifier.java b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/HostNameVerifier.java
index ffef5f9385..3d10c0391d 100644
--- a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/HostNameVerifier.java
+++ b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/HostNameVerifier.java
@@ -19,12 +19,12 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.rest;
+package org.onap.so.rest;
import javax.net.ssl.SSLException;
import org.apache.http.conn.ssl.AbstractVerifier;
-import org.openecomp.mso.logger.MsoLogger;
+import org.onap.so.logger.MsoLogger;
/**
* @version 1.0
@@ -33,7 +33,7 @@ import org.openecomp.mso.logger.MsoLogger;
*/
public class HostNameVerifier extends AbstractVerifier {
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA, HostNameVerifier.class);
public final void verify(
final String host,
diff --git a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/HttpHeader.java b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/HttpHeader.java
index 79eea08dac..a96793334d 100644
--- a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/HttpHeader.java
+++ b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/HttpHeader.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.rest;
+package org.onap.so.rest;
/**
* An immutable class used to wrap an http header.
diff --git a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTClient.java b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTClient.java
index 3170e49371..fc6266d917 100644
--- a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTClient.java
+++ b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTClient.java
@@ -8,9 +8,9 @@
* 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.
@@ -19,9 +19,8 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.rest;
+package org.onap.so.rest;
-import java.io.Closeable;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@@ -30,6 +29,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.net.ssl.SSLSocketFactory;
@@ -37,7 +37,7 @@ import javax.net.ssl.SSLSocketFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPatch;
@@ -54,13 +54,12 @@ import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.AbstractHttpMessage;
import org.apache.http.util.EntityUtils;
-
-import org.openecomp.mso.logger.MsoLogger;
+import org.onap.so.logger.MsoLogger;
/**
* Client used to send RESTFul requests.
* <p>
- * Many of the methods return a reference to the 'this,' thereby allowing
- * method chaining.
+ * Many of the methods return a reference to the 'this,' thereby allowing
+ * method chaining.
* <br>
* An example of usage can be found below:
* <pre>
@@ -84,26 +83,28 @@ import org.openecomp.mso.logger.MsoLogger;
* @since 1.0
*/
public class RESTClient {
-
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL);
+
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,RESTClient.class);
private final String proxyHost;
private final int proxyPort;
- private final String URL;
+ private final String url;
+
+ private final Map<String, List<String>> headers;
+ private final Map<String, List<String>> parameters;
+
+
- private final LinkedHashMap<String, List<String>> headers;
- private final LinkedHashMap<String, List<String>> parameters;
-
private HttpEntity httpEntity;
/**
- * Internal method used to build an APIResponse using the specified
+ * Internal method used to build an APIResponse using the specified
* HttpResponse object.
*
* @param response response wrapped inside an APIResponse object
* @return api response
*/
- private APIResponse buildResponse(HttpResponse response)
+ private APIResponse buildResponse(HttpResponse response)
throws RESTException {
return new APIResponse(response);
@@ -183,22 +184,17 @@ public class RESTClient {
* @throws RESTException if unable to create http client.
*/
private CloseableHttpClient createClient() throws RESTException {
- //TODO - we may want to trust self signed certificate at some point - add implementation here
- HttpClientBuilder clientBuilder;
-
- try {
+ HttpClientBuilder clientBuilder;
+ try {
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
(SSLSocketFactory) SSLSocketFactory.getDefault(),
new HostNameVerifier());
Registry<ConnectionSocketFactory> registry = RegistryBuilder
.<ConnectionSocketFactory> create()
- .register("http",
- PlainConnectionSocketFactory.getSocketFactory())
+ .register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory).build();
- PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(
- registry);
- clientBuilder = HttpClientBuilder.create().setConnectionManager(
- manager);
+ PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager(registry);
+ clientBuilder = HttpClientBuilder.create().setConnectionManager(manager);
} catch (Exception ex) {
LOGGER.debug("Exception :", ex);
throw new RESTException(ex.getMessage());
@@ -209,36 +205,43 @@ public class RESTClient {
HttpHost proxy = new HttpHost(this.proxyHost, this.proxyPort);
clientBuilder.setProxy(proxy);
}
-
- return clientBuilder.build();
+ int timeoutInSeconds = 300;
+ RequestConfig requestConfig = RequestConfig.custom()
+ .setConnectTimeout(timeoutInSeconds * 1000)
+ .setConnectionRequestTimeout(timeoutInSeconds * 1000)
+ .setSocketTimeout(timeoutInSeconds * 1000).build();
+ return clientBuilder.setDefaultRequestConfig(requestConfig).build();
}
+
+
+
+
/**
* Creates a RESTClient with the specified URL, proxy host, and proxy port.
*
- * @param URL URL to send request to
+ * @param url URL to send request to
* @param proxyHost proxy host to use for sending request
* @param proxyPort proxy port to use for sendin request
*
* @throws RESTException if unable to create a RESTClient
*/
- public RESTClient(String URL, String proxyHost, int proxyPort)
- throws RESTException {
- this(new RESTConfig(URL, proxyHost, proxyPort));
+ public RESTClient(String url, String proxyHost, int proxyPort) {
+ this(new RESTConfig(url, proxyHost, proxyPort));
}
/**
* Creates a RESTClient with the specified URL. No proxy host nor port will
- * be used.
+ * be used.
*
- * @param URL URL to send request to
+ * @param url URL to send request to
*
* @throws RESTException if unable to create a RESTClient
*/
- public RESTClient(String URL) throws RESTException {
- this(new RESTConfig(URL));
+ public RESTClient(String url) {
+ this(new RESTConfig(url));
}
-
+
/**
* Creates a RESTClient with the RESTConfig object.
*
@@ -246,10 +249,10 @@ public class RESTClient {
*
* @throws RESTException if unable to create a RESTClient
*/
- public RESTClient(RESTConfig restConfig) throws RESTException {
+ public RESTClient(RESTConfig restConfig) {
this.headers = new LinkedHashMap<>();
this.parameters = new LinkedHashMap<>();
- this.URL = restConfig.getURL();
+ this.url = restConfig.getURL();
this.proxyHost = restConfig.getProxyHost();
this.proxyPort = restConfig.getProxyPort();
}
@@ -257,7 +260,7 @@ public class RESTClient {
/**
* Adds parameter to be sent during http request.
* <p>
- * Does not remove any parameters with the same name, thus allowing
+ * Does not remove any parameters with the same name, thus allowing
* duplicates.
*
* @param name name of parameter
@@ -297,11 +300,11 @@ public class RESTClient {
/**
* Adds http header to be sent during http request.
* <p>
- * Does not remove any headers with the same name, thus allowing
+ * Does not remove any headers with the same name, thus allowing
* duplicates.
*
- * @param name name of header
- * @param value value of header
+ * @param name name of header
+ * @param value value of header
* @return a reference to 'this', which can be used for method chaining
*/
public RESTClient addHeader(String name, String value) {
@@ -318,11 +321,11 @@ public class RESTClient {
/**
* Sets http header to be sent during http request.
* <p>
- * Does not remove any headers with the same name, thus allowing
+ * Does not remove any headers with the same name, thus allowing
* duplicates.
*
- * @param name name of header
- * @param value value of header
+ * @param name name of header
+ * @param value value of header
* @return a reference to 'this', which can be used for method chaining
*/
public RESTClient setHeader(String name, String value) {
@@ -334,9 +337,9 @@ public class RESTClient {
return this;
}
-
+
/**
- * Convenience method for adding the authorization header using the
+ * Convenience method for adding the authorization header using the
* specified OAuthToken object.
*
* @param token token to use for setting authorization
@@ -375,10 +378,11 @@ public class RESTClient {
HttpGet httpGet = new HttpGet(this.getURL() + query);
addInternalHeaders(httpGet);
+ LOGGER.debug("Executing GET to url: " + this.getURL() + query);
+
response = httpClient.execute(httpGet);
- APIResponse apiResponse = buildResponse(response);
- return apiResponse;
+ return buildResponse(response);
} catch (IOException ioe) {
throw new RESTException(ioe);
} finally {
@@ -407,8 +411,7 @@ public class RESTClient {
* @throws RESTException if POST was unsuccessful
*/
public APIResponse httpPost() throws RESTException {
- APIResponse response = httpPost(buildQuery());
- return response;
+ return httpPost(buildQuery());
}
/**
@@ -427,10 +430,12 @@ public class RESTClient {
httpEntity = new StringEntity(body);
httpPost.setEntity(new StringEntity(body));
}
+ LOGGER.debug("Executing POST to url: " + this.getURL());
response = httpClient.execute(httpPost);
return buildResponse(response);
+
} catch (IOException e) {
throw new RESTException(e);
} finally {
@@ -441,10 +446,10 @@ public class RESTClient {
}
/**
- *
+ *
* @param body Data to PUT
* @return API response
- * @throws RESTException
+ * @throws RESTException
*/
public APIResponse httpPut(String body) throws RESTException {
HttpResponse response = null;
@@ -460,6 +465,7 @@ public class RESTClient {
httpEntity = new StringEntity(body);
httpPut.setEntity(httpEntity);
}
+ LOGGER.debug("Executing PUT to url: " + this.getURL() + query);
response = httpClient.execute(httpPut);
@@ -483,10 +489,10 @@ public class RESTClient {
}
/**
- *
+ *
* @param body Data to PATCH
* @return API response
- * @throws RESTException
+ * @throws RESTException
*/
public APIResponse httpPatch(String body) throws RESTException {
HttpResponse response = null;
@@ -501,6 +507,7 @@ public class RESTClient {
httpEntity = new StringEntity(body);
httpPatch.setEntity(httpEntity);
}
+ LOGGER.debug("Executing PATCH to url: " + this.getURL() + query);
response = httpClient.execute(httpPatch);
@@ -554,16 +561,17 @@ public class RESTClient {
}
HttpDeleteWithBody httpDelete = new HttpDeleteWithBody(this.getURL() + query);
addInternalHeaders(httpDelete);
-
+
if (body != null && !body.equals("")) {
httpEntity = new StringEntity(body);
httpDelete.setEntity(httpEntity);
}
+ LOGGER.debug("Executing DELETE to url: " + this.getURL() + query);
+
response = httpClient.execute(httpDelete);
- APIResponse apiResponse = buildResponse(response);
- return apiResponse;
+ return buildResponse(response);
} catch (IOException ioe) {
throw new RESTException(ioe);
} finally {
@@ -574,39 +582,40 @@ public class RESTClient {
}
public String getURL() {
- return URL;
+ return url;
}
- public LinkedHashMap<String,List<String>> getHeaders() {
+ public Map<String,List<String>> getHeaders() {
return headers;
}
- public LinkedHashMap<String,List<String>> getParameters() {
+ public Map<String,List<String>> getParameters() {
return parameters;
}
public HttpEntity getHttpEntity() {
return httpEntity;
}
-
+
/**
* Allows inclusion of a request body with DELETE.
*/
private class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
public static final String METHOD_NAME = "DELETE";
-
- public String getMethod() {
+
+ @Override
+ public String getMethod() {
return METHOD_NAME;
}
-
+
public HttpDeleteWithBody(final String uri) {
super();
setURI(URI.create(uri));
}
-
+
public HttpDeleteWithBody(final URI uri) {
super();
setURI(uri);
}
-
+
public HttpDeleteWithBody() {
super();
}
diff --git a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTConfig.java b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTConfig.java
index 0e4681824a..b5fecbdb87 100644
--- a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTConfig.java
+++ b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTConfig.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.rest;
+package org.onap.so.rest;
/**
* Configuration values to be used by the RESTClient.
diff --git a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTException.java b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTException.java
index 88fa16f736..579927c2ce 100644
--- a/bpmn/MSORESTClient/src/main/java/org/openecomp/mso/rest/RESTException.java
+++ b/bpmn/MSORESTClient/src/main/java/org/onap/so/rest/RESTException.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.rest;
+package org.onap.so.rest;
/**
* A custom exception class.