本文整理了Java中org.ehcache.xml.exceptions.XmlConfigurationException
类的一些代码示例,展示了XmlConfigurationException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XmlConfigurationException
类的具体详情如下:
包路径:org.ehcache.xml.exceptions.XmlConfigurationException
类名称:XmlConfigurationException
[英]Thrown to reflect an error in an XML configuration.
[中]抛出以反映XML配置中的错误。
代码示例来源:origin: ehcache/ehcache3
@Override
public Element unparseServiceCreationConfiguration(ServiceCreationConfiguration<Jsr107Service> serviceCreationConfiguration) {
throw new XmlConfigurationException("XML translation of JSR-107 cache elements are not supported");
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testFailsWithInvalidClusterUri() {
try {
new XmlConfiguration(getClass().getResource("/configs/cluster-invalid-uri.xml"));
} catch (XmlConfigurationException e) {
assertThat(e.getCause().getMessage(), containsString("not facet-valid with respect to pattern"));
}
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testGetTimeoutUnitBad() throws Exception {
final String[] config = new String[]
{
"<ehcache:config",
" xmlns:ehcache=\"http://www.ehcache.org/v3\"",
" xmlns:tc=\"http://www.ehcache.org/v3/clustered\">",
"",
" <ehcache:service>",
" <tc:cluster>",
" <tc:connection url=\"terracotta://example.com:9540/cachemanager\"/>",
" <tc:read-timeout unit=\"femtos\">5</tc:read-timeout>",
" </tc:cluster>",
" </ehcache:service>",
"",
"</ehcache:config>"
};
try {
new XmlConfiguration(makeConfig(config));
fail("Expecting XmlConfigurationException");
} catch (XmlConfigurationException e) {
assertThat(e.getMessage(), containsString("Error parsing XML configuration "));
assertThat(e.getCause().getMessage(), containsString("Value 'femtos' is not facet-valid with respect to enumeration "));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testTwoCachesWithSameAlias() {
try {
new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/invalid-two-caches.xml"));
fail("Two caches with the same alias should not be allowed");
} catch (XmlConfigurationException e) {
assertThat(e.getMessage(), is("Two caches defined with the same alias: foo"));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testGetTimeoutValueOmitted() throws Exception {
final String[] config = new String[]
{
"<ehcache:config",
" xmlns:ehcache=\"http://www.ehcache.org/v3\"",
" xmlns:tc=\"http://www.ehcache.org/v3/clustered\">",
"",
" <ehcache:service>",
" <tc:cluster>",
" <tc:connection url=\"terracotta://example.com:9540/cachemanager\"/>",
" <tc:read-timeout unit=\"seconds\"></tc:read-timeout>",
" </tc:cluster>",
" </ehcache:service>",
"",
"</ehcache:config>"
};
try {
new XmlConfiguration(makeConfig(config));
fail("Expecting XmlConfigurationException");
} catch (XmlConfigurationException e) {
assertThat(e.getMessage(), containsString("Error parsing XML configuration "));
assertThat(e.getCause().getMessage(), containsString("'' is not a valid value for 'integer'"));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testCustomResource() throws Exception {
try {
new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/custom-resource.xml"));
fail();
} catch (XmlConfigurationException xce) {
assertThat(xce.getMessage(), containsString("Can't find parser for element"));
}
}
代码示例来源:origin: ehcache/ehcache3
@Override
public Element unparseServiceConfiguration(ServiceConfiguration<Jsr107Service> serviceConfiguration) {
throw new XmlConfigurationException("XML translation of JSR-107 cache elements are not supported");
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testInvalidServiceConfiguration() throws Exception {
try {
new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/invalid-service.xml"));
fail();
} catch (XmlConfigurationException xce) {
SAXParseException e = (SAXParseException) xce.getCause();
assertThat(e.getLineNumber(), is(6));
assertThat(e.getColumnNumber(), is(15));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testGetTimeoutValueTooBig() throws Exception {
final String[] config = new String[]
{
"<ehcache:config",
" xmlns:ehcache=\"http://www.ehcache.org/v3\"",
" xmlns:tc=\"http://www.ehcache.org/v3/clustered\">",
"",
" <ehcache:service>",
" <tc:cluster>",
" <tc:connection url=\"terracotta://example.com:9540/cachemanager\"/>",
" <tc:read-timeout unit=\"seconds\">"
+ BigInteger.ONE.add(BigInteger.valueOf(Long.MAX_VALUE))
+ "</tc:read-timeout>",
" </tc:cluster>",
" </ehcache:service>",
"",
"</ehcache:config>"
};
try {
new XmlConfiguration(makeConfig(config));
fail("Expecting XmlConfigurationException");
} catch (XmlConfigurationException e) {
assertThat(e.getMessage(), containsString(" exceeds allowed value "));
}
}
代码示例来源:origin: ehcache/ehcache3
@Override
public ServiceConfiguration<XAStore.Provider> parseServiceConfiguration(Element fragment, ClassLoader classLoader) {
String localName = fragment.getLocalName();
if ("xa-store".equals(localName)) {
String uniqueXAResourceId = fragment.getAttribute("unique-XAResource-id");
return new XAStoreConfiguration(uniqueXAResourceId);
} else {
throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testInvalidCoreConfiguration() throws Exception {
try {
new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/invalid-core.xml"));
fail();
} catch (XmlConfigurationException xce) {
SAXParseException e = (SAXParseException) xce.getCause();
assertThat(e.getLineNumber(), is(5));
assertThat(e.getColumnNumber(), is(29));
}
}
代码示例来源:origin: ehcache/ehcache3
ResourcePool parseResourceExtension(final Element element) {
for (CacheResourceConfigurationParser parser : extensionParsers) {
ResourcePool resourcePool = parser.parseResourceConfiguration(element);
if (resourcePool != null) {
return resourcePool;
}
}
throw new XmlConfigurationException("Can't find parser for element: " + element);
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testGetUnknownCacheInvalidElement() {
try {
new XmlConfiguration(this.getClass().getResource("/configs/unknown-cluster-cache-invalid-element.xml"));
fail("Expected XmlConfigurationException");
} catch(XmlConfigurationException xce) {
Assert.assertThat(xce.getCause().getMessage(), endsWith("Element 'tc:clustered' must have no character or element information item [children], because the type's content type is empty."));
}
}
代码示例来源:origin: ehcache/ehcache3
@Override
public ResourcePool parseResourceConfiguration(final Element fragment) {
ResourcePool resourcePool = parseResourceConfig(fragment);
if (resourcePool != null) {
return resourcePool;
}
throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testGetUnknownCacheInvalidAttribute() {
try {
new XmlConfiguration(this.getClass().getResource("/configs/unknown-cluster-cache-invalid-attribute.xml"));
fail("Expected XmlConfigurationException");
} catch(XmlConfigurationException xce) {
Assert.assertThat(xce.getCause().getMessage(), endsWith("Attribute 'unit' is not allowed to appear in element 'tc:clustered'."));
}
}
代码示例来源:origin: ehcache/ehcache3
@Override
public ServiceConfiguration<Jsr107Service> parseServiceConfiguration(Element fragment, ClassLoader classLoader) {
String localName = fragment.getLocalName();
if ("mbeans".equals(localName)) {
ConfigurationElementState managementEnabled = ConfigurationElementState.UNSPECIFIED;
ConfigurationElementState statisticsEnabled = ConfigurationElementState.UNSPECIFIED;
if (fragment.hasAttribute(MANAGEMENT_ENABLED_ATTRIBUTE)) {
managementEnabled = Boolean.parseBoolean(fragment.getAttribute(MANAGEMENT_ENABLED_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
}
if (fragment.hasAttribute(STATISTICS_ENABLED_ATTRIBUTE)) {
statisticsEnabled = Boolean.parseBoolean(fragment.getAttribute(STATISTICS_ENABLED_ATTRIBUTE)) ? ConfigurationElementState.ENABLED : ConfigurationElementState.DISABLED;
}
return new Jsr107CacheConfiguration(statisticsEnabled, managementEnabled);
} else {
throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
}
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testNonExistentAdvisorClassInTemplateThrowsException() throws Exception {
try {
new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/nonExistentAdvisor-template.xml"));
fail();
} catch (XmlConfigurationException xce) {
assertThat(xce.getCause(), instanceOf(ClassNotFoundException.class));
}
}
代码示例来源:origin: ehcache/ehcache3
@Override
public ServiceConfiguration<ClusteredStore.Provider> parseServiceConfiguration(Element fragment, ClassLoader classLoader) {
if (CLUSTERED_STORE_ELEMENT_NAME.equals(fragment.getLocalName())) {
if (fragment.hasAttribute(CONSISTENCY_ATTRIBUTE_NAME)) {
return new ClusteredStoreConfiguration(Consistency.valueOf(fragment.getAttribute("consistency").toUpperCase()));
} else {
return new ClusteredStoreConfiguration();
}
}
throw new XmlConfigurationException(String.format("XML configuration element <%s> in <%s> is not supported",
fragment.getTagName(), (fragment.getParentNode() == null ? "null" : fragment.getParentNode().getLocalName())));
}
代码示例来源:origin: ehcache/ehcache3
@Test
public void testNonExistentAdvisorClassInCacheThrowsException() throws Exception {
try {
new XmlConfiguration(XmlConfigurationTest.class.getResource("/configs/nonExistentAdvisor-cache.xml"));
fail();
} catch (XmlConfigurationException xce) {
assertThat(xce.getCause(), instanceOf(ClassNotFoundException.class));
}
}
代码示例来源:origin: ehcache/ehcache3
private Duration processTimeout(Element parentElement, Node timeoutNode) {
try {
// <xxx-timeout> are direct subtype of ehcache:time-type; use JAXB to interpret it
JAXBContext context = JAXBContext.newInstance(TimeType.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
JAXBElement<TimeType> jaxbElement = unmarshaller.unmarshal(timeoutNode, TimeType.class);
TimeType timeType = jaxbElement.getValue();
BigInteger amount = timeType.getValue();
if (amount.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0) {
throw new XmlConfigurationException(
String.format("Value of XML configuration element <%s> in <%s> exceeds allowed value - %s",
timeoutNode.getNodeName(), parentElement.getTagName(), amount));
}
return Duration.of(amount.longValue(), convertToJavaTimeUnit(timeType.getUnit()));
} catch (JAXBException e) {
throw new XmlConfigurationException(e);
}
}
内容来源于网络,如有侵权,请联系作者删除!