Advertisement
shakasu

Untitled

Feb 24th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. import io.vertx.core.Future;
  2. import io.vertx.core.Promise;
  3. import io.vertx.core.Vertx;
  4. import io.vertx.core.buffer.Buffer;
  5. import io.vertx.core.http.HttpMethod;
  6. import io.vertx.core.http.HttpServer;
  7. import io.vertx.core.json.JsonObject;
  8. import io.vertx.ext.web.Route;
  9. import io.vertx.ext.web.Router;
  10. import io.vertx.ext.web.client.HttpResponse;
  11. import io.vertx.ext.web.client.WebClient;
  12.  
  13. import java.util.concurrent.atomic.AtomicReference;
  14.  
  15. public class NotMigrator {
  16.     final private static int PORT_TDG = 8181;
  17.     final private static int PORT_MY = 8080;
  18.     final private static String HOST = "localhost";
  19.     final private static String TOKEN = "9f226286-e0d8-4125-ad43-b123b4e464da";
  20.     final private static String TYPE = "application/json;charset=utf-8";
  21.     final private static String PATH = "/api/migrate/graphql";
  22.  
  23.     public static void main(String[] args) throws Exception {
  24.         Vertx vertx = Vertx.vertx();
  25.         HttpServer server = vertx.createHttpServer();
  26.         Router router = Router.router(vertx);
  27.         WebClient client = WebClient.create(vertx);
  28.  
  29.         JsonObject req = new JsonObject()
  30.                 .put("query", "{Book { uuid, book_name, author }}");
  31.  
  32.         NotMigrator migrator = new NotMigrator();
  33.         router
  34.                 .get(PATH)
  35.                 .respond(ctx -> Future.succeededFuture(migrator.graphql(req, client)));
  36.  
  37.         server.requestHandler(router).listen(8080);
  38.     }
  39.  
  40.     public Future<HttpResponse<Buffer>> graphql(JsonObject request, WebClient client) {
  41.         Promise<HttpResponse<Buffer>> promise = Promise.promise();
  42.         client
  43.                 .post("/graphql")
  44.                 .sendJson(request, t -> {
  45.                     if (t.succeeded()) {
  46.                         promise.complete(t.result());
  47.                     } else {
  48.                         promise.fail(new Exception("Error while sending request to tarantool", t.cause()));
  49.                     }
  50.                 });
  51.         return promise.future();
  52.  
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement