Changeset 38db0b0f


Ignore:
Timestamp:
Apr 28, 2011 5:57:30 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
e8d9498
Parents:
e4a8b96
Message:
  • UPnP: Strip trailing nulls from incoming XML to prevent "content not allowed in trailing section" exceptions from stupid routers
File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/org/cybergarage/xml/parser/JaxpParser.java

    re4a8b96 r38db0b0f  
    1818package org.cybergarage.xml.parser;
    1919
     20import java.io.FilterInputStream;
     21import java.io.IOException;
    2022import java.io.InputStream;
    2123
     
    103105                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    104106                        DocumentBuilder builder = factory.newDocumentBuilder();
    105                         InputSource inSrc = new InputSource(inStream);
     107                        InputSource inSrc = new InputSource(new NullFilterInputStream(inStream));
    106108                        Document doc = builder.parse(inSrc);
    107109
     
    125127        }
    126128
     129        /**
     130         *  I2P -
     131         *  Filter out nulls, hopefully to avoid
     132         *  SAXParserException "Content not allowed in trailing section",
     133         *  which is apparently caused by nulls.
     134         *  Alternative is to remove all stuff between '>' and '<',
     135         *  which isn't so hard if we assume no CDATA.
     136         */
     137        private static class NullFilterInputStream extends FilterInputStream {
     138
     139                public NullFilterInputStream(InputStream is) {
     140                        super(is);
     141                }
     142
     143                @Override
     144                public int read() throws IOException {
     145                        int rv;
     146                        while ((rv = super.read()) == 0) {
     147                                // try again
     148                        }
     149                        return rv;
     150                }
     151        }
    127152}
Note: See TracChangeset for help on using the changeset viewer.