"url": "http://172.18.0.6:8081/pdp/api/getDecision",
"httpMethod": "POST",
"restRequestTimeout": 2000,
- "httpHeader": "Authorization:dGVzdHBkcDphbHBoYTEyMw== ClientAuth:cHl0aG9uOnRlc3Q="
+ "httpHeaders": [
+ ["Authorization:dGVzdHBkcDphbHBoYTEyMw== ClientAuth:cHl0aG9uOnRlc3Q="]
+ ]
}
},
"eventProtocolParameters": {
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
+import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.ValidationStatus;
// @formatter:off
/**
this.setEventProducerPluginClass(ApexRestClientProducer.class.getName());
this.setEventConsumerPluginClass(ApexRestClientConsumer.class.getName());
}
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public GroupValidationResult validateUrl(final GroupValidationResult result) {
+ // Check if the URL has been set for event output
+ final String urlNullMessage = "no URL has been set for event sending on " + getLabel();
+ if (getUrl() == null) {
+ result.setResult("url", ValidationStatus.INVALID, urlNullMessage);
+ return result;
+ }
+
+ return super.validateUrl(result);
+ }
}
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
-import java.util.regex.Matcher;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
-import org.onap.policy.common.parameters.ValidationStatus;
// @formatter:off
/**
this.setEventProducerPluginClass(ApexRestRequestorProducer.class.getName());
this.setEventConsumerPluginClass(ApexRestRequestorConsumer.class.getName());
}
-
- // @formatter:off
- /**
- * Validate the URL.
- *
- * <p>Checks:
- * http://www.blah.com/{par1/somethingelse (Missing end tag) use {[^\\{}]*$
- * http://www.blah.com/{par1/{some}thingelse (Nested tag) use {[^}]*{
- * http://www.blah.com/{par1}/some}thingelse (Missing start tag1) use }[^{}]*.}
- * http://www.blah.com/par1}/somethingelse (Missing start tag2) use }[^{}]*}
- * http://www.blah.com/{}/somethingelse (Empty tag) use {[\s]*}
- * @param result the result of the validation
- */
- // @formatter:on
- @Override
- public GroupValidationResult validateUrl(final GroupValidationResult result) {
- // URL is only set on Requestor consumers
- if (getUrl() == null) {
- return result;
- }
-
- Matcher matcher = patternErrorKey.matcher(getUrl());
- if (matcher.find()) {
- result.setResult("url", ValidationStatus.INVALID,
- "no proper URL has been set for event sending on REST requestor");
- }
-
- return result;
- }
}
private static final Logger LOGGER = LoggerFactory.getLogger(RestPluginCarrierTechnologyParameters.class);
/** The supported HTTP methods. */
+ // @formatter:off
public enum HttpMethod {
GET,
PUT,
POST,
DELETE
}
+ // @formatter:on
/** The default HTTP code filter, allows 2xx HTTP codes through. */
public static final String DEFAULT_HTTP_CODE_FILTER = "[2][0-9][0-9]";
// Regular expression patterns for finding and checking keys in URLs
private static final Pattern patternProperKey = Pattern.compile("(?<=\\{)[^}]*(?=\\})");
- protected static final Pattern patternErrorKey =
- Pattern.compile("(\\{[^\\{}]*.?\\{)|(\\{[^\\{}]*$)|(\\}[^\\{}]*.?\\})|(^[^\\{}]*.?\\})|\\{\\s*\\}");
+ protected static final Pattern patternErrorKey = Pattern
+ .compile("(\\{[^\\{}]*.?\\{)|(\\{[^\\{}]*$)|(\\}[^\\{}]*.?\\})|(^[^\\{}]*.?\\})|\\{\\s*\\}");
// variable
protected String url = null;
protected String httpCodeFilter = DEFAULT_HTTP_CODE_FILTER;
/**
- * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter
- * service.
+ * Constructor to create a REST carrier technology parameters instance and
+ * register the instance with the parameter service.
*/
public RestPluginCarrierTechnologyParameters() {
super();
*/
// @formatter:on
public GroupValidationResult validateUrl(final GroupValidationResult result) {
- // Check if the URL has been set for event output
- String urlErrorMessage = "no URL has been set for event sending on " + getLabel();
+ // The URL may be optional so existence must be checked in the plugin code
if (getUrl() == null) {
- result.setResult("url", ValidationStatus.INVALID, urlErrorMessage);
return result;
}
Matcher matcher = patternErrorKey.matcher(getUrl());
if (matcher.find()) {
- result.setResult("url", ValidationStatus.INVALID, urlErrorMessage);
+ final String urlInvalidMessage = "invalid URL " + getUrl() + " has been set for event sending on "
+ + getLabel();
+ result.setResult("url", ValidationStatus.INVALID, urlInvalidMessage);
}
return result;
result.setResult(HTTP_HEADERS, ValidationStatus.INVALID, "HTTP header array entry is null");
} else if (httpHeader.length != 2) {
result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
- "HTTP header array entries must have one key and one value: "
- + Arrays.deepToString(httpHeader));
+ "HTTP header array entries must have one key and one value: " + Arrays.deepToString(httpHeader));
} else if (!ParameterValidationUtils.validateStringParameter(httpHeader[0])) {
result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
- "HTTP header key is null or blank: " + Arrays.deepToString(httpHeader));
+ "HTTP header key is null or blank: " + Arrays.deepToString(httpHeader));
} else if (!ParameterValidationUtils.validateStringParameter(httpHeader[1])) {
result.setResult(HTTP_HEADERS, ValidationStatus.INVALID,
- "HTTP header value is null or blank: " + Arrays.deepToString(httpHeader));
+ "HTTP header value is null or blank: " + Arrays.deepToString(httpHeader));
}
}
} else if (StringUtils.isBlank(httpCodeFilter)) {
result.setResult(HTTP_CODE_FILTER, ValidationStatus.INVALID,
- "HTTP code filter must be specified as a three digit regular expression");
+ "HTTP code filter must be specified as a three digit regular expression");
} else {
try {
Pattern.compile(httpCodeFilter);
} catch (PatternSyntaxException pse) {
- String message =
- "Invalid HTTP code filter, the filter must be specified as a three digit regular expression: "
- + pse.getMessage();
+ String message = "Invalid HTTP code filter, the filter must be specified as a three digit "
+ + "regular expression: " + pse.getMessage();
result.setResult(HTTP_CODE_FILTER, ValidationStatus.INVALID, message);
LOGGER.debug(message, pse);
}
@Override
public String toString() {
return getLabel() + "CarrierTechnologyParameters [url=" + url + ", httpMethod=" + httpMethod + ", httpHeaders="
- + Arrays.deepToString(httpHeaders) + ", httpCodeFilter=" + httpCodeFilter + "]";
+ + Arrays.deepToString(httpHeaders) + ", httpCodeFilter=" + httpCodeFilter + "]";
}
}
@BeforeClass
public static void compilePolicy() {
// @formatter:off
- final String[] cliArgs = {
- "-c",
+ final String[] cliArgs = { "-c",
"src/test/resources/policies/executionproperties/policy/ExecutionPropertiesRestTestPolicyModel.apex",
"-l",
"target/ExecutionPropertiesRestTestPolicyModel.log",
}
server = HttpServletServerFactoryInstance.getServerFactory().build("TestExecutionPropertyRest", false, null,
- PORT, "/TestExecutionRest", false, false);
+ PORT, "/TestExecutionRest", false, false);
server.addServletClass(null, TestRestClientEndpoint.class.getName());
server.setSerializationProvider(GsonMessageBodyHandler.class.getName());
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
- final String[] args = {"src/test/resources/testdata/executionproperties/RESTEventBadUrl.json"};
+ final String[] args = { "src/test/resources/testdata/executionproperties/RESTEventBadUrl.json" };
final ApexMain apexMain = new ApexMain(args);
ThreadUtilities.sleep(500);
System.setErr(stderr);
LOGGER.info("testReplaceUrlTag-OUTSTRING=\n" + outString + "\nEnd-TagUrl");
- assertTrue(outString.contains("no URL has been set for event sending on RESTCLIENT"));
+ assertTrue(outString.contains("invalid URL http://localhost:32801/TestExecutionRest/apex/event/tagId}"
+ + " has been set for event sending on RESTCLIENT"));
}
/**
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
- final String[] args = {"src/test/resources/testdata/executionproperties/RESTEventNoValueSetForTag.json"};
+ final String[] args = { "src/test/resources/testdata/executionproperties/RESTEventNoValueSetForTag.json" };
final ApexMain apexMain = new ApexMain(args);
ThreadUtilities.sleep(2000);
LOGGER.info("testReplaceUrlTag-OUTSTRING=\n" + outString + "\nEnd-TagUrl");
assertTrue(outString.contains("key \"Number\" specified on url \"http://localhost:32801/TestExecutionRest/apex"
- + "/event/{tagId}/{Number}\" not found in execution properties passed by the current policy"));
+ + "/event/{tagId}/{Number}\" not found in execution properties passed by the current policy"));
}
/**
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
- final String[] args = {"src/test/resources/testdata/executionproperties/RESTEventBadHttpCodeFilter.json"};
+ final String[] args = { "src/test/resources/testdata/executionproperties/RESTEventBadHttpCodeFilter.json" };
final ApexMain apexMain = new ApexMain(args);
ThreadUtilities.sleep(500);
public void testReplaceUrlTag() throws Exception {
final Client client = ClientBuilder.newClient();
- final String[] args = {"src/test/resources/testdata/executionproperties/RESTHttpCodeFilterSetToTagUrlOK.json"};
+ final String[] args = {
+ "src/test/resources/testdata/executionproperties/RESTHttpCodeFilterSetToTagUrlOK.json" };
final ApexMain apexMain = new ApexMain(args);
ThreadUtilities.sleep(1000);
apexMain.shutdown();
Response response = null;
response = client.target("http://localhost:32801/TestExecutionRest/apex/event/GetProperUrl")
- .request("application/json").get();
+ .request("application/json").get();
LOGGER.info("testReplaceUrlTag-OUTSTRING=\n" + outString + "\nEnd-TagUrl");
final String responseEntity = response.readEntity(String.class);
final Client client = ClientBuilder.newClient();
// @formatter:off
final String[] args = {
- "src/test/resources/testdata/executionproperties/RESTHttpCodeFilterSetToMultiTagUrlOK.json"
- };
+ "src/test/resources/testdata/executionproperties/RESTHttpCodeFilterSetToMultiTagUrlOK.json" };
// @formatter:on
final ApexMain apexMain = new ApexMain(args);
ThreadUtilities.sleep(1500);
System.setErr(stderr);
Response response = null;
response = client.target("http://localhost:32801/TestExecutionRest/apex/event/GetProperUrl")
- .request("application/json").get();
+ .request("application/json").get();
final String responseEntity = response.readEntity(String.class);
LOGGER.info("testReplaceUrlMultiTag-OUTSTRING=\n" + responseEntity + "\nEnd-MultiTagUrl");
assertTrue(responseEntity.contains("\"PostProperUrl\": 3"));