EN · DE · RU · FR · ES

#1865: CarddavTestClient.kt

projectforge-carddav/src/test/kotlin/org/projectforge/carddav/CarddavTestClient.kt Test utility / development tool — org.projectforge.carddav package, projectforge-carddav/src/test/kotlin/org/projectforge/carddav/CarddavTestClient.kt 468 lines · 372 code · 60 comments · 36 blank
Standalone CardDAV test client with a main() function and an HTTP client class. Used for manual testing and debugging of the CardDAV server. Supports OPTIONS/PROPFIND/GET/REPORT requests, sync-token collection, VCard fetching with PHOTO analysis, and batch export of all contacts. Includes extensive commented-out test sequences showing the iterative development of CardDAV protocol support.

Architecture

This is a development debugging tool, not a unit test. It has a main() entry point and acts as a standalone CardDAV client for testing the server implementation. The file contains extensive commented-out code showing the evolution of CardDAV protocol testing.

Imports and Dependencies

Class Structure: CardDavTestClient

Constructor Parameters

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:

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:

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
ImportPurpose
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.abbreviateKotlin extension function to truncate long strings in log output
java.util.Base64JDK Base64 encoder for HTTP Basic Authentication header