use of org.codice.ddf.admin.common.fields.common.UrlField in project admin-console-beta by connexta.
the class RequestUtils method discoverUrlFromHost.
/**
* Takes a list of url formats, for example "https://%s:%d/wfs", formats them together with the
* hostField name and port, then sends GET requests to those URLs. If an HTTP 200 and response body is returned on one the the formatted
* URLs, then a {@link UrlField} whose value is the formatted URL is returned. The {@code UrlField} returned
* will have the same path and field name as the hostField passed in.
*
* Possible Error Codes to be returned
* - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#CANNOT_CONNECT}
*
* @param hostField host field containing the host name and port
* @param urlFormats list of url formats to format with the hostField
* @param creds credentials for basic authentication
* @param queryParams additional query params
* @return a {@code ReportWithResult} containing a {@code UrlField} on success, or {@link org.codice.ddf.admin.common.report.message.ErrorMessage}s on failure
*/
public ReportWithResultImpl<UrlField> discoverUrlFromHost(HostField hostField, List<String> urlFormats, CredentialsField creds, Map<String, String> queryParams) {
ReportWithResultImpl<UrlField> responseBody = new ReportWithResultImpl<>();
for (String formatUrl : urlFormats) {
UrlField clientUrl = new UrlField();
clientUrl.fieldName(hostField.fieldName());
// copy this hostField's path so that if it's used to make errors they have the path of the hostField
clientUrl.updatePath(hostField.path().subList(0, hostField.path().size() - 1));
clientUrl.setValue(String.format(formatUrl, hostField.name(), hostField.port()));
ReportWithResultImpl<String> body = sendGetRequest(clientUrl, creds, queryParams);
if (!body.containsErrorMsgs()) {
responseBody.result(clientUrl);
return responseBody;
}
}
return responseBody.addResultMessage(cannotConnectError());
}
Aggregations