| Import | Purpose |
org.apache.hc.client5.http.* | Apache HttpClient 5 for HTTP communication (HttpGet, CloseableHttpClient, HttpClients, ClassicHttpResponse, ContentType, HttpEntity, HttpClientResponseHandler, StringEntity, ClassicRequestBuilder, HttpCoreContext) |
org.projectforge.common.extensions.abbreviate | Kotlin extension function to truncate long strings in log output |
java.util.Base64 | JDK Base64 encoder for HTTP Basic Authentication header |
Class Structure: CardDavTestClient
Constructor Parameters
baseUrl: String — Server base URL (default: http://localhost:8080/carddav)
username: String — CardDAV username for Basic auth
password: String — CardDAV password (DAV token)
lastSyncToken: String? — Optional sync token for incremental sync testing
Inner Class: ResponseData
Simple data class holding content: String, status: Int, and headers: String from HTTP responses.
Authentication
Uses HTTP Basic Authentication with the Authorization: Basic {base64(username:password)} header, constructed once at initialization.
Response Handler
A functional HttpClientResponseHandler that reads the response entity as UTF-8 text and extracts status code and headers.
Key Methods
run() — Default Test Sequence
Executes a CardDAV protocol flow: OPTIONS → GET (VCard) → GET (photo). Most of the original test code (PROPFIND, REPORT, sync-collection) is commented out with XML request body examples preserved for reference.
fetchAllVCards() — Batch VCard Export
Fetches all VCards from the server using a CardDAV addressbook-query REPORT request, saves each VCard to /tmp/carddav-vcards/, and analyzes PHOTO entries. Reports statistics on:
- JPEG/PNG/GIF URL references vs embedded base64 images
- Contacts with no photo
- Error counts
This method was instrumental in debugging the CardDAV photo handling (URL vs embedded modes).
sendRequest() — Generic HTTP Request
Builds and executes HTTP requests with configurable method, path, body, authentication, and logging. Uses ClassicRequestBuilder from Apache HttpClient 5.
analyzePhoto(vcard) — PHOTO Property Parser
Parses VCard data to determine photo encoding mode:
- URL mode:
PHOTO;VALUE=URI:https://... — photo served via URL
- Embedded mode:
PHOTO;ENCODING=b;TYPE=JPEG:base64data... or data:image/jpeg;base64,...
Handles VCard line folding (continuation lines starting with whitespace).
Main Function — CLI Interface
Usage: CardDavTestClient <username> <dav-token> [--fetch-all]
--fetch-all: Fetch all VCards from server and save to /tmp/carddav-vcards/
Positional arguments: username, DAV token, optional base URL, optional sync token.
The file contains commented-out reference data showing real CardDAV server responses:
Request with method=OPTIONS for Milton (uri=/users/username/, session-id=null)
Basic authentication failed, header 'authorization' not found.
PROPFIND call detected: /users/username/
PROPFIND for Milton (uri=/users/username/addressBooks/default/
REPORT for Milton (uri=/users/username/addressBooks/default/
This reveals the CardDAV server was originally built on the
Milton WebDAV framework, and the current implementation reimplements that protocol natively.
The file serves as both a test client and living documentation of the CardDAV protocol implementation. The commented-out PROPFIND/REPORT request bodies are valid CardDAV XML that document the expected server behavior.
Git History
868d6abb7 2025 -> 2026
bbf6b792c VCard upload: special handling of form field.
f2ceb72f1 CardDav: photo-urls relative.
63081666f Source file headers: 2024-> 2025.
943947aaa Addresses: support of gif and jpeg (also for carddav server).
fc6301b43 WIP: CardDavServer.
c4062ed97 WIP: Carddav
40e554cbe WIP: Carddav