Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 08:35 Go to next message
Emin M. is currently offline Emin M.Friend
Messages: 55
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

Re: LanguageServer with Apache HTTP Client, endless wait on read [message #1790110 is a reply to message #1790109] Tue, 05 June 2018 08:38 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 12229
Registered: July 2009
Senior Member
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.

Need professional support for Xtext, Xpand, EMF?
Go to: https://xtext.itemis.com
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: LanguageServer with Apache HTTP Client, endless wait on read [message #1790111 is a reply to message #1790110] Tue, 05 June 2018 08:49 Go to previous message
Emin M. is currently offline Emin M.Friend
Messages: 55
Registered: November 2012
Location: Berlin
Member
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: Wed Sep 19 21:07:05 GMT 2018

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

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

Back to the top