All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lsdconsulting.interceptors.messaging.HtmlRenderer.kt Maven / Gradle / Ivy

Go to download

Provides various interceptors to capture events for the lsd-core library to generate sequence diagrams

There is a newer version: 8.0.73
Show newest version
package io.lsdconsulting.interceptors.messaging

import j2html.TagCreator
import org.springframework.messaging.MessageHeaders

fun renderHtmlFor(messageHeaders: MessageHeaders, prettyBody: String?): String {
    return TagCreator.div(
        TagCreator.section(TagCreator.h3("Message Headers"), TagCreator.p(prettyPrintHeaders(messageHeaders))),
        if (prettyBody.isNullOrEmpty()) TagCreator.p()
        else TagCreator.section(
            TagCreator.h3("Body"),
            TagCreator.p(prettyBody)
        )
    ).render()
}

private fun prettyPrintHeaders(requestHeaders: MessageHeaders): String =
    requestHeaders.entries.joinToString(separator = System.lineSeparator()) { (key, value): Map.Entry ->
        "$key: $value"
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy