in support/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/GenerateRestXML.java [57:107]
public void execute() throws MojoExecutionException {
if (inputFile == null) {
throw new MojoExecutionException("Missing input file: " + inputFile);
}
Path input = Paths.get(this.inputFile);
if (!Files.exists(input)) {
throw new MojoExecutionException("Unable to read the input file: " + inputFile);
}
try {
JsonFactory factory = null;
if (inputFile.endsWith(".yaml") || inputFile.endsWith(".yml")) {
factory = new YAMLFactory();
}
ObjectMapper mapper = new ObjectMapper(factory);
mapper.findAndRegisterModules();
FileInputStream fis = new FileInputStream(inputFile);
JsonNode node = mapper.readTree(fis);
OpenApiDocument document = (OpenApiDocument) Library.readDocument(JsonUtil.toObject(node));
final Writer writer;
if (outputFile != null) {
Path output = Paths.get(this.outputFile);
if (output.getParent() != null && Files.notExists(output.getParent())) {
Files.createDirectories(output.getParent());
}
if (Files.exists(output)) {
Files.delete(output);
}
writer = Files.newBufferedWriter(output);
} else {
writer = new PrintWriter(System.out);
}
final CamelContext context = new DefaultCamelContext();
final String dsl = RestDslXmlGenerator.toXml(document).generate(context);
try (writer) {
writer.write(dsl);
}
} catch (Exception e) {
throw new MojoExecutionException("Exception while generating rest xml", e);
}
}