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;
}
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;
}
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;
}
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);
}
}
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");
}
}
Aggregations