Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 8f1e74a

Browse files
author
Roman Grigoriadi
committed
Incorrect escape handling caused 'SAAJ0543: Entity References are not allowed in SOAP documents' when custom handler is added.
Fixes #1179 Signed-off-by: Roman Grigoriadi <roman.grigoriadi@oracle.com>
1 parent 2de3ad0 commit 8f1e74a

File tree

1 file changed

+3
-40
lines changed

1 file changed

+3
-40
lines changed

jaxb-ri/runtime/impl/src/main/java/com/sun/xml/bind/v2/runtime/output/XMLStreamWriterOutput.java

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -48,6 +48,7 @@
4848
import javax.xml.stream.XMLStreamWriter;
4949

5050
import com.sun.xml.bind.marshaller.CharacterEscapeHandler;
51+
import com.sun.xml.bind.marshaller.NoEscapeHandler;
5152
import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
5253
import com.sun.xml.bind.v2.runtime.XMLSerializer;
5354

@@ -86,7 +87,7 @@ public static XmlOutput create(XMLStreamWriter out, JAXBContextImpl context, Cha
8687
}
8788

8889
CharacterEscapeHandler xmlStreamEscapeHandler = escapeHandler != null ?
89-
escapeHandler : NewLineEscapeHandler.theInstance;
90+
escapeHandler : NoEscapeHandler.theInstance;
9091

9192
// otherwise the normal writer.
9293
return new XMLStreamWriterOutput(out, xmlStreamEscapeHandler);
@@ -232,44 +233,6 @@ private static Constructor<? extends XmlOutput> initStAXExOutputClass() {
232233
}
233234
}
234235

235-
/**
236-
* Performs character escaping only for new lines.
237-
*/
238-
private static class NewLineEscapeHandler implements CharacterEscapeHandler {
239-
240-
public static final NewLineEscapeHandler theInstance = new NewLineEscapeHandler();
241-
242-
@Override
243-
public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
244-
int limit = start+length;
245-
int lastEscaped = start;
246-
for (int i = start; i < limit; i++) {
247-
char c = ch[i];
248-
if (c == '\r' || c == '\n') {
249-
if (i != lastEscaped) {
250-
out.write(ch, lastEscaped, i - lastEscaped);
251-
}
252-
lastEscaped = i + 1;
253-
if (out instanceof XmlStreamOutWriterAdapter) {
254-
try {
255-
((XmlStreamOutWriterAdapter)out).writeEntityRef("#x" + Integer.toHexString(c));
256-
} catch (XMLStreamException e) {
257-
throw new IOException("Error writing xml stream", e);
258-
}
259-
} else {
260-
out.write("&#x");
261-
out.write(Integer.toHexString(c));
262-
out.write(';');
263-
}
264-
}
265-
}
266-
267-
if (lastEscaped != limit) {
268-
out.write(ch, lastEscaped, length - lastEscaped);
269-
}
270-
}
271-
}
272-
273236
private static final class XmlStreamOutWriterAdapter extends Writer {
274237

275238
private final XMLStreamWriter writer;

0 commit comments

Comments
 (0)