Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GenericMessage types cannot be encoded to XML (illegal characters) #20

Open
kbalthaser opened this issue Jun 8, 2018 · 0 comments · May be fixed by #21
Open

GenericMessage types cannot be encoded to XML (illegal characters) #20

kbalthaser opened this issue Jun 8, 2018 · 0 comments · May be fixed by #21

Comments

@kbalthaser
Copy link
Contributor

If you attempt to use the DefaultXmlParser to encode a Message which is a GenericMessage, it will fail with a org.w3c.dom.DOMException.

This is due to the presence of a $ within the ClassName of an instantiated GenericMessage. Ex: GenericMessage$V23.

Sample Test:

/**
     * <p>
     *     Attempt to parse a {@link ca.uhn.hl7v2.model.GenericMessage}.  These objects have `$` in their class name, ex: `GenericMessage$V21`.
     *     The {@link DefaultXMLParser} will attempt to use the class name when constructing the {@link Document} when encoding.  The `$` is
     *     not a valid character within an element name.
     * </p>
     * <p>
     *     Construct a {@link GenericMessage} for each available version, and call {@link DefaultXMLParser#encode(Message)} on the message.
     *     We expect that a valid {@link Document} is returned, as the `$` is stripped out.
     * </p>
     */
	@Test
    public void test_encode_GenericMessage() throws Exception {

	    DefaultXMLParser xmlParser = new DefaultXMLParser();

        for (Version version : Version.values()) {

            Class<? extends Message> c = GenericMessage.getGenericMessageClass(version.getVersion());
            Message m = c.getConstructor(ModelClassFactory.class).newInstance(new GenericModelClassFactory());

            Document d = xmlParser.encodeDocument(m);
            Assert.assertNotNull(d);
            Assert.assertEquals("GenericMessage" + version.name(), d.getDocumentElement().getTagName());
        }
    }

Will be submitting a PR with a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant