added java future for response handling

This commit is contained in:
Aditya Mayukh Som
2024-03-24 18:50:38 +05:30
parent 4d997f4e85
commit 8c011d27ba

@ -50,29 +50,20 @@ public class Main {
.setBody(bodyContent)\n .setBody(bodyContent)\n
'''; ''';
final String kTemplateRequestEnd = """ final String kTemplateRequestEnd = '''
.build(); Future<Response> whenResponse = requestBuilder.execute();
ListenableFuture<Response> listenableFuture = asyncHttpClient.executeRequest(request); Response response = whenResponse.get();
listenableFuture.addListener(() -> {
try {
Response response = listenableFuture.get();
InputStream is = response.getResponseBodyAsStream(); InputStream is = response.getResponseBodyAsStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
String respBody = br.lines().collect(Collectors.joining("\\n")); String respBody = br.lines().collect(Collectors.joining("\\n"));
System.out.println(response.getStatusCode()); System.out.println(response.getStatusCode());
System.out.println(respBody); System.out.println(respBody);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}, Executors.newCachedThreadPool());
listenableFuture.get();
} catch (InterruptedException | ExecutionException | IOException ignored) { } catch (InterruptedException | ExecutionException | IOException ignored) {
} }
} }
} }\n
\n ''';
""";
String? getCode( String? getCode(
RequestModel requestModel, RequestModel requestModel,