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

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

Introduction

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

Prototype

public BeanDefinitionParsingException(Problem problem) 

Source Link

Document

Create a new BeanDefinitionParsingException.

Usage

From source file:org.data.support.beans.factory.parsing.FailFastProblemReporter.java

/**
 * Throws a {@link BeanDefinitionParsingException} detailing the error
 * that has occurred.//from w w  w .  j  a v a  2 s.c o m
 * @param problem the source of the error
 */
public void fatal(Problem problem) {
    throw new BeanDefinitionParsingException(problem);
}

From source file:org.data.support.beans.factory.parsing.FailFastProblemReporter.java

/**
 * Throws a {@link BeanDefinitionParsingException} detailing the error
 * that has occurred.// w ww .j a va2 s  . c  om
 * @param problem the source of the error
 */
public void error(Problem problem) {
    throw new BeanDefinitionParsingException(problem);
}

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

/** {@inheritDoc} */
@Override//from  w w  w.  j  a v  a  2  s.  co  m
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   ww w.j a  v a 2 s . c  om*/
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 ava  2  s .c om*/
 * @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 w  ww  .j ava  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()) {
        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:grails.spring.BeanBuilder.java

/**
 * Loads a set of given beans// w w  w . j av a 2 s.  co m
 * @param resources The resources to load
 * @throws IOException Thrown if there is an error reading one of the passes resources
 */
public void loadBeans(Resource[] resources) {
    @SuppressWarnings("rawtypes")
    Closure beans = new Closure(this) {
        private static final long serialVersionUID = -2778328821635253740L;

        @Override
        public Object call(Object... args) {
            invokeBeanDefiningClosure((Closure) args[0]);
            return null;
        }
    };

    Binding b = new Binding() {
        @Override
        public void setVariable(String name, Object value) {
            if (currentBeanConfig == null) {
                super.setVariable(name, value);
            } else {
                setPropertyOnBeanConfig(name, value);
            }
        }
    };
    b.setVariable("beans", beans);

    for (Resource resource : resources) {
        try {
            GroovyShell shell = classLoader == null ? new GroovyShell(b) : new GroovyShell(classLoader, b);
            shell.evaluate(new InputStreamReader(resource.getInputStream()));
        } catch (Throwable e) {
            throw new BeanDefinitionParsingException(
                    new Problem("Error evaluating bean definition script: " + e.getMessage(),
                            new Location(resource), null, e));
        }
    }
}

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

/**
 * Load bean definitions from the specified Groovy script or XML file.
 * <p>Note that {@code ".xml"} files will be parsed as XML content; all other kinds
 * of resources will be parsed as Groovy scripts.
 * @param encodedResource the resource descriptor for the Groovy script or XML file,
 * allowing specification of an encoding to use for parsing the file
 * @return the number of bean definitions found
 * @throws BeanDefinitionStoreException in case of loading or parsing errors
 *//*from   w ww. j av  a  2  s.  c o m*/
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
    // Check for XML files and redirect them to the "standard" XmlBeanDefinitionReader
    String filename = encodedResource.getResource().getFilename();
    if (StringUtils.endsWithIgnoreCase(filename, ".xml")) {
        return this.standardXmlBeanDefinitionReader.loadBeanDefinitions(encodedResource);
    }

    Closure beans = new Closure(this) {
        public Object call(Object[] args) {
            invokeBeanDefiningClosure((Closure) args[0]);
            return null;
        }
    };
    Binding binding = new Binding() {
        @Override
        public void setVariable(String name, Object value) {
            if (currentBeanDefinition != null) {
                applyPropertyToBeanDefinition(name, value);
            } else {
                super.setVariable(name, value);
            }
        }
    };
    binding.setVariable("beans", beans);

    int countBefore = getRegistry().getBeanDefinitionCount();
    try {
        GroovyShell shell = new GroovyShell(getBeanClassLoader(), binding);
        shell.evaluate(encodedResource.getReader(), "beans");
    } catch (Throwable ex) {
        throw new BeanDefinitionParsingException(
                new Problem("Error evaluating Groovy script: " + ex.getMessage(),
                        new Location(encodedResource.getResource()), null, ex));
    }
    return getRegistry().getBeanDefinitionCount() - countBefore;
}

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

/**
 * Define a Spring XML namespace definition to use.
 * @param definition the namespace definition
 *//*from   ww  w . ja  va 2  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.beans.factory.parsing.FailFastProblemReporter.java

/**
 * Throws a {@link BeanDefinitionParsingException} detailing the error
 * that has occurred.//w  ww.j  a  v  a  2  s .  co m
 * @param problem the source of the error
 */
@Override
public void fatal(Problem problem) {
    throw new BeanDefinitionParsingException(problem);
}