Skip to content

Commit bda2a08

Browse files
author
aefimov
committed
8196491: Newlines in JAXB string values of SOAP-requests are escaped to "
"
Reviewed-by: lancea, rgrigoriadi
1 parent a9f50c1 commit bda2a08

File tree

3 files changed

+16
-47
lines changed

3 files changed

+16
-47
lines changed

jaxws/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java

+3-41
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@
3333
import javax.xml.stream.XMLStreamWriter;
3434

3535
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler;
36+
import com.sun.xml.internal.bind.marshaller.NoEscapeHandler;
3637
import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
3738
import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
3839

@@ -71,7 +72,7 @@ public static XmlOutput create(XMLStreamWriter out, JAXBContextImpl context, Cha
7172
}
7273

7374
CharacterEscapeHandler xmlStreamEscapeHandler = escapeHandler != null ?
74-
escapeHandler : NewLineEscapeHandler.theInstance;
75+
escapeHandler : NoEscapeHandler.theInstance;
7576

7677
// otherwise the normal writer.
7778
return new XMLStreamWriterOutput(out, xmlStreamEscapeHandler);
@@ -217,45 +218,6 @@ private static Constructor<? extends XmlOutput> initStAXExOutputClass() {
217218
}
218219
}
219220

220-
221-
/**
222-
* Performs character escaping only for new lines.
223-
*/
224-
private static class NewLineEscapeHandler implements CharacterEscapeHandler {
225-
226-
public static final NewLineEscapeHandler theInstance = new NewLineEscapeHandler();
227-
228-
@Override
229-
public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
230-
int limit = start+length;
231-
int lastEscaped = start;
232-
233-
for (int i = start; i < limit; i++) {
234-
char c = ch[i];
235-
if (c == '\r' || c == '\n') {
236-
if (i != lastEscaped) {
237-
out.write(ch, lastEscaped, i - lastEscaped);
238-
}
239-
lastEscaped = i + 1;
240-
if (out instanceof XmlStreamOutWriterAdapter) {
241-
try {
242-
((XmlStreamOutWriterAdapter)out).writeEntityRef("#x" + Integer.toHexString(c));
243-
} catch (XMLStreamException e) {
244-
throw new IOException("Error writing xml stream", e);
245-
}
246-
} else {
247-
out.write("&#x");
248-
out.write(Integer.toHexString(c));
249-
out.write(';');
250-
}
251-
}
252-
}
253-
if (lastEscaped != limit) {
254-
out.write(ch, lastEscaped, length - lastEscaped);
255-
}
256-
}
257-
}
258-
259221
private static final class XmlStreamOutWriterAdapter extends Writer {
260222

261223
private final XMLStreamWriter writer;

jaxws/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -386,7 +386,7 @@ public void doRecycle(XMLStreamWriter r) {
386386

387387
}
388388

389-
private static class HasEncodingWriter extends XMLStreamWriterFilter implements HasEncoding {
389+
public static class HasEncodingWriter extends XMLStreamWriterFilter implements HasEncoding {
390390
private final String encoding;
391391

392392
HasEncodingWriter(XMLStreamWriter writer, String encoding) {
@@ -399,7 +399,7 @@ public String getEncoding() {
399399
return encoding;
400400
}
401401

402-
XMLStreamWriter getWriter() {
402+
public XMLStreamWriter getWriter() {
403403
return writer;
404404
}
405405
}

jaxws/src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
package com.sun.xml.internal.ws.streaming;
2727

2828
import com.sun.istack.internal.Nullable;
29+
import com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory;
2930
import com.sun.xml.internal.ws.encoding.HasEncoding;
3031
import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
3132

@@ -57,9 +58,15 @@ private XMLStreamWriterUtil() {
5758
public static @Nullable OutputStream getOutputStream(XMLStreamWriter writer) throws XMLStreamException {
5859
Object obj = null;
5960

61+
XMLStreamWriter xmlStreamWriter =
62+
writer instanceof XMLStreamWriterFactory.HasEncodingWriter ?
63+
((XMLStreamWriterFactory.HasEncodingWriter) writer).getWriter()
64+
: writer;
65+
66+
6067
// Hack for JDK6's SJSXP
61-
if (writer instanceof Map) {
62-
obj = ((Map) writer).get("sjsxp-outputstream");
68+
if (xmlStreamWriter instanceof Map) {
69+
obj = ((Map) xmlStreamWriter).get("sjsxp-outputstream");
6370
}
6471

6572
// woodstox

0 commit comments

Comments
 (0)