Search in sources :

Example 1 with XmlParseException

use of com.zimbra.common.soap.XmlParseException in project zm-mailbox by Zimbra.

the class ExchangeFreeBusyProvider method getFreeBusyForHost.

public List<FreeBusy> getFreeBusyForHost(String host, ArrayList<Request> req) throws IOException {
    ArrayList<FreeBusy> ret = new ArrayList<FreeBusy>();
    int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
    Request r = req.get(0);
    ServerInfo serverInfo = (ServerInfo) r.data;
    if (serverInfo == null) {
        ZimbraLog.fb.warn("no exchange server info for user " + r.email);
        return ret;
    }
    if (!serverInfo.enabled) {
        return ret;
    }
    String url = constructGetUrl(serverInfo, req);
    ZimbraLog.fb.debug("fetching fb from url=" + url);
    HttpRequestBase method = new HttpGet(url);
    Element response = null;
    HttpResponse httpResponse = null;
    try {
        httpResponse = sendRequest(method, serverInfo);
        int status = httpResponse.getStatusLine().getStatusCode();
        if (status != 200)
            return getEmptyList(req);
        if (ZimbraLog.fb.isDebugEnabled()) {
            Header cl = httpResponse.getFirstHeader(HttpHeader.CONTENT_LENGTH.name());
            int contentLength = 10240;
            if (cl != null)
                contentLength = Integer.valueOf(cl.getValue());
            String buf = new String(com.zimbra.common.util.ByteUtil.readInput(httpResponse.getEntity().getContent(), contentLength, contentLength), "UTF-8");
            ZimbraLog.fb.debug(buf);
            response = Element.parseXML(buf);
        } else
            response = Element.parseXML(httpResponse.getEntity().getContent());
    } catch (XmlParseException e) {
        ZimbraLog.fb.warn("error parsing fb response from exchange", e);
        return getEmptyList(req);
    } catch (IOException | HttpException e) {
        ZimbraLog.fb.warn("error parsing fb response from exchange", e);
        return getEmptyList(req);
    } finally {
        EntityUtils.consumeQuietly(httpResponse.getEntity());
    }
    for (Request re : req) {
        String fb = getFbString(response, re.email);
        ret.add(new ExchangeUserFreeBusy(fb, re.email, fb_interval, re.start, re.end));
    }
    return ret;
}
Also used : HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpGet(org.apache.http.client.methods.HttpGet) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) XmlParseException(com.zimbra.common.soap.XmlParseException) IOException(java.io.IOException) Header(org.apache.http.Header) HttpHeader(org.eclipse.jetty.http.HttpHeader) HttpException(org.apache.http.HttpException)

Example 2 with XmlParseException

use of com.zimbra.common.soap.XmlParseException in project zm-mailbox by Zimbra.

the class RetentionPolicyManager method getCachedSystemPolicy.

private SystemPolicy getCachedSystemPolicy(Entry entry) throws ServiceException {
    SystemPolicy sp;
    synchronized (entry) {
        sp = (SystemPolicy) entry.getCachedData(SYSTEM_POLICY_KEY);
        if (sp == null) {
            String xml;
            if (entry instanceof Config)
                xml = ((Config) entry).getMailPurgeSystemPolicy();
            else if (entry instanceof Cos)
                xml = ((Cos) entry).getMailPurgeSystemPolicy();
            else
                throw ServiceException.UNSUPPORTED();
            sp = new SystemPolicy();
            if (!Strings.isNullOrEmpty(xml)) {
                ZimbraLog.purge.debug("Parsing system retention policy:\n%s", xml);
                try {
                    Element el = Element.parseXML(xml);
                    RetentionPolicy rp = JaxbUtil.elementToJaxb(el, RetentionPolicy.class);
                    for (Policy p : rp.getKeepPolicy()) {
                        assert (p.getId() != null);
                        sp.keep.put(p.getId(), p);
                    }
                    for (Policy p : rp.getPurgePolicy()) {
                        assert (p.getId() != null);
                        sp.purge.put(p.getId(), p);
                    }
                } catch (XmlParseException e) {
                    throw ServiceException.FAILURE("Unable to parse system retention policy.", e);
                }
            }
            entry.setCachedData(SYSTEM_POLICY_KEY, sp);
        }
    }
    return sp;
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Config(com.zimbra.cs.account.Config) Cos(com.zimbra.cs.account.Cos) XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) XmlParseException(com.zimbra.common.soap.XmlParseException) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy)

Example 3 with XmlParseException

use of com.zimbra.common.soap.XmlParseException in project zm-mailbox by Zimbra.

the class WebDavClient method sendMultiResponseRequest.

public Collection<DavObject> sendMultiResponseRequest(DavRequest req) throws IOException, DavException, HttpException {
    ArrayList<DavObject> ret = new ArrayList<DavObject>();
    HttpResponse response = null;
    try {
        response = executeFollowRedirect(req);
        int status = response.getStatusLine().getStatusCode();
        if (status >= 400) {
            throw new DavException("DAV server returned an error: " + status, status);
        }
        Document doc = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(response.getEntity().getContent());
        Element top = doc.getRootElement();
        for (Object obj : top.elements(DavElements.E_RESPONSE)) {
            if (obj instanceof Element) {
                ret.add(new DavObject((Element) obj));
            }
        }
    } catch (XmlParseException e) {
        throw new DavException("can't parse response", e);
    } finally {
        if (response != null) {
            EntityUtils.consume(response.getEntity());
        }
    }
    return ret;
}
Also used : DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) XmlParseException(com.zimbra.common.soap.XmlParseException) Document(org.dom4j.Document)

Example 4 with XmlParseException

use of com.zimbra.common.soap.XmlParseException in project zm-mailbox by Zimbra.

the class TestCalDav method setGroupMemberSet.

public static Document setGroupMemberSet(String url, Account acct, Account memberAcct) throws IOException, XmlParseException {
    PropPatchMethod method = new PropPatchMethod(url);
    addBasicAuthHeaderForUser(method, acct);
    HttpClient client = HttpClientBuilder.create().build();
    TestCalDav.HttpMethodExecutor executor;
    method.addHeader("Content-Type", MimeConstants.CT_TEXT_XML);
    String body = TestCalDav.propPatchGroupMemberSetTemplate.replace("%%MEMBER%%", UrlNamespace.getPrincipalUrl(memberAcct, memberAcct));
    method.setEntity(new ByteArrayEntity(body.getBytes(), org.apache.http.entity.ContentType.create(MimeConstants.CT_TEXT_XML)));
    try {
        executor = new TestCalDav.HttpMethodExecutor(client, method, HttpStatus.SC_MULTI_STATUS);
        return executor.getResponseDoc(DavElements.P_MULTISTATUS);
    } catch (Exception e) {
        throw new IOException("Unexpected error", e);
    }
}
Also used : ByteArrayEntity(org.apache.http.entity.ByteArrayEntity) HttpClient(org.apache.http.client.HttpClient) IOException(java.io.IOException) XPathExpressionException(javax.xml.xpath.XPathExpressionException) XmlParseException(com.zimbra.common.soap.XmlParseException) HttpException(org.apache.http.HttpException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException)

Example 5 with XmlParseException

use of com.zimbra.common.soap.XmlParseException in project zm-mailbox by Zimbra.

the class ZimletMeta method addToElement.

/*
	 * attaches the DOM tree underneath the Element passed in.
	 */
public void addToElement(Element elem) throws ZimletException {
    try {
        // TODO: cache parsed structure or result or both.
        Element newElem = W3cDomUtil.parseXML(toXMLString(), elem.getFactory());
        elem.addElement(newElem);
    } catch (XmlParseException de) {
        throw ZimletException.ZIMLET_HANDLER_ERROR("cannot parse the dom tree");
    }
}
Also used : Element(com.zimbra.common.soap.Element) XmlParseException(com.zimbra.common.soap.XmlParseException)

Aggregations

XmlParseException (com.zimbra.common.soap.XmlParseException)8 Element (com.zimbra.common.soap.Element)4 ServiceException (com.zimbra.common.service.ServiceException)3 IOException (java.io.IOException)3 HttpException (org.apache.http.HttpException)3 HttpResponse (org.apache.http.HttpResponse)3 HttpClient (org.apache.http.client.HttpClient)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 XPathExpressionException (javax.xml.xpath.XPathExpressionException)2 Header (org.apache.http.Header)2 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)2 ByteArrayEntity (org.apache.http.entity.ByteArrayEntity)2 Document (org.dom4j.Document)2 Element (org.dom4j.Element)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1