Embedding OnlyOffice in Spring Boot for In-Browser Word and Excel Editing
Teams that already run Spring Boot services can add browser-based Office editing without reaching for Google Docs APIs or Microsoft 365 cloud dependencies. OnlyOffice's Community Edition is free and self-hosted, so document data stays on your own infrastructure.
The integration runs OnlyOffice's Community Edition Docker image and wires it to a Spring Boot backend that handles file upload, download via one-time tokens, and save callbacks. Two plain HTML pages — a file manager and an editor host — load the OnlyOffice frontend SDK dynamically, turning any DOCX, XLSX, or PPTX file into an editable browser session.
A JWT signing step, using the Nimbus library, secures the configuration payload passed to the document server. The callback endpoint listens for status 2 (document ready for saving) and status 6 (editing finished), then fetches the updated file from OnlyOffice and overwrites local storage. File type detection and content-type mapping are handled through simple extension-based switch expressions.
The whole setup — Docker run command, Maven dependencies, controller code, and frontend HTML — fits into a single walkthrough. The result is a self-contained online Office editor that persists edits without external storage services.
The integration deliberately avoids a database — file state lives on disk and token-to-filename mappings sit in an in-memory map, which works for a single-instance demo but would break across multiple app nodes without shared storage.
Using a static JWT secret hardcoded in a constants class is expedient for a tutorial but skips any discussion of secret rotation or environment-based configuration, which a production deployment would need.
The callback handler writes the downloaded file to a .tmp path first and then moves it into place, a small atomicity detail that prevents serving a partially written file if the download fails mid-stream.