Анализатор SAX генерирует исключение 403 для действительного URL, который загружается без проблем в браузер.Мы можем воспроизвести проблему с помощью следующего примера кода.Указатели оценены.
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.helpers.DefaultHandler;
public class StackOverflow {
public static void main(String[] args) {
SAXParserFactory factory2 = SAXParserFactory.newInstance();
try {
String uri;
uri = "https://www.sec.gov/Archives/edgar/data/1326801/000132680119000009/FilingSummary.xml"; // Does not work
// uri = "https://www.w3schools.com/xml/simple.xml"; // ** Works if this line is uncommented **
SAXParser saxParser = factory2.newSAXParser();
DefaultHandler eventHandler = new DefaultHandler();
saxParser.parse(uri, eventHandler);
// ...
// Business Logic
// ...
System.out.println("SUCCESS");
}
catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
Трассировка стека выглядит следующим образом:
java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.sec.gov/Archives/edgar/data/1326801/000132680119000009/FilingSummary.xml
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at StackOverflow.main(StackOverflow.java:15)