diff --git a/src/main/java/de/tudan/otrsclient/OtrsSoapMessageParser.java b/src/main/java/de/tudan/otrsclient/OtrsSoapMessageParser.java index c962cd9..14167d6 100644 --- a/src/main/java/de/tudan/otrsclient/OtrsSoapMessageParser.java +++ b/src/main/java/de/tudan/otrsclient/OtrsSoapMessageParser.java @@ -6,10 +6,13 @@ import org.w3c.dom.NodeList; import javax.xml.XMLConstants; +import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPException; import javax.xml.soap.SOAPMessage; + import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -29,8 +32,7 @@ private Object nodeToObject(Node node) { } public Object[] nodesToArray(SOAPMessage msg) throws SOAPException { - Document doc = msg.getSOAPPart().getEnvelope().getBody().extractContentAsDocument(); - Element el = doc.getDocumentElement(); + Element el = getDispatchResponse(msg.getSOAPPart().getEnvelope().getBody()); NodeList nl = el.getChildNodes(); Object[] results = new Object[nl.getLength()]; @@ -48,8 +50,7 @@ public List nodesToList(SOAPMessage msg) throws SOAPException { public Map nodesToMap(SOAPMessage msg) throws SOAPException { Map map = new HashMap<>(); - Document doc = msg.getSOAPPart().getEnvelope().getBody().extractContentAsDocument(); - Element el = doc.getDocumentElement(); + Element el = getDispatchResponse(msg.getSOAPPart().getEnvelope().getBody()); NodeList nl = el.getChildNodes(); for (int i = 0; i < (nl.getLength() / 2); i++) { @@ -63,4 +64,28 @@ public Map nodesToMap(SOAPMessage msg) throws SOAPException { return map; } + + private Element getDispatchResponse(SOAPBody body) throws SOAPException{ + Element dispatchResponse = null; + try { + Document doc = body.extractContentAsDocument(); + dispatchResponse = doc.getDocumentElement(); + } catch (SOAPException e){ + //Workaround for CustomerUserDataGet because it returns more child elements in SOAP:Body + @SuppressWarnings("unchecked") + Iterator it = body.getChildElements(); + while(it.hasNext() && dispatchResponse == null){ + Element tmp = it.next(); + if(tmp.getNodeName().equals("DispatchResponse")){ + dispatchResponse = tmp; + } + } + //If the DispatchResponse can still not been found throw the SOAPException + if(dispatchResponse == null){ + throw e; + } + } + + return dispatchResponse; + } }