changeset 1612:6ac8c8bf6b78 jdk8u192-b01

8196491: Newlines in JAXB string values of SOAP-requests are escaped to "
" Reviewed-by: lancea, rgrigoriadi
author aefimov
date Mon, 23 Apr 2018 13:24:44 +0100
parents 479db640b75a
children 1630786393b6
files src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java
diffstat 3 files changed, 16 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java	Fri Apr 13 18:18:41 2018 +0000
+++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/output/XMLStreamWriterOutput.java	Mon Apr 23 13:24:44 2018 +0100
@@ -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;
--- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java	Fri Apr 13 18:18:41 2018 +0000
+++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java	Mon Apr 23 13:24:44 2018 +0100
@@ -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;
         }
     }
--- a/src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java	Fri Apr 13 18:18:41 2018 +0000
+++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/streaming/XMLStreamWriterUtil.java	Mon Apr 23 13:24:44 2018 +0100
@@ -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