8196491: Newlines in JAXB string values of SOAP-requests are escaped to "
"
Reviewed-by: lancea, rgrigoriadi
diff --git a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java
index a4d7fd5..3367a1b 100644
--- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java
+++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,6 +33,7 @@
import javax.xml.stream.XMLStreamWriter;
import com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler;
+import com.sun.xml.internal.bind.marshaller.NoEscapeHandler;
import com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl;
import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
@@ -71,7 +72,7 @@
}
CharacterEscapeHandler xmlStreamEscapeHandler = escapeHandler != null ?
- escapeHandler : NewLineEscapeHandler.theInstance;
+ escapeHandler : NoEscapeHandler.theInstance;
// otherwise the normal writer.
return new XMLStreamWriterOutput(out, xmlStreamEscapeHandler);
@@ -217,45 +218,6 @@
}
}
-
- /**
- * Performs character escaping only for new lines.
- */
- private static class NewLineEscapeHandler implements CharacterEscapeHandler {
-
- public static final NewLineEscapeHandler theInstance = new NewLineEscapeHandler();
-
- @Override
- public void escape(char[] ch, int start, int length, boolean isAttVal, Writer out) throws IOException {
- int limit = start+length;
- int lastEscaped = start;
-
- for (int i = start; i < limit; i++) {
- char c = ch[i];
- if (c == '\r' || c == '\n') {
- if (i != lastEscaped) {
- out.write(ch, lastEscaped, i - lastEscaped);
- }
- lastEscaped = i + 1;
- if (out instanceof XmlStreamOutWriterAdapter) {
- try {
- ((XmlStreamOutWriterAdapter)out).writeEntityRef("#x" + Integer.toHexString(c));
- } catch (XMLStreamException e) {
- throw new IOException("Error writing xml stream", e);
- }
- } else {
- out.write("&#x");
- out.write(Integer.toHexString(c));
- out.write(';');
- }
- }
- }
- if (lastEscaped != limit) {
- out.write(ch, lastEscaped, length - lastEscaped);
- }
- }
- }
-
private static final class XmlStreamOutWriterAdapter extends Writer {
private final XMLStreamWriter writer;
diff --git a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java
index 6cff489..878a896 100644
--- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java
+++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -386,7 +386,7 @@
}
- private static class HasEncodingWriter extends XMLStreamWriterFilter implements HasEncoding {
+ public static class HasEncodingWriter extends XMLStreamWriterFilter implements HasEncoding {
private final String encoding;
HasEncodingWriter(XMLStreamWriter writer, String encoding) {
@@ -399,7 +399,7 @@
return encoding;
}
- XMLStreamWriter getWriter() {
+ public XMLStreamWriter getWriter() {
return writer;
}
}
diff --git a/src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java b/src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java
index b72cb73..92e1e10 100644
--- a/src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java
+++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
package com.sun.xml.internal.ws.streaming;
import com.sun.istack.internal.Nullable;
+import com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory;
import com.sun.xml.internal.ws.encoding.HasEncoding;
import com.sun.xml.internal.ws.encoding.SOAPBindingCodec;
@@ -57,9 +58,15 @@
public static @Nullable OutputStream getOutputStream(XMLStreamWriter writer) throws XMLStreamException {
Object obj = null;
+ XMLStreamWriter xmlStreamWriter =
+ writer instanceof XMLStreamWriterFactory.HasEncodingWriter ?
+ ((XMLStreamWriterFactory.HasEncodingWriter) writer).getWriter()
+ : writer;
+
+
// Hack for JDK6's SJSXP
- if (writer instanceof Map) {
- obj = ((Map) writer).get("sjsxp-outputstream");
+ if (xmlStreamWriter instanceof Map) {
+ obj = ((Map) xmlStreamWriter).get("sjsxp-outputstream");
}
// woodstox