Sign Up Sign In

Validating xsd schema that contains import from external http source in Java 11


In the example.xsd file I have an import to an external xsd file that looks like this:

<schema xmlns=""
<import namespace="" 
        schemaLocation="" />
<element name="attachment" type="wsi:swaRef" />

In the config file I have created the XsdSchema and validator beans

public XsdSchema schema() {
  return new SimpleXsdSchema(new ClassPathResource("example.xsd"));

public XmlValidator schemaValidator(XsdSchema xsdSchema) {
  return xsdSchema.createValidator()); // throws exception

when starting the server I get the following exception:

schema_reference: Failed to read schema document 'swaref.xsd', because 'http' access is not allowed due to restriction set by the accessExternalSchema property.

In order to solve the problem I have tried different things such as:

  • Setting System.setProperty("javax.xml.accessExternalSchema", "all");
  • Setting System.setProperty("javax.xml.accessExternalDTD", "all");
  • Creating file under both jdk/lib and jdk/jre/lib and adding javax.xml.accessExternalSchema = all in there
  • Changing import in xsd to <import namespace=""/> which then causes different exception - Cannot resolve the name 'wsi:swaRef' to a(n) 'type definition' component.

Java 11, Gradle 5.5.1, Spring Boot 2.1.6, jaxws-ri 2.3.2

how to get it to work?

Why should this post be closed?


Hello. Apparently we have a bug that affected the layout on this post (made things kind of unreadable). I'm trying to get that fixed, but in the meantime I made an edit that I believe is harmless but want to check. In the first code block, I moved each attribute to its own line instead of having multiples on single (longer) lines. I'm pretty sure XSD doesn't care about whitespace, but if I'm wrong, please accept my apologies. ‭Monica Cellio‭ 24 days ago

Not an answer because I don't have a test environment to see whether it works, but have you tried (a) javax.xml.accessExternalSchema = http in; (b) searching all files for other references to javax.xml.accessExternalSchema which might have priority; (c) logging System.getProperty("javax.xml.accessExternalSchema") to check that the is being loaded? ‭Peter Taylor‭ 24 days ago

@Monica Cellio yes, that's fine, thank you @Peter Taylor yes, I have even tried setting the system property right before the createValidator call. ‭Janar‭ 23 days ago

0 answers

Sign up to answer this question »