Example usage for org.springframework.beans.factory.parsing Problem Problem

List of usage examples for org.springframework.beans.factory.parsing Problem Problem

Introduction

In this page you can find the example usage for org.springframework.beans.factory.parsing Problem Problem.

Prototype

public Problem(String message, Location location) 

Source Link

Document

Create a new instance of the Problem class.

Usage

From source file:fi.okm.mpass.shibboleth.profile.metadata.spring.DataSourceMetadataProviderParser.java

/** {@inheritDoc} */
@Override//from   w w  w  . j  av  a  2s . com
protected void doNativeParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    super.doNativeParse(element, parserContext, builder);

    if (element.hasAttributeNS(null, "dataSource")) {
        builder.addConstructorArgReference(
                StringSupport.trimOrNull(element.getAttributeNS(null, "dataSource")));
    } else {
        log.error("{}: dataSource configuration not found",
                parserContext.getReaderContext().getResource().getDescription());
        throw new BeanDefinitionParsingException(new Problem("dataSource configuration not found",
                new Location(parserContext.getReaderContext().getResource())));
    }
}

From source file:net.shibboleth.idp.profile.spring.relyingparty.metadata.impl.HTTPMetadataProviderParser.java

/** {@inheritDoc} */
// Checkstyle: CyclomaticComplexity OFF
@Override//from   w ww.j a v a 2  s  . c  o m
protected void doNativeParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doNativeParse(element, parserContext, builder);

    if (element.hasAttributeNS(null, "cacheDuration")) {
        log.error("{}: cacheDuration is not supported",
                parserContext.getReaderContext().getResource().getDescription());
        throw new BeanDefinitionParsingException(new Problem("cacheDuration is not supported",
                new Location(parserContext.getReaderContext().getResource())));
    }

    if (element.hasAttributeNS(null, "maintainExpiredMetadata")) {
        log.error("{}: maintainExpiredMetadata is not supported",
                parserContext.getReaderContext().getResource().getDescription());
        throw new BeanDefinitionParsingException(new Problem("maintainExpiredMetadata is not supported",
                new Location(parserContext.getReaderContext().getResource())));
    }

    boolean haveTLSTrustEngine = false;
    if (element.hasAttributeNS(null, "tlsTrustEngineRef")) {
        builder.addPropertyReference("tLSTrustEngine",
                StringSupport.trimOrNull(element.getAttributeNS(null, "tlsTrustEngineRef")));
        haveTLSTrustEngine = true;
    } else {
        BeanDefinition tlsTrustEngine = parseTLSTrustEngine(element, parserContext);
        if (tlsTrustEngine != null) {
            builder.addPropertyValue("tLSTrustEngine", tlsTrustEngine);
            haveTLSTrustEngine = true;
        }
    }

    if (element.hasAttributeNS(null, "httpClientRef")) {
        builder.addConstructorArgReference(
                StringSupport.trimOrNull(element.getAttributeNS(null, "httpClientRef")));
        if (element.hasAttributeNS(null, "requestTimeout")
                || element.hasAttributeNS(null, "disregardSslCertificate")
                || element.hasAttributeNS(null, "disregardTLSCertificate")
                || element.hasAttributeNS(null, "proxyHost") || element.hasAttributeNS(null, "proxyPort")
                || element.hasAttributeNS(null, "proxyUser") || element.hasAttributeNS(null, "proxyPassword")) {
            log.warn("httpClientRef overrides settings for requestTimeout, disregardSslCertificate, "
                    + "disregardTLSCertificate, proxyHost, proxyPort, proxyUser and proxyPassword");
        }
    } else {
        builder.addConstructorArgValue(buildHttpClient(element, parserContext, haveTLSTrustEngine));
    }
    builder.addConstructorArgValue(StringSupport.trimOrNull(element.getAttributeNS(null, METADATA_URL)));

    if (element.hasAttributeNS(null, BASIC_AUTH_USER) || element.hasAttributeNS(null, BASIC_AUTH_PASSWORD)) {
        builder.addPropertyValue("basicCredentials", buildBasicCredentials(element));
    }

}

