Advertisement
shakasu

Untitled

Feb 24th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. import io.vertx.core.Future;
  2. import io.vertx.core.Vertx;
  3. import io.vertx.core.http.HttpMethod;
  4. import io.vertx.core.http.HttpServer;
  5. import io.vertx.core.json.JsonObject;
  6. import io.vertx.ext.web.Route;
  7. import io.vertx.ext.web.Router;
  8. import io.vertx.ext.web.client.WebClient;
  9.  
  10. import java.util.concurrent.atomic.AtomicReference;
  11.  
  12. public class NotMigrator {
  13.     final private static int PORT_TDG = 8181;
  14.     final private static int PORT_MY = 8080;
  15.     final private static String HOST = "localhost";
  16.     final private static String TOKEN = "9f226286-e0d8-4125-ad43-b123b4e464da";
  17.     final private static String TYPE = "application/json;charset=utf-8";
  18.     final private static String PATH = "/api/migrate/graphql";
  19.  
  20.     public static void main(String[] args) throws Exception {
  21.         Vertx vertx = Vertx.vertx();
  22.         HttpServer server = vertx.createHttpServer();
  23.         Router router = Router.router(vertx);
  24.         WebClient client = WebClient.create(vertx);
  25.  
  26.         router
  27.                 .get(PATH)
  28.                 .respond(ctx -> Future.succeededFuture(new JsonObject().put("hello", "world")));
  29.  
  30.         server.requestHandler(router).listen(8080);
  31.     }
  32.  
  33.     public void get(WebClient client) {
  34.         client
  35.                 .post(PORT_TDG, HOST, "/graphql")
  36.                 .putHeader("Content-Type", "application/json")
  37.                 .sendJsonObject(
  38.                         new JsonObject()
  39.                                 .put("query", "{Book(first: 100) { uuid, book_name, author }}")
  40.                 )
  41.                 .onSuccess(res -> {
  42.                     if (res.statusCode() == 200 &&
  43.                             res.getHeader("content-type").equals(TYPE)) {
  44.                         JsonObject body = res.bodyAsJsonObject();
  45.                         //объект json
  46.                     }
  47.                 });
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement