LanguageServer with Apache HTTP Client, endless wait on read [message #1790109] |
Tue, 05 June 2018 08:35 |
Mehmet Karaman Messages: 63 Registered: November 2012 Location: Berlin |
Member |
|
|
Hello,
i've started the LanguageServer (using Xtxt 2.13.0) and tried to send a "initialize" method request. After that the client (used the Apache http client) was waiting endless and it seemed to me that it don't receives anything. The server log output shows the specified workspace and it content, so it was receiving the request.
CloseableHttpClient client = HttpClientBuilder.create().disableAuthCaching().disableAutomaticRetries()
.disableConnectionState().disableContentCompression().disableRedirectHandling().build();
HttpPost post = new HttpPost("http://localhost:5007");
StringBuilder initParams = new StringBuilder(); // Experimental.. didn't used GSon for this..
initParams.append(" \"processId\": null,\n");
initParams.append(" \"rootPath\": \"c:/ws/\",\n");
initParams.append(" \"capabilities\": {},\n");
initParams.append(" \"workspaceFolders\" : null\n ");
String json = getJsonString("initialize", initParams.toString(), MessageType.RequestMessage); // <- returns the rpc json, with the specified method "initialize" and the specified parameters in initParams
StringEntity entity = new StringEntity(json);
post.setEntity(entity);
post.addHeader("Content-Type", "application/vscode-jsonrpc; charset=utf-8");
CloseableHttpResponse response = client.execute(post); // <- here it didn't got back, checked with the debugger and saw that it stuck in reading.
System.out.println(response);
Then i've started to implement manually a basic http client with readLine to gather the received string in lines. The execution got stuck and waited endless. So i've tried reading chars only, this worked. I've never got a \n or \0 or something, which shows that the receiving of data ended, so i've tried to count the json content for '{' and '}' to realize that the receiving of data reached the end.
Socket socket = new Socket("localhost", 5007);
InputStream inputStream = socket.getInputStream();
OutputStream outputStream = socket.getOutputStream();
PrintWriter writer = new PrintWriter(outputStream, true);
writer.print("POST / HTTP/1.1\r\n");
writer.print("Content-Length : " + jsonString.length() + "\r\n");
writer.print("Host : " + socket.getRemoteSocketAddress() + "\n\r\n");
writer.write(jsonString);
writer.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
int readChar;
int klammern = 0;
StringBuilder stringBuilder = new StringBuilder();
while ((readChar = reader.read()) != -1) { // will stuck also endless, so i have added a manually break if the amount of opening and closing braces are equal.
stringBuilder.append((char) readChar);
if (readChar == 123) { // 123 is the { character
klammern++;
} else if (readChar == 125) { // 125 is the } character
klammern--;
}
if (stringBuilder.indexOf("{") != -1) {
if (klammern == 0) {
break;
}
}
}
String test = stringBuilder.substring(stringBuilder.indexOf("{"), stringBuilder.length());
System.out.println(test);
What is wrong with this? Is this the usual way of implementing a java client for the language server or is this a bug? Thank you in advance.
Best regards
Mehmet Karaman
[Updated on: Tue, 05 June 2018 08:36] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03301 seconds