diff options
author | lapentafd <francesco.lapenta@est.tech> | 2021-10-18 10:06:31 +0100 |
---|---|---|
committer | lapentafd <francesco.lapenta@est.tech> | 2021-10-19 12:36:29 +0100 |
commit | 06ea4844bddd197796933775faf8999612daa63d (patch) | |
tree | 09dfa971b72206edb84b217ed5903bfd83c7c7c2 /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main | |
parent | 5db2ed027f3f17be19cb1ff6850129af7525d5d5 (diff) |
HTTP code filter for RestClientProducer
RestClient producer can now consider 2xx response status as success
Issue-ID: POLICY-3743
Change-Id: I40c4dce01b437ea6b9f9bbc317835657cb7ebc8a
Signed-off-by: lapentafd <francesco.lapenta@est.tech>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main')
2 files changed, 12 insertions, 8 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java index 956345cd4..899d4de11 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java @@ -75,7 +75,6 @@ public class ApexRestClientConsumer extends ApexPluginsEventConsumer { if (!(consumerParameters.getCarrierTechnologyParameters() instanceof RestClientCarrierTechnologyParameters)) { final String errorMessage = "specified consumer properties are not applicable to REST client consumer (" + this.name + ")"; - LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } restConsumerProperties = @@ -92,7 +91,6 @@ public class ApexRestClientConsumer extends ApexPluginsEventConsumer { final String errorMessage = "specified HTTP method of \"" + restConsumerProperties.getHttpMethod() + "\" is invalid, only HTTP method \"GET\" " + "is supported for event reception on REST client consumer (" + this.name + ")"; - LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } @@ -157,7 +155,6 @@ public class ApexRestClientConsumer extends ApexPluginsEventConsumer { final String errorMessage = "reception of event from URL \"" + restConsumerProperties.getUrl() + "\" failed with status code " + response.getStatus() + " and message \"" + response.readEntity(String.class) + "\""; - LOGGER.warn(errorMessage); throw new ApexEventRuntimeException(errorMessage); } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java index 035bd6524..15b6dd3dd 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -26,6 +26,7 @@ package org.onap.policy.apex.plugins.event.carrier.restclient; import java.util.Optional; import java.util.Properties; import java.util.Set; +import java.util.regex.Pattern; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; @@ -59,6 +60,8 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { // The REST carrier properties private RestClientCarrierTechnologyParameters restProducerProperties; + private Pattern httpCodeFilterPattern = null; + /** * {@inheritDoc}. */ @@ -71,12 +74,13 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { if (!(producerParameters.getCarrierTechnologyParameters() instanceof RestClientCarrierTechnologyParameters)) { final String errorMessage = "specified producer properties are not applicable to REST client producer (" + this.name + ")"; - LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } restProducerProperties = (RestClientCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + this.httpCodeFilterPattern = Pattern.compile(restProducerProperties.getHttpCodeFilter()); + // Check if the HTTP method has been set if (restProducerProperties.getHttpMethod() == null) { restProducerProperties.setHttpMethod(RestPluginCarrierTechnologyParameters.HttpMethod.POST); @@ -88,7 +92,6 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { final String errorMessage = "specified HTTP method of \"" + restProducerProperties.getHttpMethod() + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supported " + "for event sending on REST client producer (" + this.name + ")"; - LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } @@ -128,8 +131,12 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer { NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, untaggedUrl, response.readEntity(String.class)); - // Check that the request worked - if (response.getStatus() != Response.Status.OK.getStatusCode()) { + + // Match the return code + var isPass = httpCodeFilterPattern.matcher(String.valueOf(response.getStatus())); + + // Check that status code + if (!isPass.matches()) { final String errorMessage = "send of event to URL \"" + untaggedUrl + "\" using HTTP \"" + restProducerProperties.getHttpMethod() + "\" failed with status code " + response.getStatus(); throw new ApexEventRuntimeException(errorMessage); |