Search in sources :

Example 1 with UndefinedOutputFormatException

use of io.kroki.server.error.UndefinedOutputFormatException in project kroki by yuzutech.

the class DiagramHandler method getOutputFileFormatFromAcceptHeaders.

private FileFormat getOutputFileFormatFromAcceptHeaders(String serviceName, RoutingContext routingContext) {
    List<String> mimeTypes = routingContext.parsedHeaders().accept().stream().sorted(Comparator.comparingInt(ParsedHeaderValue::weightedOrder)).map(ParsedHeaderValue::value).collect(Collectors.toList());
    List<FileFormat> supportedFormats = service.getSupportedFormats();
    if (mimeTypes.isEmpty()) {
        throw new UndefinedOutputFormatException(serviceName, supportedFormats);
    }
    for (String mimeType : mimeTypes) {
        FileFormat fileFormat = ContentType.get(mimeType);
        if (fileFormat != null && supportedFormats.contains(fileFormat)) {
            return fileFormat;
        }
    }
    throw new UnsupportedMimeTypeException(mimeTypes, serviceName, supportedFormats);
}
Also used : UnsupportedMimeTypeException(io.kroki.server.error.UnsupportedMimeTypeException) UndefinedOutputFormatException(io.kroki.server.error.UndefinedOutputFormatException) FileFormat(io.kroki.server.format.FileFormat)

Aggregations

UndefinedOutputFormatException (io.kroki.server.error.UndefinedOutputFormatException)1 UnsupportedMimeTypeException (io.kroki.server.error.UnsupportedMimeTypeException)1 FileFormat (io.kroki.server.format.FileFormat)1