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);
}
Aggregations