Search in sources :

Example 1 with WfsSourceConfigurationField

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;
}
Also used : XPath(javax.xml.xpath.XPath) ReportWithResultImpl(org.codice.ddf.admin.common.report.ReportWithResultImpl) XPathExpressionException(javax.xml.xpath.XPathExpressionException) SourceConfigUnionField(org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField) Document(org.w3c.dom.Document) SourceUtilCommons.createDocument(org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.createDocument) WfsSourceConfigurationField(org.codice.ddf.admin.sources.fields.type.WfsSourceConfigurationField) XPathExpressionException(javax.xml.xpath.XPathExpressionException)

Example 2 with WfsSourceConfigurationField

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;
}
Also used : WfsSourceConfigurationField(org.codice.ddf.admin.sources.fields.type.WfsSourceConfigurationField)

Aggregations

WfsSourceConfigurationField (org.codice.ddf.admin.sources.fields.type.WfsSourceConfigurationField)2 XPath (javax.xml.xpath.XPath)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 ReportWithResultImpl (org.codice.ddf.admin.common.report.ReportWithResultImpl)1 SourceUtilCommons.createDocument (org.codice.ddf.admin.sources.commons.utils.SourceUtilCommons.createDocument)1 SourceConfigUnionField (org.codice.ddf.admin.sources.fields.type.SourceConfigUnionField)1 Document (org.w3c.dom.Document)1