From source file:net.shibboleth.idp.profile.spring.relyingparty.metadata.impl.AbstractDynamicHTTPMetadataProviderParser.java

/**
 * Build the definition of the HTTPClientBuilder which contains all our configuration.
 * // w  w w.  j a v a2  s . c o  m
 * @param element the HTTPMetadataProvider parser.
 * @param parserContext thee context
 * @param haveTLSTrustEngine whether have a TLS TrustEngine configured
 * @return the bean definition with the parameters.
 */
// Checkstyle: CyclomaticComplexity OFF
// Checkstyle: MethodLength OFF
private BeanDefinition buildHttpClient(Element element, ParserContext parserContext,
        boolean haveTLSTrustEngine) {
    String caching = DEFAULT_CACHING;
    if (element.hasAttributeNS(null, "httpCaching")) {
        caching = StringSupport.trimOrNull(element.getAttributeNS(null, "httpCaching"));
    }

    BeanDefinitionBuilder clientBuilder = null;
    switch (caching) {
    case "none":
        clientBuilder = BeanDefinitionBuilder.genericBeanDefinition(HttpClientFactoryBean.class);
        break;
    case "file":
        clientBuilder = BeanDefinitionBuilder.genericBeanDefinition(FileCachingHttpClientFactoryBean.class);
        if (element.hasAttributeNS(null, "httpCacheDirectory")) {
            clientBuilder.addPropertyValue("cacheDirectory",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpCacheDirectory")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntries")) {
            clientBuilder.addPropertyValue("maxCacheEntries",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntries")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntrySize")) {
            clientBuilder.addPropertyValue("maxCacheEntrySize",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntrySize")));
        }
        break;
    case "memory":
        clientBuilder = BeanDefinitionBuilder.genericBeanDefinition(InMemoryCachingHttpClientFactoryBean.class);
        if (element.hasAttributeNS(null, "httpMaxCacheEntries")) {
            clientBuilder.addPropertyValue("maxCacheEntries",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntries")));
        }
        if (element.hasAttributeNS(null, "httpMaxCacheEntrySize")) {
            clientBuilder.addPropertyValue("maxCacheEntrySize",
                    StringSupport.trimOrNull(element.getAttributeNS(null, "httpMaxCacheEntrySize")));
        }
        break;
    default:
        throw new BeanDefinitionParsingException(
                new Problem(String.format("Caching value '%s' is unsupported", caching),
                        new Location(parserContext.getReaderContext().getResource())));
    }

    clientBuilder.setLazyInit(true);

    if (element.hasAttributeNS(null, "requestTimeout")) {
        clientBuilder.addPropertyValue("connectionTimeout",
                StringSupport.trimOrNull(element.getAttributeNS(null, "requestTimeout")));
    }

    if (haveTLSTrustEngine) {
        clientBuilder.addPropertyValue("tLSSocketFactory", new SecurityEnhancedTLSSocketFactory(
                HttpClientSupport.buildNoTrustTLSSocketFactory(), new StrictHostnameVerifier()));
    }

    if (element.hasAttributeNS(null, "disregardTLSCertificate")) {
        clientBuilder.addPropertyValue("connectionDisregardTLSCertificate",
                StringSupport.trimOrNull(element.getAttributeNS(null, "disregardTLSCertificate")));
    } else if (element.hasAttributeNS(null, "disregardSslCertificate")) {
        log.warn("disregardSslCertificate is deprecated, please switch to disregardTLSCertificate");
        clientBuilder.addPropertyValue("connectionDisregardTLSCertificate",
                StringSupport.trimOrNull(element.getAttributeNS(null, "disregardSslCertificate")));
    }

    if (element.hasAttributeNS(null, "proxyHost")) {
        clientBuilder.addPropertyValue("connectionProxyHost",
                StringSupport.trimOrNull(element.getAttributeNS(null, "proxyHost")));
    }

    if (element.hasAttributeNS(null, "proxyPort")) {
        clientBuilder.addPropertyValue("connectionProxyPort",
                StringSupport.trimOrNull(element.getAttributeNS(null, "proxyPort")));
    }

    if (element.hasAttributeNS(null, "proxyUser")) {
        clientBuilder.addPropertyValue("connectionProxyUsername",
                StringSupport.trimOrNull(element.getAttributeNS(null, "proxyUser")));
    }

    if (element.hasAttributeNS(null, "proxyPassword")) {
        clientBuilder.addPropertyValue("connectionProxyPassword",
                element.getAttributeNS(null, "proxyPassword"));
    }

    return clientBuilder.getBeanDefinition();
}

From source file:grails.spring.BeanBuilder.java

/**
 * Defines a Spring namespace definition to use.
 *
 * @param definition The definition/*from   ww  w.j a  v  a 2 s .c o m*/
 */
public void xmlns(Map<String, String> definition) {
    Assert.notNull(namespaceHandlerResolver,
            "You cannot define a Spring namespace without a [namespaceHandlerResolver] set");
    if (definition.isEmpty()) {
        return;
    }

    for (Map.Entry<String, String> entry : definition.entrySet()) {
        String namespace = entry.getKey();
        String uri = entry.getValue() == null ? null : entry.getValue();

        Assert.notNull(uri, "Namespace definition cannot supply a null URI");

        final NamespaceHandler namespaceHandler = namespaceHandlerResolver.resolve(uri);
        if (namespaceHandler == null) {
            throw new BeanDefinitionParsingException(new Problem("No namespace handler found for URI: " + uri,
                    new Location(readerContext.getResource())));
        }
        namespaceHandlers.put(namespace, namespaceHandler);
        namespaces.put(namespace, uri);
    }
}

From source file:org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader.java

/**
 * Define a Spring XML namespace definition to use.
 * @param definition the namespace definition
 *///from  w w  w .j a  v  a2 s . c  o  m
public void xmlns(Map<String, String> definition) {
    if (!definition.isEmpty()) {
        for (Map.Entry<String, String> entry : definition.entrySet()) {
            String namespace = entry.getKey();
            String uri = entry.getValue();
            if (uri == null) {
                throw new IllegalArgumentException("Namespace definition must supply a non-null URI");
            }
            NamespaceHandler namespaceHandler = this.groovyDslXmlBeanDefinitionReader
                    .getNamespaceHandlerResolver().resolve(uri);
            if (namespaceHandler == null) {
                throw new BeanDefinitionParsingException(
                        new Problem("No namespace handler found for URI: " + uri,
                                new Location(new DescriptiveResource(("Groovy")))));
            }
            this.namespaces.put(namespace, uri);
        }
    }
}

From source file:org.springframework.context.groovy.GroovyBeanDefinitionReader.java

/**
 * Defines an Spring namespace definition to use
 *
 * @param definition The definition/*  w w w  . ja v  a 2s  . c o m*/
 */
public void xmlns(Map<String, String> definition) {
    Assert.notNull(namespaceHandlerResolver,
            "You cannot define a Spring namespace without a [namespaceHandlerResolver] set");
    if (!definition.isEmpty()) {

        for (Map.Entry<String, String> entry : definition.entrySet()) {
            String namespace = entry.getKey();
            String uri = null;
            if (entry.getValue() != null) {
                uri = entry.getValue();
            }

            if (uri == null) {
                throw new IllegalArgumentException("Namespace definition cannot supply a null URI");
            }
            final NamespaceHandler namespaceHandler = namespaceHandlerResolver.resolve(uri);
            if (namespaceHandler == null) {
                throw new BeanDefinitionParsingException(
                        new Problem("No namespace handler found for URI: " + uri,
                                new Location(this.readerContext.getResource())));
            }
            namespaceHandlers.put(namespace, namespaceHandler);
            namespaces.put(namespace, uri);

        }

    }
}