In httpclient my response come late , till the time request block is executed and response is Null

20 views
Skip to first unread message

Yogesh Kumar

unread,
Oct 21, 2016, 1:18:50 AM10/21/16
to vert.x

 Hi All,

 Please help me as I am new on Vert.x .

 In httpclient my response come late , till the time request block is executed and response set is NULL but later it will print into CONSOLE.



HttpClientOptions options = new HttpClientOptions().setKeepAlive(false);
options.setLogActivity(true);
options.setDefaultHost("delvmpllbbab10");

options.setDefaultPort(7003);
HttpClient client = vertx.createHttpClient(options);
String[] resp = {null};

client.request(HttpMethod.GET, "/rcsservices/homePage", response -> {
response.handler(buffer -> {
System.out.println("Received a part of the response body: " + buffer);
resp[0] = buffer.toString();
});
}).putHeader("content-type", "application/json").end(Json.encodePrettily(resp[0]));

System.out.println(resp[0]);


OUPUT in CONSOLE :


null (means this line going to print first " System.out.println(resp[0]);" which is out of request body);

Received a part of the response body: {"contents":} (later my response came "System.out.println("Received a part of the response body: " + buffer);" )


Unable to understand whats going on., Help me .

Thanks,
Yogesh Kumar Bholan

Jez P

unread,
Oct 21, 2016, 2:04:57 AM10/21/16
to vert.x

Yogesh Kumar

unread,
Oct 21, 2016, 2:57:18 AM10/21/16
to vert.x


  Thanks Jez P.
Reply all
Reply to author
Forward
0 new messages