Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Escaping ]]> in MOXy(It is handled differently in RI and MOXy)
Escaping ]]> in MOXy [message #1699857] Sat, 27 June 2015 14:20 Go to next message
Sh Ee is currently offline Sh EeFriend
Messages: 1
Registered: June 2015
Junior Member
Hi!

MOXy(2.6) does not escape ">" in generated XML and the unmarshalling fails in the following example:

import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

public class MoxyEscaping {

	@XmlRootElement static class A {
		@XmlValue String field = "a]]>b";
	}

	public static void main(String[] args) throws Exception {
		
		System.setProperty(
			"javax.xml.bind.context.factory",
			"org.eclipse.persistence.jaxb.JAXBContextFactory");
		JAXBContext ctx = JAXBContext.newInstance(A.class);
		
		StringWriter out = new StringWriter();
		ctx.createMarshaller().marshal(new A(), out);
		ctx.createUnmarshaller().unmarshal(new StringReader(out.toString()));
	}
}


Similar code works OK for RI.
Overriding the CharacterEscapeHandler has some cost. Is this a bug?

[Updated on: Mon, 27 July 2015 12:49]

Report message to a moderator

Re: Escaping ]]> in MOXy [message #1719307 is a reply to message #1699857] Wed, 06 January 2016 23:34 Go to previous messageGo to next message
Jeff Shern is currently offline Jeff ShernFriend
Messages: 2
Registered: January 2016
Junior Member
Did you ever figure anything out on this?



Digging, I did find that the OutputStreamRecord.java in MOXY does not have any mechanism to add a > symbol. Generally, that's fine, but they do ignore the second half of the standard, where it says it is required when escaping a "]]>"

According to the standard (www.w3.org /TR/2008/REC-xml-20081126/#syntax)

Quote:
The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.


Also, a little strange, is that org.eclipse.persistence.oxm.CharacterEscapeHandler does not implement com.sun.xml.internal.bind.marshaller.CharacterEscapeHandler .. even though they appear to be identical. So you have to use a wrapper class to convert between the two.

I did modify your code, below, to use the NioEscapeHandler that is used in JAXB RI.

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import org.eclipse.persistence.jaxb.MarshallerProperties;
import org.eclipse.persistence.oxm.CharacterEscapeHandler;

public class MoxyEscaping {

    @XmlRootElement static class A {
        @XmlValue String field = "a]]>b";
    }

    public static void main(String[] args) throws Exception {
        System.setProperty(
                "javax.xml.bind.context.factory",
                "org.eclipse.persistence.jaxb.JAXBContextFactory");
        JAXBContext ctx = JAXBContext.newInstance(A.class);

        StringWriter out = new StringWriter();
        Marshaller m=ctx.createMarshaller();
        String Encoding = (String) m.getProperty(Marshaller.JAXB_ENCODING);
        CharacterEscapeHandler eh = new dxinittest.NioEscapeHandlerWrapper(Encoding);
        m.setProperty(MarshallerProperties.CHARACTER_ESCAPE_HANDLER, eh);     
        m.marshal(new A(), out);
        ctx.createUnmarshaller().unmarshal(new StringReader(out.toString()));
    }

    static class NioEscapeHandlerWrapper implements org.eclipse.persistence.oxm.CharacterEscapeHandler {

        com.sun.xml.internal.bind.marshaller.NioEscapeHandler NEH;

        NioEscapeHandlerWrapper(String charSetName) {
            NEH = new com.sun.xml.internal.bind.marshaller.NioEscapeHandler(charSetName);
        }

        @Override
        public void escape(char[] buffer, int start, int length, boolean isAttributeValue, Writer out) throws IOException {
            NEH.escape(buffer, start, length, isAttributeValue, out);
        }

    }
}


It's not a fix, but it's a little better then writing your own EscapeHandlerWrapper.

[Updated on: Thu, 07 January 2016 17:15]

Report message to a moderator

Re: Escaping ]]> in MOXy [message #1719431 is a reply to message #1719307] Thu, 07 January 2016 20:29 Go to previous message
Jeff Shern is currently offline Jeff ShernFriend
Messages: 2
Registered: January 2016
Junior Member
I created a bug for this:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=485372
Previous Topic:RollbackException for tree structure
Next Topic:Integrate BoneCP and EclipseLink with LOCAL_RESOURCE transaction-type
Goto Forum:
  


Current Time: Wed Apr 24 21:16:27 GMT 2024

Powered by FUDForum. Page generated in 0.03058 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top