summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/src/main/java/org/onap/so/client/BaseClient.java89
-rw-r--r--common/src/main/java/org/onap/so/client/policy/entities/DictionaryJson.java2
-rw-r--r--common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java2
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/CloudRequestData.java59
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/Request.java15
5 files changed, 164 insertions, 3 deletions
diff --git a/common/src/main/java/org/onap/so/client/BaseClient.java b/common/src/main/java/org/onap/so/client/BaseClient.java
new file mode 100644
index 0000000000..d939a33358
--- /dev/null
+++ b/common/src/main/java/org/onap/so/client/BaseClient.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.so.client;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.onap.so.logging.jaxrs.filter.SpringClientFilter;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.http.client.BufferingClientHttpRequestFactory;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+
+public class BaseClient<I, O> {
+
+ private HttpHeaders httpHeader;
+ private String targetUrl;
+
+ public HttpHeaders getHttpHeader() {
+ return httpHeader;
+ }
+
+ public HttpHeaders setDefaultHttpHeaders(String auth) {
+ httpHeader = new HttpHeaders();
+ httpHeader.set("Authorization", auth);
+ httpHeader.setContentType(MediaType.APPLICATION_JSON);
+ List<MediaType> acceptMediaTypes = new ArrayList<MediaType>();
+ acceptMediaTypes.add(MediaType.APPLICATION_JSON);
+ acceptMediaTypes.add(MediaType.TEXT_PLAIN);
+ httpHeader.setAccept(acceptMediaTypes);
+ return httpHeader;
+ }
+
+ public void setHttpHeader(HttpHeaders httpHeader) {
+ this.httpHeader = httpHeader;
+ }
+
+ public String getTargetUrl() {
+ return targetUrl;
+ }
+
+ public void setTargetUrl(String targetUrl) {
+ this.targetUrl = targetUrl;
+ }
+
+ public O get(I data, ParameterizedTypeReference<O> typeRef, Object... uriVariables) throws RestClientException {
+ return run(data, HttpMethod.GET, typeRef, uriVariables);
+ }
+
+ public O post(I data, ParameterizedTypeReference<O> typeRef, Object... uriVariables) throws RestClientException {
+ return run(data, HttpMethod.POST, typeRef, uriVariables);
+ }
+
+ public O run(I data, HttpMethod method, ParameterizedTypeReference<O> typeRef, Object... uriVariables)
+ throws RestClientException {
+ HttpEntity<I> requestEntity = new HttpEntity<I>(data, getHttpHeader());
+ RestTemplate restTemplate = new RestTemplate();
+ restTemplate
+ .setRequestFactory(new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()));
+ restTemplate.getInterceptors().add(new SpringClientFilter());
+ ResponseEntity<O> responseEntity =
+ restTemplate.exchange(getTargetUrl(), method, requestEntity, typeRef, uriVariables);
+ return responseEntity.getBody();
+ }
+
+}
diff --git a/common/src/main/java/org/onap/so/client/policy/entities/DictionaryJson.java b/common/src/main/java/org/onap/so/client/policy/entities/DictionaryJson.java
index 5b99fe1a05..6e7baa37e6 100644
--- a/common/src/main/java/org/onap/so/client/policy/entities/DictionaryJson.java
+++ b/common/src/main/java/org/onap/so/client/policy/entities/DictionaryJson.java
@@ -31,7 +31,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder;
public class DictionaryJson {
@JsonProperty("DictionaryDatas")
- private List<DictionaryData> dictionaryDatas = new ArrayList<DictionaryData>();
+ private List<DictionaryData> dictionaryDatas = new ArrayList<>();
@JsonProperty("DictionaryDatas")
public List<DictionaryData> getDictionaryDatas() {
diff --git a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
index 8e6ebab43a..a627e82802 100644
--- a/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
+++ b/common/src/main/java/org/onap/so/rest/service/HttpRestServiceProviderImpl.java
@@ -96,7 +96,7 @@ public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
private <T> Optional<T> createOptional(final ResponseEntity<T> response, final String url,
final HttpMethod httpMethod) {
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
+ if (!response.getStatusCode().equals(HttpStatus.OK) && !response.getStatusCode().equals(HttpStatus.CREATED)) {
final String message = "Unable to invoke HTTP " + httpMethod + " using URL: " + url + ", Response Code: "
+ response.getStatusCode();
LOGGER.error(message);
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/CloudRequestData.java b/common/src/main/java/org/onap/so/serviceinstancebeans/CloudRequestData.java
new file mode 100644
index 0000000000..abaef26562
--- /dev/null
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/CloudRequestData.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 AT&T 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.so.serviceinstancebeans;
+
+import org.apache.commons.lang3.builder.ToStringBuilder;
+
+public class CloudRequestData {
+
+ Object cloudRequest;
+ String cloudIdentifier;
+
+ public CloudRequestData() {}
+
+ public CloudRequestData(Object cloudRequest, String cloudIdentifier) {
+ this.cloudRequest = cloudRequest;
+ this.cloudIdentifier = cloudIdentifier;
+ }
+
+ public Object getCloudRequest() {
+ return cloudRequest;
+ }
+
+ public void setCloudRequest(Object cloudRequest) {
+ this.cloudRequest = cloudRequest;
+ }
+
+ public String getCloudIdentifier() {
+ return cloudIdentifier;
+ }
+
+ public void setCloudIdentifier(String cloudIdentifier) {
+ this.cloudIdentifier = cloudIdentifier;
+ }
+
+ @Override
+ public String toString() {
+ return new ToStringBuilder(this).append("cloudRequest", cloudRequest).append("cloudIdentifier", cloudIdentifier)
+ .toString();
+ }
+}
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java b/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java
index 8635af5b94..fbdb27c0ec 100644
--- a/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/Request.java
@@ -20,7 +20,9 @@
package org.onap.so.serviceinstancebeans;
+import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import org.apache.commons.lang3.builder.ToStringBuilder;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
@@ -38,6 +40,7 @@ public class Request {
protected InstanceReferences instanceReferences;
protected RequestStatus requestStatus;
protected List<RequestProcessingData> requestProcessingData;
+ protected List<CloudRequestData> cloudRequestData = new ArrayList<>();
public String getRequestId() {
@@ -112,12 +115,22 @@ public class Request {
this.requestProcessingData = requestProcessingData;
}
+
+ public List<CloudRequestData> getCloudRequestData() {
+ return cloudRequestData;
+ }
+
+ public void setCloudRequestData(List<CloudRequestData> cloudRequestData) {
+ this.cloudRequestData = cloudRequestData;
+ }
+
@Override
public String toString() {
return new ToStringBuilder(this).append("requestId", requestId).append("startTime", startTime)
.append("finishTime", finishTime).append("requestScope", requestScope)
.append("requestType", requestType).append("requestDetails", requestDetails)
.append("instanceReferences", instanceReferences).append("requestStatus", requestStatus)
- .append("requestProcessingData", requestProcessingData).toString();
+ .append("requestProcessingData", requestProcessingData).append("cloudRequestData", cloudRequestData)
+ .toString();
}
}