Skip to main content



      Home
Home » Modeling » TMF (Xtext) » LanguageServer with Apache HTTP Client, endless wait on read
LanguageServer with Apache HTTP Client, endless wait on read [message #1790109] Tue, 05 June 2018 04:35 Go to next message
Eclipse UserFriend
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 04:36] by Moderator

Re: LanguageServer with Apache HTTP Client, endless wait on read [message #1790110 is a reply to message #1790109] Tue, 05 June 2018 04:38 Go to previous messageGo to next message
Eclipse UserFriend
i recommend you to ask this as a question in the github.com/eclipse/lsp4j project. but i assume they will recommend you to use lsp4j as client too.
Re: LanguageServer with Apache HTTP Client, endless wait on read [message #1790111 is a reply to message #1790110] Tue, 05 June 2018 04:49 Go to previous message
Eclipse UserFriend
Thank you. I will check the lsp4j client.
Previous Topic:XtextReconcilerJob popup error (start > length)
Next Topic:how to unit test of generator
Goto Forum:
  


Current Time: Mon Jul 14 22:26:16 EDT 2025

Powered by FUDForum. Page generated in 0.83694 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top