/** * Reads the SOAP fault. * * @param reader The reader. * @return SOAP fault details. */ private SoapFaultDetails readSoapFault(EwsXmlReader reader) { SoapFaultDetails soapFaultDetails = null; try { reader.read(); if (reader.getNodeType().getNodeType() == XmlNodeType.START_DOCUMENT) { reader.read(); } if (!reader.isStartElement() || (!reader.getLocalName().equals(XmlElementNames.SOAPEnvelopeElementName))) { return null; } // Get the namespace URI from the envelope element and use it for // the rest of the parsing. // If it's not 1.1 or 1.2, we can't continue. XmlNamespace soapNamespace = EwsUtilities.getNamespaceFromUri(reader.getNamespaceUri()); if (soapNamespace == XmlNamespace.NotSpecified) { return null; } reader.read(); // Skip SOAP header. if (reader.isStartElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)) { do { reader.read(); } while (!reader.isEndElement(soapNamespace, XmlElementNames.SOAPHeaderElementName)); // Queue up the next read reader.read(); } // Parse the fault element contained within the SOAP body. if (reader.isStartElement(soapNamespace, XmlElementNames.SOAPBodyElementName)) { do { reader.read(); // Parse Fault element if (reader.isStartElement(soapNamespace, XmlElementNames.SOAPFaultElementName)) { soapFaultDetails = SoapFaultDetails.parse(reader, soapNamespace); } } while (!reader.isEndElement(soapNamespace, XmlElementNames.SOAPBodyElementName)); } reader.readEndElement(soapNamespace, XmlElementNames.SOAPEnvelopeElementName); } catch (Exception e) { // If response doesn't contain a valid SOAP fault, just ignore // exception and // return null for SOAP fault details. e.printStackTrace(); } return soapFaultDetails; }
/** * Parses the. * * @param reader the reader * @param soapNamespace the soap namespace * @return the soap fault details * @throws Exception the exception */ public static SoapFaultDetails parse(EwsXmlReader reader, XmlNamespace soapNamespace) throws Exception { SoapFaultDetails soapFaultDetails = new SoapFaultDetails(); do { reader.read(); if (reader.getNodeType().equals(new XmlNodeType(XmlNodeType.START_ELEMENT))) { String localName = reader.getLocalName(); if (localName.equals(XmlElementNames.SOAPFaultCodeElementName)) { soapFaultDetails.setFaultCode(reader.readElementValue()); } else if (localName.equals(XmlElementNames.SOAPFaultStringElementName)) { soapFaultDetails.setFaultString(reader.readElementValue()); } else if (localName.equals(XmlElementNames.SOAPFaultActorElementName)) { soapFaultDetails.setFaultActor(reader.readElementValue()); } else if (localName.equals(XmlElementNames.SOAPDetailElementName)) { soapFaultDetails.parseDetailNode(reader); } } } while (!reader.isEndElement(soapNamespace, XmlElementNames.SOAPFaultElementName)); return soapFaultDetails; }