new PushbackReader(reader, 4096); //some size to unread <?xml ....?> XMLDeclarationParser ev = new XMLDeclarationParser(pushbackReader); try { ev.parse(); } catch (Exception e) { log.log( "XML declaration parsing failed", e); String xmlDecl = ev.getXmlDeclaration(); if ((xmlDecl != null) && (xmlDecl.length() > 0)) { this.omitXmlDecl = false;
m_encoding = parseEncoding(xmlDecl, eqIndex); if(m_encoding.startsWith("\"")){ m_encoding = m_encoding.substring(m_encoding.indexOf("\"")+1, m_encoding.lastIndexOf("\""));
new XMLDeclarationParser(pushbackReader); try { ev.parse(); } catch (Exception ex) { throw new TransformerException( ev.writeTo(writer); // doesn't write any, if no header
@Override protected Envelope createEnvelopeFromSource() throws SOAPException { // Record the presence of xml declaration before the envelope gets // created. XMLDeclarationParser parser = lookForXmlDecl(); Source tmp = source; source = null; EnvelopeImpl envelope = (EnvelopeImpl) EnvelopeFactory.createEnvelope(tmp, this); if (!envelope.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE)) { log.severe("SAAJ0304.ver1_1.msg.invalid.SOAP1.1"); throw new SOAPException("InputStream does not represent a valid SOAP 1.1 Message"); } if (parser != null && !omitXmlDecl) { envelope.setOmitXmlDecl("no"); envelope.setXmlDecl(parser.getXmlDeclaration()); envelope.setCharsetEncoding(parser.getEncoding()); } return envelope; }
@Override protected Envelope createEnvelopeFromSource() throws SOAPException { XMLDeclarationParser parser = lookForXmlDecl(); Source tmp = source; source = null; EnvelopeImpl envelope = (EnvelopeImpl)EnvelopeFactory.createEnvelope(tmp, this); if (!envelope.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) { log.severe("SAAJ0415.ver1_2.msg.invalid.soap1.2"); throw new SOAPException("InputStream does not represent a valid SOAP 1.2 Message"); } if (parser != null) { //can be null if source was a DomSource and not StreamSource if (!omitXmlDecl) { envelope.setOmitXmlDecl("no"); envelope.setXmlDecl(parser.getXmlDeclaration()); envelope.setCharsetEncoding(parser.getEncoding()); } } return envelope; }