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

CustomerUserDataGet was not working #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/main/java/de/tudan/otrsclient/OtrsSoapMessageParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()];
Expand All @@ -48,8 +50,7 @@ public List<?> nodesToList(SOAPMessage msg) throws SOAPException {
public Map<String, Object> nodesToMap(SOAPMessage msg) throws SOAPException {
Map<String, Object> 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++) {
Expand All @@ -63,4 +64,28 @@ public Map<String, Object> 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<Element> 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;
}
}