use of org.codice.ddf.admin.common.report.ReportWithResultImpl in project admin-console-beta by connexta.
the class RequestUtils method executeGetRequest.
/**
* Executes a request by creating a Secure CXF Client from the provided url, credentials, and query params.
*
* Possible Error Codes to return
* - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#CANNOT_CONNECT}
*
* @param clientUrl url to send GET request to
* @param creds optional basic authentication
* @param queryParams additional query parameters
* @return {@link Response} of the request
*/
public ReportWithResultImpl<Response> executeGetRequest(UrlField clientUrl, CredentialsField creds, Map<String, String> queryParams) {
WebClient client = generateClient(clientUrl.getValue(), creds, queryParams);
ReportWithResultImpl<Response> report = new ReportWithResultImpl<>();
Response response;
try {
response = client.get();
} catch (ProcessingException e) {
report.addResultMessage(cannotConnectError());
return report;
}
report.result(response);
return report;
}
use of org.codice.ddf.admin.common.report.ReportWithResultImpl in project admin-console-beta by connexta.
the class CswSourceUtils method getPreferredCswConfig.
/**
* Attempts to create a CSW configuration from the given url.
*
* Possible Error Codes to be returned
* - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#CANNOT_CONNECT}
* - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#UNAUTHORIZED}
* - {@link org.codice.ddf.admin.common.report.message.DefaultMessages#UNKNOWN_ENDPOINT}
*
* @param urlField A URL of an endpoint with CSW capabilities
* @param creds optional credentials for basic authentication
* @return a {@link ReportWithResultImpl} containing the {@link SourceConfigUnionField} or an {@link org.codice.ddf.admin.common.report.message.ErrorMessage} on failure.
*/
public ReportWithResultImpl<SourceConfigUnionField> getPreferredCswConfig(UrlField urlField, CredentialsField creds) {
ReportWithResultImpl<String> responseBodyResult = requestUtils.sendGetRequest(urlField, creds, GET_CAPABILITIES_PARAMS);
ReportWithResultImpl<SourceConfigUnionField> configResult = new ReportWithResultImpl<>();
if (responseBodyResult.containsErrorMsgs()) {
configResult.addMessages(responseBodyResult);
return configResult;
}
String requestBody = responseBodyResult.result();
Document capabilitiesXml;
try {
capabilitiesXml = createDocument(requestBody);
} catch (Exception e) {
LOGGER.debug("Failed to create XML document from response.");
configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
return configResult;
}
CswSourceConfigurationField preferred = new CswSourceConfigurationField();
preferred.endpointUrl(urlField.getValue()).credentials().username(creds.username()).password(FLAG_PASSWORD);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(SOURCES_NAMESPACE_CONTEXT);
try {
if ((Boolean) xpath.compile(HAS_CATALOG_METACARD_EXP).evaluate(capabilitiesXml, XPathConstants.BOOLEAN)) {
configResult.result(preferred.outputSchema(METACARD_OUTPUT_SCHEMA).cswProfile(CSW_FEDERATION_PROFILE_SOURCE));
return configResult;
}
} catch (Exception e) {
LOGGER.debug("Failed to compile DDF Profile CSW discovery XPath expression.");
}
try {
if ((Boolean) xpath.compile(HAS_GMD_ISO_EXP).evaluate(capabilitiesXml, XPathConstants.BOOLEAN)) {
configResult.result(preferred.outputSchema(GMD_OUTPUT_SCHEMA).cswProfile(GMD_CSW_ISO_FEDERATED_SOURCE));
return configResult;
}
} catch (Exception e) {
LOGGER.debug("Failed to compile GMD CSW discovery XPath expression.");
}
try {
xpath.compile(GET_FIRST_OUTPUT_SCHEMA).evaluate(capabilitiesXml);
configResult.result(preferred.outputSchema(CSW_2_0_2_OUTPUT_SCHEMA).cswProfile(CSW_SPEC_PROFILE_FEDERATED_SOURCE));
return configResult;
} catch (Exception e) {
LOGGER.debug("Failed to compile generic CSW specification discovery XPath expression.");
}
LOGGER.debug("URL [{}] responded to GetCapabilities request, but response was not readable.", urlField.getValue());
configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
return configResult;
}
Aggregations