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

com.zandero.rest.writer.PlainResponseWriter Maven / Gradle / Ivy

The newest version!
package com.zandero.rest.writer;

import io.vertx.core.http.*;
import org.slf4j.*;

import static io.vertx.core.http.HttpHeaders.CONTENT_TYPE;

/**
 * Returns toString() output
 *
 * @param  provided response type
 */
// @Produces("html/text")
public class PlainResponseWriter implements HttpResponseWriter {

    private final static Logger log = LoggerFactory.getLogger(PlainResponseWriter.class);

    @Override
    public void write(T result, HttpServerRequest request, HttpServerResponse response) {

        String mediaType = response.headers().get(CONTENT_TYPE);
        log.warn(request.path() + " - no writer for Content-Type='" + mediaType + "', defaulting to toString() as output!");
        if (result != null) {
            response.end(result.toString());
        } else {
            response.end();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy