@@ -85,7 +85,13 @@ public function loadSource($source) {
8585 SimpleSAML_Logger::debug ('Downloaded fresh copy ' );
8686 }
8787
88- $ entities = $ this ->loadXML ($ data , $ source );
88+ try {
89+ $ entities = $ this ->loadXML ($ data , $ source );
90+ } catch (Exception $ e ) {
91+ SimpleSAML_Logger::debug ('XML parser error when parsing ' . $ source ['src ' ] . ' - attempting to re-use cached metadata ' );
92+ $ this ->addCachedMetadata ($ source );
93+ return ;
94+ }
8995
9096 foreach ($ entities as $ entity ) {
9197
@@ -205,17 +211,13 @@ private function saveState($source, $responseHeaders) {
205211 */
206212 private function loadXML ($ data , $ source ) {
207213 $ entities = array ();
208- try {
209- $ doc = new DOMDocument ();
210- $ res = $ doc ->loadXML ($ data );
211- if ($ res !== TRUE ) {
212- throw new Exception ('Failed to read XML from ' . $ source ['src ' ]);
213- }
214- if ($ doc ->documentElement === NULL ) throw new Exception ('Opened file is not an XML document: ' . $ source ['src ' ]);
215- $ entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement ($ doc ->documentElement );
216- } catch (Exception $ e ) {
217- SimpleSAML_Logger::warning ('metarefresh: Failed to retrieve metadata. ' . $ e ->getMessage ());
214+ $ doc = new DOMDocument ();
215+ $ res = $ doc ->loadXML ($ data );
216+ if ($ res !== TRUE ) {
217+ throw new Exception ('Failed to read XML from ' . $ source ['src ' ]);
218218 }
219+ if ($ doc ->documentElement === NULL ) throw new Exception ('Opened file is not an XML document: ' . $ source ['src ' ]);
220+ $ entities = SimpleSAML_Metadata_SAMLParser::parseDescriptorsElement ($ doc ->documentElement );
219221 return $ entities ;
220222 }
221223
0 commit comments