Search in sources :

Example 1 with SoapParseException

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;
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) JSONElement(com.zimbra.common.soap.Element.JSONElement) JAXBElement(javax.xml.bind.JAXBElement) SoapParseException(com.zimbra.common.soap.SoapParseException)

Example 2 with SoapParseException

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(com.zimbra.common.soap.Element) SoapProtocol(com.zimbra.common.soap.SoapProtocol) SoapParseException(com.zimbra.common.soap.SoapParseException) XmlParseException(com.zimbra.common.soap.XmlParseException)

Aggregations

Element (com.zimbra.common.soap.Element)2 SoapParseException (com.zimbra.common.soap.SoapParseException)2 JSONElement (com.zimbra.common.soap.Element.JSONElement)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 SoapProtocol (com.zimbra.common.soap.SoapProtocol)1 XmlParseException (com.zimbra.common.soap.XmlParseException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 JAXBElement (javax.xml.bind.JAXBElement)1