1
votes

Good Morning everyone So I have this java code that parses into swagger documentation file (a JSON file) and split its:

{ Swagger swagger = new SwaggerParser().read("C:/Users/admin/Desktop/testdownload.txt");
  Map<String, Path> paths = swagger.getPaths();
  for (Map.Entry<String, Path> p : paths.entrySet()) {
    Path path = p.getValue();
    Map<HttpMethod, Operation> operations = path.getOperationMap();
    for (java.util.Map.Entry<HttpMethod, Operation> o : operations.entrySet()) {
      System.out.println("===");
      System.out.println("PATH:" + p.getKey());
      System.out.println("Http method:" + o.getKey());
      System.out.println("Summary:" + o.getValue().getSummary());
      System.out.println("Parameters number: " + o.getValue().getParameters().size());
      for (Parameter parameter : o.getValue().getParameters()) {
        System.out.println(" - " + parameter.getName());
      }
      System.out.println("Responses:");
      for (Map.Entry<String, Response> r : o.getValue().getResponses().entrySet()) {
        System.out.println(" - " + r.getKey() + ": " + r.getValue().getDescription());
      }
      System.out.println("");
    }

  }
}

And here is the input: input file and the output is : output file

What I want to ask is: is it possible to send this output one path by one to apache Nifi ?? is there is any solution that Nifi extracts those outputs and put each one of them in a dependent processor??

1
I don't have an immediate answer but some thoughts ... 1) NiFi allows you to write custom processors in Java ... you could write some Java code that takes the original input (txt) and writes a new FlowFlile per path entry. 2) Instead of transforming to your text format at the start, you may find a JSON extractor that can split your JSON into an array of paths and process that array. - Kolban
call nifi api to create processor instead of print out - daggett

1 Answers

1
votes

You could start a HTTP lister service in NiFi. Use the HandleHttpRequest

Some time ago I did something like this. And was sending data from my Java application to this HandleHttpRequest. This Processor is designed to be used in conjunction with the HandleHttpResponse Processor in order to create a Web Service

You just have to post your data to this webservice and the webservice can consume it and you would already have your data in NiFi. From then on, you are manipulate and control you data as you please.

enter image description here

You can also look into ListenHTTP