Skip to content

Commit

Permalink
#73: Serialization error when using SOAPHandler and Eclipselink plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
(cherry picked from commit 930d332)
  • Loading branch information
lukasj committed Jun 6, 2021
1 parent 76df104 commit 4851b23
Showing 1 changed file with 23 additions and 18 deletions.
Expand Up @@ -12,8 +12,10 @@

import java.util.Iterator;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
Expand Down Expand Up @@ -320,24 +322,30 @@ public Object getProperty(final String name) throws IllegalArgumentException {
@Override
public NamespaceContext getNamespaceContext() {
return new NamespaceContext() {
@Override
public String getNamespaceURI(final String prefix) {
return currentElement.getNamespaceURI(prefix);
}
@Override
public String getPrefix(final String namespaceURI) {
return currentElement.lookupPrefix(namespaceURI);
}
@Override
public Iterator getPrefixes(final String namespaceURI) {
return new Iterator<String>() {
String prefix = getPrefix(namespaceURI);
@Override
public boolean hasNext() {
return (prefix != null);
}
@Override
public String next() {
if (!hasNext()) throw new java.util.NoSuchElementException();
String next = prefix;
prefix = null;
return next;
}
@Override
public void remove() {}
};
}
Expand Down Expand Up @@ -382,12 +390,12 @@ static class DeferredElement {
private String prefix;
private String localName;
private String namespaceUri;
private final List<NamespaceDeclaration> namespaceDeclarations;
private final Map<String, String> namespaceDeclarations;
private final List<AttributeDeclaration> attributeDeclarations;

DeferredElement() {
this.namespaceDeclarations = new LinkedList<NamespaceDeclaration>();
this.attributeDeclarations = new LinkedList<AttributeDeclaration>();
this.namespaceDeclarations = new HashMap<>();
this.attributeDeclarations = new LinkedList<>();
reset();
}

Expand Down Expand Up @@ -435,7 +443,7 @@ public void addNamespaceDeclaration(final String prefix, final String namespaceU
if (null == this.namespaceUri && null != namespaceUri && emptyIfNull(this.prefix).equals(prefix)) {
this.namespaceUri = namespaceUri;
}
this.namespaceDeclarations.add(new NamespaceDeclaration(prefix, namespaceUri));
this.namespaceDeclarations.put(emptyIfNull(namespaceUri), prefix);
}

/**
Expand All @@ -449,7 +457,7 @@ public void addAttribute(final String prefix, final String ns, final String ln,
if (ns == null && prefix == null && xmlns.equals(ln)) {
this.addNamespaceDeclaration(null, value);
} else {
this.attributeDeclarations.add(new AttributeDeclaration(prefix, ns, ln, value));
this.attributeDeclarations.add(new AttributeDeclaration(emptyIfNull(prefix), ns, ln, value));
}
}

Expand Down Expand Up @@ -483,13 +491,20 @@ public SOAPElement flushTo(final SOAPElement target) throws XMLStreamException {
newElement = target.addChildElement(this.localName, this.prefix, this.namespaceUri);
}
// add namespace declarations
for (NamespaceDeclaration namespace : this.namespaceDeclarations) {
newElement.addNamespaceDeclaration(namespace.prefix, namespace.namespaceUri);
for (Map.Entry<String, String> namespace : this.namespaceDeclarations.entrySet()) {
newElement.addNamespaceDeclaration(namespace.getValue(), namespace.getKey());
}
// add attribute declarations
for (AttributeDeclaration attribute : this.attributeDeclarations) {
String pfx = attribute.prefix;
if ("".equals(emptyIfNull(pfx))) {
String p = this.namespaceDeclarations.get(attribute.namespaceUri);
if (p != null) {
pfx = p;
}
}
addAttibuteToElement(newElement,
attribute.prefix, attribute.namespaceUri, attribute.localName, attribute.value);
pfx, attribute.namespaceUri, attribute.localName, attribute.value);
}
// reset state
this.reset();
Expand Down Expand Up @@ -525,16 +540,6 @@ private static String emptyIfNull(String s) {
}
}

static class NamespaceDeclaration {
final String prefix;
final String namespaceUri;

NamespaceDeclaration(String prefix, String namespaceUri) {
this.prefix = prefix;
this.namespaceUri = namespaceUri;
}
}

static class AttributeDeclaration {
final String prefix;
final String namespaceUri;
Expand Down

0 comments on commit 4851b23

Please sign in to comment.