Search in sources :

Example 1 with BasicHttpClient

use of org.bedework.util.http.BasicHttpClient in project bw-calendar-engine by Bedework.

the class AbstractDirImpl method find.

@Override
public List<BwPrincipalInfo> find(final String cua, final String cutype, final boolean expand, final Holder<Boolean> truncated) throws CalFacadeException {
    final CardDavInfo cdi = getCardDavInfo(false);
    if ((cdi == null) || (cdi.getHost() == null)) {
        return null;
    }
    BasicHttpClient cdc = null;
    try {
        cdc = new BasicHttpClient(cdi.getHost(), cdi.getPort(), null, 15 * 1000);
        final List<BwPrincipalInfo> pis = find(cdc, cdi, cua, cutype);
        if (!expand) {
            return pis;
        }
        for (final BwPrincipalInfo pi : pis) {
            if (!Kind.GROUP.getValue().equalsIgnoreCase(pi.getKind())) {
                continue;
            }
            final List<BwPrincipalInfo> memberPis = new ArrayList<>();
            VCard card = pi.getCard();
            List<Property> members = card.getProperties(Id.MEMBER);
            if (members == null) {
                continue;
            }
            for (final Property p : members) {
                BwPrincipalInfo memberPi = fetch(cdc, cdi, p.getValue());
                if (memberPi != null) {
                    memberPis.add(memberPi);
                }
            }
            pi.setMembers(memberPis);
        }
        return pis;
    } catch (final Throwable t) {
        if (getLogger().isDebugEnabled()) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        if (cdc != null) {
            try {
                cdc.release();
            } catch (final Throwable ignored) {
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) BasicHttpClient(org.bedework.util.http.BasicHttpClient) CardDavInfo(org.bedework.calfacade.configs.CardDavInfo) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo) VCard(net.fortuna.ical4j.vcard.VCard) BooleanPrincipalProperty(org.bedework.calfacade.BwPrincipalInfo.BooleanPrincipalProperty) IntPrincipalProperty(org.bedework.calfacade.BwPrincipalInfo.IntPrincipalProperty) Property(net.fortuna.ical4j.vcard.Property) WebdavProperty(org.bedework.webdav.servlet.shared.WebdavProperty) BwProperty(org.bedework.calfacade.BwProperty) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with BasicHttpClient

use of org.bedework.util.http.BasicHttpClient in project bw-calendar-engine by Bedework.

the class AbstractDirImpl method getDirInfo.

@Override
public BwPrincipalInfo getDirInfo(final BwPrincipal p) throws CalFacadeException {
    BwPrincipalInfo pi = principalInfoMap.get(p.getPrincipalRef());
    if (pi != null) {
        return pi;
    }
    // If carddav lookup is enabled - use that
    final CardDavInfo cdi = getCardDavInfo(false);
    if ((cdi == null) || (cdi.getHost() == null)) {
        return null;
    }
    BasicHttpClient cdc = null;
    pi = new BwPrincipalInfo();
    try {
        cdc = new BasicHttpClient(cdi.getHost(), cdi.getPort(), null, 15 * 1000);
        pi.setPropertiesFromVCard(getCard(cdc, cdi.getContextPath(), p), "text/vcard");
    } catch (final Throwable t) {
        if (getLogger().isDebugEnabled()) {
            error(t);
        }
    } finally {
        if (cdc != null) {
            cdc.close();
        }
    }
    principalInfoMap.put(p.getPrincipalRef(), pi);
    return pi;
}
Also used : BasicHttpClient(org.bedework.util.http.BasicHttpClient) CardDavInfo(org.bedework.calfacade.configs.CardDavInfo) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo)

Example 3 with BasicHttpClient

use of org.bedework.util.http.BasicHttpClient in project bw-calendar-engine by Bedework.

the class NotificationClient method sendRequest.

private void sendRequest(final Object req, final String path) throws CalFacadeException {
    if (np.getNotifierURI() == null) {
        // Assume not enabled
        return;
    }
    synchronized (this) {
        try {
            final BasicHttpClient cl = getClient();
            cl.setBaseURI(new URI(np.getNotifierURI()));
            final StringWriter sw = new StringWriter();
            om.writeValue(sw, req);
            final byte[] content = sw.toString().getBytes();
            final int status = cl.sendRequest("POST", path, // hdrs
            null, "application/json", content.length, content);
            if (status != HttpServletResponse.SC_OK) {
                warn("Unable to post notification");
            }
        } catch (final Throwable t) {
            if (debug) {
                error(t);
            }
            error("Unable to contact notification engine " + t.getLocalizedMessage());
        } finally {
            try {
                getClient().release();
            } catch (final Throwable t) {
                warn("Error on close " + t.getLocalizedMessage());
            }
        }
    }
}
Also used : StringWriter(java.io.StringWriter) BasicHttpClient(org.bedework.util.http.BasicHttpClient) URI(java.net.URI)

Example 4 with BasicHttpClient

use of org.bedework.util.http.BasicHttpClient in project bw-calendar-engine by Bedework.

the class AbstractDirImpl method find.

@Override
public List<BwPrincipalInfo> find(final List<WebdavProperty> props, final List<WebdavProperty> returnProps, final String cutype, final Holder<Boolean> truncated) throws CalFacadeException {
    final CardDavInfo cdi = getCardDavInfo(false);
    if ((cdi == null) || (cdi.getHost() == null)) {
        return null;
    }
    BasicHttpClient cdc = null;
    final String path = getCutypePath(cutype, cdi);
    String addrCtype = null;
    /* See if we want address data in any particular form */
    for (final WebdavProperty wd : returnProps) {
        if (!wd.getTag().equals(CarddavTags.addressData)) {
            continue;
        }
        addrCtype = wd.getAttr("content-type");
        break;
    }
    try {
        cdc = new BasicHttpClient(cdi.getHost(), cdi.getPort(), null, 15 * 1000);
        final List<MatchResult> mrs = matching(cdc, cdi.getContextPath() + path, addrCtype, props);
        final List<BwPrincipalInfo> pis = new ArrayList<>();
        if (mrs == null) {
            return pis;
        }
        for (final MatchResult mr : mrs) {
            final BwPrincipalInfo pi = new BwPrincipalInfo();
            pi.setPropertiesFromVCard(mr.card, addrCtype);
            pis.add(pi);
        }
        return pis;
    } catch (final Throwable t) {
        if (getLogger().isDebugEnabled()) {
            error(t);
        }
        throw new CalFacadeException(t);
    } finally {
        if (cdc != null) {
            cdc.close();
        }
    }
}
Also used : WebdavProperty(org.bedework.webdav.servlet.shared.WebdavProperty) ArrayList(java.util.ArrayList) BasicHttpClient(org.bedework.util.http.BasicHttpClient) CardDavInfo(org.bedework.calfacade.configs.CardDavInfo) BwPrincipalInfo(org.bedework.calfacade.BwPrincipalInfo) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BasicHttpClient (org.bedework.util.http.BasicHttpClient)4 BwPrincipalInfo (org.bedework.calfacade.BwPrincipalInfo)3 CardDavInfo (org.bedework.calfacade.configs.CardDavInfo)3 ArrayList (java.util.ArrayList)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 WebdavProperty (org.bedework.webdav.servlet.shared.WebdavProperty)2 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 Property (net.fortuna.ical4j.vcard.Property)1 VCard (net.fortuna.ical4j.vcard.VCard)1 BooleanPrincipalProperty (org.bedework.calfacade.BwPrincipalInfo.BooleanPrincipalProperty)1 IntPrincipalProperty (org.bedework.calfacade.BwPrincipalInfo.IntPrincipalProperty)1 BwProperty (org.bedework.calfacade.BwProperty)1