use of org.codice.ddf.admin.sources.fields.type.WfsSourceConfigurationField in project admin-console-beta by connexta.
the class WfsSourceUtils method getPreferredWfsConfig.
/**
* Attempts to create a WFS 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 WFS URL to probe for a configuration
* @param creds optional username to add to Basic Auth header
* @return a {@link ReportWithResultImpl} containing the preferred {@link SourceConfigUnionField}, or containing {@link org.codice.ddf.admin.common.report.message.ErrorMessage}s on failure.
*/
public ReportWithResultImpl<SourceConfigUnionField> getPreferredWfsConfig(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 read response from WFS endpoint.");
configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
return configResult;
}
WfsSourceConfigurationField preferredConfig = new WfsSourceConfigurationField();
preferredConfig.endpointUrl(urlField.getValue()).credentials().username(creds.username()).password(FLAG_PASSWORD);
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(SOURCES_NAMESPACE_CONTEXT);
String wfsVersion;
try {
wfsVersion = xpath.compile(WFS_VERSION_EXP).evaluate(capabilitiesXml);
} catch (XPathExpressionException e) {
LOGGER.debug("Failed to parse XML response.");
configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
return configResult;
}
try {
configResult.result(preferredConfig.wfsVersion(wfsVersion));
} catch (IllegalArgumentException e) {
configResult.addArgumentMessage(unknownEndpointError(urlField.path()));
}
return configResult;
}
use of org.codice.ddf.admin.sources.fields.type.WfsSourceConfigurationField in project admin-console-beta by connexta.
the class WfsServiceProperties method servicePropsToWfsConfig.
public static WfsSourceConfigurationField servicePropsToWfsConfig(Map<String, Object> props) {
WfsSourceConfigurationField wfsConfig = new WfsSourceConfigurationField();
wfsConfig.pid(mapValue(props, SERVICE_PID_KEY));
wfsConfig.sourceName(mapValue(props, ID));
wfsConfig.endpointUrl(mapValue(props, WFS_URL));
wfsConfig.credentials().username(mapValue(props, USERNAME));
wfsConfig.credentials().password(FLAG_PASSWORD);
wfsConfig.wfsVersion(wfsFactoryPidToVersion(mapValue(props, FACTORY_PID_KEY)));
return wfsConfig;
}
Aggregations