use of com.zimbra.common.soap.SoapParseException in project zm-mailbox by Zimbra.
the class JaxbToElementTest method getElementForEnvelopedJSON.
private static Element getElementForEnvelopedJSON(String json) {
Element envelope = null;
try {
envelope = Element.parseJSON(json);
} catch (SoapParseException e) {
Assert.fail(String.format("Parse from JSON to Element failed - %s", e.getMessage()));
}
Assert.assertNotNull("Envelope element from parse from JSON", envelope);
Element inner = envelope.listElements().get(0);
Assert.assertNotNull("element inside envelope element from parse from JSON", inner);
return inner;
}
use of com.zimbra.common.soap.SoapParseException in project zm-mailbox by Zimbra.
the class SoapEngine method dispatch.
public Element dispatch(String path, byte[] soapMessage, Map<String, Object> context) throws CsrfTokenException {
if (soapMessage == null || soapMessage.length == 0) {
SoapProtocol soapProto = SoapProtocol.Soap12;
return soapFaultEnv(soapProto, "SOAP exception", ServiceException.PARSE_ERROR("empty request payload", null));
}
InputStream in = new ByteArrayInputStream(soapMessage);
Element document = null;
try {
if (soapMessage[0] == '<') {
document = Element.parseXML(in);
} else {
document = Element.parseJSON(in);
}
} catch (SoapParseException e) {
SoapProtocol soapProto = SoapProtocol.SoapJS;
logUnparsableRequest(context, soapMessage, e.getMessage());
return soapFaultEnv(soapProto, "SOAP exception", ServiceException.PARSE_ERROR(e.getMessage(), e));
} catch (XmlParseException e) {
logUnparsableRequest(context, soapMessage, e.getMessage());
SoapProtocol soapProto = chooseFaultProtocolFromBadXml(new ByteArrayInputStream(soapMessage));
return soapFaultEnv(soapProto, "SOAP exception", e);
}
Element resp = dispatch(path, document, context);
/*
* For requests(e.g. AuthRequest) that don't have account info in time when they
* are normally added to the logging context in dispatch after zsc is established
* from the SOAP request header. Thus account logging for zimbra.soap won't be
* effective when the SOAP request is logged in TRACE level normally.
*
* For AuthRequest, we call Account.addAccountToLogContext from the handler as
* soon as the account, which is only available in the SOAP body, is discovered.
* Account info should be available after dispatch() so account logger can be
* triggered.
*/
logRequest(context, document);
return resp;
}
Aggregations