aboutsummaryrefslogtreecommitdiffstats
path: root/so-monitoring/so-monitoring-handler
diff options
context:
space:
mode:
Diffstat (limited to 'so-monitoring/so-monitoring-handler')
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java49
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java87
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java28
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java85
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java4
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java36
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java37
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java37
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java33
-rw-r--r--so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java119
-rw-r--r--so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java2
-rw-r--r--so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java12
-rw-r--r--so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java19
13 files changed, 45 insertions, 503 deletions
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java
deleted file mode 100644
index 34afd825cb..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/BasicAuthorizationHttpRequestInterceptor.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.configuration.rest;
-
-import java.io.IOException;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpRequest;
-import org.springframework.http.client.ClientHttpRequestExecution;
-import org.springframework.http.client.ClientHttpRequestInterceptor;
-import org.springframework.http.client.ClientHttpResponse;
-
-/**
- * @author waqas.ikram@ericsson.com
- *
- */
-public class BasicAuthorizationHttpRequestInterceptor implements ClientHttpRequestInterceptor {
-
- private final String authorization;
-
- public BasicAuthorizationHttpRequestInterceptor(final String authorization) {
- this.authorization = authorization;
- }
-
- @Override
- public ClientHttpResponse intercept(final HttpRequest request, final byte[] body,
- final ClientHttpRequestExecution execution) throws IOException {
- final HttpHeaders headers = request.getHeaders();
- headers.add("Authorization", authorization);
- return execution.execute(request, body);
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java
deleted file mode 100644
index 1260e535a1..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpClientConnectionConfiguration.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.configuration.rest;
-
-import java.util.concurrent.TimeUnit;
-
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Service;
-
-@Service
-public class HttpClientConnectionConfiguration {
-
- @Value(value = "${rest.http.client.configuration.connTimeOutInSec:10}")
- private int connectionTimeOutInSeconds;
-
- @Value(value = "${rest.http.client.configuration.socketTimeOutInSec:180}")
- private int socketTimeOutInSeconds;
-
- @Value(value = "${rest.http.client.configuration.socketTimeOutInSec:600}")
- private int timeToLiveInSeconds;
-
- @Value(value = "${rest.http.client.configuration.maxConnections:10}")
- private int maxConnections;
-
- @Value(value = "${rest.http.client.configuration.maxConnectionsPerRoute:2}")
- private int maxConnectionsPerRoute;
-
- /**
- * @return the socketTimeOut
- */
- public int getSocketTimeOutInMiliSeconds() {
- return (int) TimeUnit.SECONDS.toMillis(socketTimeOutInSeconds);
- }
-
- /**
- * @return the maxConnections
- */
- public int getMaxConnections() {
- return maxConnections;
- }
-
- /**
- * @return the maxConnectionsPerRoute
- */
- public int getMaxConnectionsPerRoute() {
- return maxConnectionsPerRoute;
- }
-
- /**
- * @return the connectionTimeOut
- */
- public int getConnectionTimeOutInMilliSeconds() {
- return (int) TimeUnit.SECONDS.toMillis(connectionTimeOutInSeconds);
- }
-
- /**
- * @return the timeToLive
- */
- public int getTimeToLiveInMins() {
- return (int) TimeUnit.SECONDS.toMinutes(timeToLiveInSeconds);
- }
-
- @Override
- public String toString() {
- return "HttpClientConnectionConfiguration [connectionTimeOutInSeconds=" + connectionTimeOutInSeconds
- + ", socketTimeOutInSeconds=" + socketTimeOutInSeconds + ", timeToLiveInSeconds=" + timeToLiveInSeconds
- + ", maxConnections=" + maxConnections + ", maxConnectionsPerRoute=" + maxConnectionsPerRoute + "]";
- }
-
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java
index a590d7908f..11c4d1b4f4 100644
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java
+++ b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/HttpServiceProviderConfiguration.java
@@ -19,17 +19,17 @@
*/
package org.onap.so.monitoring.configuration.rest;
-import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.CAMUNDA_REST_TEMPLATE;
-import static org.onap.so.monitoring.configuration.rest.RestTemplateConfiguration.DATABASE_REST_TEMPLATE;
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProviderImpl;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+import org.onap.so.configuration.rest.HttpHeadersProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.web.client.RestTemplate;
/**
@@ -45,28 +45,22 @@ public class HttpServiceProviderConfiguration {
@Bean
@Qualifier(CAMUNDA_HTTP_REST_SERVICE_PROVIDER)
public HttpRestServiceProvider camundaHttpRestServiceProvider(
- @Qualifier(CAMUNDA_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
@Value(value = "${camunda.rest.api.auth:#{null}}") final String authorization) {
- return getHttpRestServiceProvider(restTemplate, authorization);
+ return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider(authorization));
}
@Bean
@Qualifier(DATABASE_HTTP_REST_SERVICE_PROVIDER)
public HttpRestServiceProvider databaseHttpRestServiceProvider(
- @Qualifier(DATABASE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate,
@Value(value = "${mso.database.rest.api.auth:#{null}}") final String authorization) {
-
- return getHttpRestServiceProvider(restTemplate, authorization);
+ return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider(authorization));
}
private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate,
- final String authorization) {
- if (authorization != null && !authorization.isEmpty()) {
- final ClientHttpRequestInterceptor authorizationInterceptor =
- new BasicAuthorizationHttpRequestInterceptor(authorization);
- restTemplate.getInterceptors().add(authorizationInterceptor);
- }
- return new HttpRestServiceProviderImpl(restTemplate);
+ final HttpHeadersProvider httpHeadersProvider) {
+ return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider);
}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java
deleted file mode 100644
index f8f0f687cf..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/RestTemplateConfiguration.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.monitoring.configuration.rest;
-
-import java.util.concurrent.TimeUnit;
-
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.web.client.RestTemplate;
-
-/**
- * @author waqas.ikram@ericsson.com
- */
-@Configuration
-public class RestTemplateConfiguration {
-
- public static final String DATABASE_REST_TEMPLATE = "databaseRestTemplate";
-
- public static final String CAMUNDA_REST_TEMPLATE = "camundaRestTemplate";
-
- @Autowired
- private HttpClientConnectionConfiguration clientConnectionConfiguration;
-
- @Bean
- @Qualifier(CAMUNDA_REST_TEMPLATE)
- public RestTemplate camundaRestTemplate() {
- return new RestTemplate(httpComponentsClientHttpRequestFactory());
- }
-
- @Bean
- @Qualifier(DATABASE_REST_TEMPLATE)
- public RestTemplate dataBasecamundaRestTemplate() {
- return new RestTemplate(httpComponentsClientHttpRequestFactory());
- }
-
- @Bean
- public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory() {
- return new HttpComponentsClientHttpRequestFactory(httpClient());
- }
-
- @Bean
- public CloseableHttpClient httpClient() {
- return HttpClientBuilder.create().setConnectionManager(poolingHttpClientConnectionManager())
- .setMaxConnPerRoute(clientConnectionConfiguration.getMaxConnectionsPerRoute())
- .setMaxConnTotal(clientConnectionConfiguration.getMaxConnections())
- .setDefaultRequestConfig(requestConfig()).build();
- }
-
- @Bean
- public PoolingHttpClientConnectionManager poolingHttpClientConnectionManager() {
- return new PoolingHttpClientConnectionManager(clientConnectionConfiguration.getTimeToLiveInMins(),
- TimeUnit.MINUTES);
- }
-
- @Bean
- public RequestConfig requestConfig() {
- return RequestConfig.custom().setSocketTimeout(clientConnectionConfiguration.getSocketTimeOutInMiliSeconds())
- .setConnectTimeout(clientConnectionConfiguration.getConnectionTimeOutInMilliSeconds()).build();
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java
index 6be6367302..49e3d4f92f 100644
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java
+++ b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/db/service/DatabaseServiceProviderImpl.java
@@ -30,7 +30,7 @@ import org.onap.so.monitoring.camunda.model.SoActiveInfraRequests;
import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider;
import org.onap.so.monitoring.model.SoInfraRequest;
import org.onap.so.monitoring.model.SoInfraRequestBuilder;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@@ -60,7 +60,7 @@ public class DatabaseServiceProviderImpl implements DatabaseServiceProvider {
final String url = urlProvider.getSearchUrl(startTime, endTime, maxResult);
final Optional<SoActiveInfraRequests[]> optionalRequests =
- httpRestServiceProvider.postHttpRequest(filters, url, SoActiveInfraRequests[].class);
+ httpRestServiceProvider.post(filters, url, SoActiveInfraRequests[].class);
if (optionalRequests.isPresent()) {
return getSoInfraRequest(optionalRequests.get());
}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java
deleted file mode 100644
index 4d3c489fa9..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/InvalidRestRequestException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.exception;
-
-/**
- * @author waqas.ikram@ericsson.com
- *
- */
-public class InvalidRestRequestException extends RuntimeException {
- private static final long serialVersionUID = -1158414939006977465L;
-
- public InvalidRestRequestException(final String message) {
- super(message);
- }
-
- public InvalidRestRequestException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java
deleted file mode 100644
index ab25854542..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/exception/RestProcessingException.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.exception;
-
-/**
- * @author waqas.ikram@ericsson.com
- *
- */
-public class RestProcessingException extends RuntimeException {
-
- private static final long serialVersionUID = 16862313537198441L;
-
- public RestProcessingException(final String message) {
- super(message);
- }
-
- public RestProcessingException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java
index e6fbb68456..b7a439fc28 100644
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java
+++ b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderImpl.java
@@ -35,15 +35,15 @@ import org.onap.so.monitoring.model.ProcessDefinitionDetail;
import org.onap.so.monitoring.model.ProcessInstanceDetail;
import org.onap.so.monitoring.model.ProcessInstanceIdDetail;
import org.onap.so.monitoring.model.ProcessInstanceVariableDetail;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.google.common.base.Optional;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* @author waqas.ikram@ericsson.com
*/
@@ -64,13 +64,12 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
@Override
public Optional<ProcessInstanceIdDetail> getProcessInstanceIdDetail(final String requestId) {
final String url = urlProvider.getHistoryProcessInstanceUrl(requestId);
- final Optional<ProcessInstance[]> processInstances =
- httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class);
+ final Optional<ProcessInstance[]> processInstances = httpRestServiceProvider.get(url, ProcessInstance[].class);
if (processInstances.isPresent()) {
final ProcessInstance[] instances = processInstances.get();
- final String message = "found process instance for request id: " + requestId +
- ", result size: " + instances.length;
+ final String message =
+ "found process instance for request id: " + requestId + ", result size: " + instances.length;
LOGGER.debug(message);
if (instances.length > 0) {
@@ -79,8 +78,8 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
if (processInstance.getSuperProcessInstanceId() == null) {
return Optional.of(new ProcessInstanceIdDetail(processInstance.getId()));
}
- LOGGER.debug("found sub process instance id with super process instanceId: " +
- processInstance.getSuperProcessInstanceId());
+ LOGGER.debug("found sub process instance id with super process instanceId: "
+ + processInstance.getSuperProcessInstanceId());
}
}
}
@@ -91,8 +90,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
@Override
public Optional<ProcessInstanceDetail> getSingleProcessInstanceDetail(final String processInstanceId) {
final String url = urlProvider.getSingleProcessInstanceUrl(processInstanceId);
- final Optional<ProcessInstance> processInstances =
- httpRestServiceProvider.getHttpResponse(url, ProcessInstance.class);
+ final Optional<ProcessInstance> processInstances = httpRestServiceProvider.get(url, ProcessInstance.class);
if (processInstances.isPresent()) {
final ProcessInstance processInstance = processInstances.get();
@@ -111,8 +109,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
@Override
public Optional<ProcessDefinitionDetail> getProcessDefinition(final String processDefinitionId) {
final String url = urlProvider.getProcessDefinitionUrl(processDefinitionId);
- final Optional<ProcessDefinition> response =
- httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class);
+ final Optional<ProcessDefinition> response = httpRestServiceProvider.get(url, ProcessDefinition.class);
if (response.isPresent()) {
final ProcessDefinition processDefinition = response.get();
final String xmlDefinition = processDefinition.getBpmn20Xml();
@@ -120,16 +117,14 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
return Optional.of(new ProcessDefinitionDetail(processDefinitionId, xmlDefinition));
}
}
- LOGGER.error("Unable to find process definition for processDefinitionId: " +
- processDefinitionId);
+ LOGGER.error("Unable to find process definition for processDefinitionId: " + processDefinitionId);
return Optional.absent();
}
@Override
public List<ActivityInstanceDetail> getActivityInstance(final String processInstanceId) {
final String url = urlProvider.getActivityInstanceUrl(processInstanceId);
- final Optional<ActivityInstance[]> response =
- httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class);
+ final Optional<ActivityInstance[]> response = httpRestServiceProvider.get(url, ActivityInstance[].class);
if (response.isPresent()) {
final ActivityInstance[] activityInstances = response.get();
final List<ActivityInstanceDetail> activityInstanceDetails = new ArrayList<>(activityInstances.length);
@@ -148,8 +143,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
}
return activityInstanceDetails;
}
- LOGGER.error("Unable to find activity intance detail for process instance id: " +
- processInstanceId);
+ LOGGER.error("Unable to find activity intance detail for process instance id: " + processInstanceId);
return Collections.emptyList();
}
@@ -157,7 +151,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
public List<ProcessInstanceVariableDetail> getProcessInstanceVariable(final String processInstanceId) {
final String url = urlProvider.getProcessInstanceVariablesUrl(processInstanceId);
final Optional<ProcessInstanceVariable[]> response =
- httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class);
+ httpRestServiceProvider.get(url, ProcessInstanceVariable[].class);
if (response.isPresent()) {
final ProcessInstanceVariable[] instanceVariables = response.get();
final List<ProcessInstanceVariableDetail> instanceVariableDetails =
@@ -171,8 +165,7 @@ public class CamundaProcessDataServiceProviderImpl implements CamundaProcessData
}
return instanceVariableDetails;
}
- LOGGER.error("Unable to find process intance variable details for process instance id: "
- + processInstanceId);
+ LOGGER.error("Unable to find process intance variable details for process instance id: " + processInstanceId);
return Collections.emptyList();
}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java
deleted file mode 100644
index 4606c04e05..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProvider.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.rest.service;
-
-import com.google.common.base.Optional;
-
-/**
- * @author waqas.ikram@ericsson.com
- */
-public interface HttpRestServiceProvider {
-
- public <T> Optional<T> getHttpResponse(final String url, final Class<T> clazz);
-
- public <T> Optional<T> postHttpRequest(final Object object, final String url, final Class<T> clazz);
-
-}
diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java
deleted file mode 100644
index 82a54c10a2..0000000000
--- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/rest/service/HttpRestServiceProviderImpl.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. 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.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-package org.onap.so.monitoring.rest.service;
-
-import org.onap.so.monitoring.exception.InvalidRestRequestException;
-import org.onap.so.monitoring.exception.RestProcessingException;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.HttpClientErrorException;
-import org.springframework.web.client.RestClientException;
-import org.springframework.web.client.RestTemplate;
-
-import com.google.common.base.Optional;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * @author waqas.ikram@ericsson.com
- */
-public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(HttpRestServiceProviderImpl.class);
- private final RestTemplate restTemplate;
-
- public HttpRestServiceProviderImpl(final RestTemplate restTemplate) {
- this.restTemplate = restTemplate;
- }
-
- @Override
- public <T> Optional<T> getHttpResponse(final String url, final Class<T> clazz) {
- LOGGER.trace("Will invoke HTTP GET using URL: " + url);
- try {
- final ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, null, clazz);
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- final String message = "Unable to invoke HTTP GET using URL: " + url +
- ", Response Code: " + response.getStatusCode();
- LOGGER.error(message);
- return Optional.absent();
- }
-
- if (response.hasBody()) {
- return Optional.of(response.getBody());
- }
- } catch (final HttpClientErrorException httpClientErrorException) {
- final String message = "Unable to invoke HTTP GET using url: " + url + ", Response: " +
- httpClientErrorException.getRawStatusCode();
- LOGGER.error(message, httpClientErrorException);
- final int rawStatusCode = httpClientErrorException.getRawStatusCode();
- if (rawStatusCode == HttpStatus.BAD_REQUEST.value() || rawStatusCode == HttpStatus.NOT_FOUND.value()) {
- throw new InvalidRestRequestException("No result found for given url: " + url);
- }
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " + url);
-
- } catch (final RestClientException restClientException) {
- LOGGER.error("Unable to invoke HTTP GET using url: " + url, restClientException);
- throw new RestProcessingException("Unable to invoke HTTP GET using URL: " +
- url, restClientException);
- }
-
- return Optional.absent();
- }
-
- @Override
- public <T> Optional<T> postHttpRequest(final Object object, final String url, final Class<T> clazz) {
- try {
- final HttpEntity<?> request = new HttpEntity<>(object);
- final ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.POST, request, clazz);
- if (!response.getStatusCode().equals(HttpStatus.OK)) {
- final String message = "Unable to invoke HTTP GET using URL: " + url +
- ", Response Code: " + response.getStatusCode();
- LOGGER.error(message);
- return Optional.absent();
- }
-
- if (response.hasBody()) {
- return Optional.of(response.getBody());
- }
-
- } catch (final HttpClientErrorException httpClientErrorException) {
- final String message = "Unable to invoke HTTP POST using url: " + url +
- ", Response: " + httpClientErrorException.getRawStatusCode();
- LOGGER.error(message, httpClientErrorException);
- final int rawStatusCode = httpClientErrorException.getRawStatusCode();
- if (rawStatusCode == HttpStatus.BAD_REQUEST.value() || rawStatusCode == HttpStatus.NOT_FOUND.value()) {
- throw new InvalidRestRequestException("No result found for given url: " + url);
- }
- throw new RestProcessingException("Unable to invoke HTTP POST using URL: " + url);
-
- } catch (final RestClientException restClientException) {
- LOGGER.error("Unable to invoke HTTP POST using url: " + url, restClientException);
- throw new RestProcessingException("Unable to invoke HTTP POST using URL: "
- + url, restClientException);
- }
-
- return Optional.absent();
- }
-
-
-}
diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java
index 1b3e168c12..9df24c1921 100644
--- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java
+++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.onap.so.monitoring.configuration.rest.HttpServiceProviderConfiguration;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import org.springframework.web.client.RestTemplate;
/**
diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java
index 58666671a7..3a7ce18bf7 100644
--- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java
+++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java
@@ -38,7 +38,7 @@ import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider;
import org.onap.so.monitoring.db.service.DatabaseServiceProvider;
import org.onap.so.monitoring.db.service.DatabaseServiceProviderImpl;
import org.onap.so.monitoring.model.SoInfraRequest;
-import org.onap.so.monitoring.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import com.google.common.base.Optional;
@@ -57,8 +57,8 @@ public class DatabaseServiceProviderTest {
final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null);
final Optional<SoActiveInfraRequests[]> response = Optional.of(new SoActiveInfraRequests[] {});
- when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl),
- eq(SoActiveInfraRequests[].class))).thenReturn(response);
+ when(mockServiceProvider.post(eq(Collections.emptyMap()), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
+ .thenReturn(response);
final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider);
@@ -71,8 +71,8 @@ public class DatabaseServiceProviderTest {
final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null);
final Optional<SoActiveInfraRequests[]> response = Optional.absent();
- when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl),
- eq(SoActiveInfraRequests[].class))).thenReturn(response);
+ when(mockServiceProvider.post(eq(Collections.emptyMap()), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
+ .thenReturn(response);
final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider);
@@ -94,7 +94,7 @@ public class DatabaseServiceProviderTest {
final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class);
- when(mockServiceProvider.postHttpRequest(eq(filters), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
+ when(mockServiceProvider.post(eq(filters), eq(searchUrl), eq(SoActiveInfraRequests[].class)))
.thenReturn(response);
final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider);
diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java
index c3930df196..d21cf6d02b 100644
--- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java
+++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java
@@ -38,6 +38,7 @@ import org.onap.so.monitoring.model.ActivityInstanceDetail;
import org.onap.so.monitoring.model.ProcessDefinitionDetail;
import org.onap.so.monitoring.model.ProcessInstanceIdDetail;
import org.onap.so.monitoring.model.ProcessInstanceVariableDetail;
+import org.onap.so.rest.service.HttpRestServiceProvider;
import com.google.common.base.Optional;
@@ -65,7 +66,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessInstanceDetail_EmptyResponse() {
final Optional<ProcessInstance[]> response = Optional.<ProcessInstance[]>absent();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -77,7 +78,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNull() {
final Optional<ProcessInstance[]> response = Optional.of(getProcessInstance());
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -92,7 +93,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNotNull() {
final Optional<ProcessInstance[]> response = Optional.of(getProcessInstance(SUPER_PROCESS_ID));
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -105,7 +106,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessDefinition_EmptyResponse() {
final Optional<ProcessDefinition> response = Optional.<ProcessDefinition>absent();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + ID + "/xml";
- when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessDefinition.class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -117,7 +118,7 @@ public class CamundaProcessDataServiceProviderTest {
public void test_GetProcessDefinition_NonEmptyResponse() {
final Optional<ProcessDefinition> response = getProcessDefinition();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + PROCESS_ID + "/xml";
- when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessDefinition.class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -132,7 +133,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ActivityInstance[]> response = Optional.<ActivityInstance[]>absent();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID
+ "&sortBy=startTime&sortOrder=asc";
- when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ActivityInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -146,7 +147,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ActivityInstance[]> response = getActivityInstance();
final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID
+ "&sortBy=startTime&sortOrder=asc";
- when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ActivityInstance[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -164,7 +165,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ProcessInstanceVariable[]> response = Optional.<ProcessInstanceVariable[]>absent();
final String url =
CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstanceVariable[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);
@@ -178,7 +179,7 @@ public class CamundaProcessDataServiceProviderTest {
final Optional<ProcessInstanceVariable[]> response = getProcessInstanceVariable();
final String url =
CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID;
- when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response);
+ when(httpRestServiceProvider.get(url, ProcessInstanceVariable[].class)).thenReturn(response);
final CamundaProcessDataServiceProvider objUnderTest =
new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider);