org.eclipse.lsp4j.jsonrpc.Launcher Java Examples
The following examples show how to use
org.eclipse.lsp4j.jsonrpc.Launcher.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultGLSPServerLauncher.java From graphical-lsp with Eclipse Public License 2.0 | 6 votes |
private void createClientConnection(AsynchronousSocketChannel socketChannel) { Injector injector = Guice.createInjector(getGLSPModule()); GsonConfigurator gsonConf = injector.getInstance(GsonConfigurator.class); InputStream in = Channels.newInputStream(socketChannel); OutputStream out = Channels.newOutputStream(socketChannel); Consumer<GsonBuilder> configureGson = (GsonBuilder builder) -> gsonConf.configureGsonBuilder(builder); Function<MessageConsumer, MessageConsumer> wrapper = Function.identity(); GLSPServer languageServer = injector.getInstance(GLSPServer.class); Launcher<GLSPClient> launcher = Launcher.createIoLauncher(languageServer, GLSPClient.class, in, out, threadPool, wrapper, configureGson); languageServer.connect(launcher.getRemoteProxy()); launcher.startListening(); try { SocketAddress remoteAddress = socketChannel.getRemoteAddress(); log.info("Started language server for client " + remoteAddress); } catch (IOException ex) { log.error("Failed to get the remoteAddress for the new client connection: " + ex.getMessage(), ex); } }
Example #2
Source File: ProtocolTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
/** * creates a proxy, delegating to a remote endpoint, forwarding to another remote endpoint, that delegates to an actual implementation. * @param intf * @param impl * @return * @throws IOException */ public <T> T wrap(Class<T> intf, T impl) { PipedInputStream in1 = new PipedInputStream(); PipedOutputStream out1 = new PipedOutputStream(); Launcher<T> launcher1 = Launcher.createLauncher(impl, intf, in1, out1); PipedInputStream in2 = new PipedInputStream(); PipedOutputStream out2 = new PipedOutputStream(); Launcher<T> launcher2 = Launcher.createLauncher(new Object(), intf, in2, out2); try { in1.connect(out2); in2.connect(out1); } catch (IOException e) { throw new IllegalStateException(e); } launcher1.startListening(); launcher2.startListening(); return launcher2.getRemoteProxy(); }
Example #3
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testValidationIssue2() throws Exception { String requestMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"1\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": null, \"nested\": { \"value\": null } }\n" + "}"; String clientMessages = getHeader(requestMessage1.getBytes().length) + requestMessage1; ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out, true, null); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 379" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32600,\"message\":\"Multiple issues were found in \\u0027askServer\\u0027 request.\"," + "\"data\":[" + "{\"text\":\"The accessor \\u0027MyParam.getValue()\\u0027 must return a non-null value. Path: $.params.nested.value\",\"code\":-32602}," + "{\"text\":\"The accessor \\u0027MyParam.getValue()\\u0027 must return a non-null value. Path: $.params.value\",\"code\":-32602}" + "]}}", out.toString()); }
Example #4
Source File: LauncherTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testCanceled() throws Exception { A a = new A() { @Override public void say(Param p) { } }; Launcher<A> launcher = Launcher.createLauncher(a, A.class, new InputStream() { @Override public int read() throws IOException { try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } return '\n'; } }, new ByteArrayOutputStream()); Future<?> startListening = launcher.startListening(); startListening.cancel(true); Assert.assertTrue(startListening.isDone()); Assert.assertTrue(startListening.isCancelled()); }
Example #5
Source File: SocketServerLauncher.java From xtext-core with Eclipse Public License 2.0 | 6 votes |
public void launch(String[] args) { Injector injector = Guice.createInjector(getServerModule()); try (AsynchronousServerSocketChannel serverSocket = AsynchronousServerSocketChannel.open() .bind(getSocketAddress(args))) { LOG.info("Started server socket at " + getSocketAddress(args)); while (true) { AsynchronousSocketChannel socketChannel = serverSocket.accept().get(); InputStream in = Channels.newInputStream(socketChannel); OutputStream out = Channels.newOutputStream(socketChannel); PrintWriter trace = getTrace(args); boolean validate = shouldValidate(args); LanguageServerImpl languageServer = injector.getInstance(LanguageServerImpl.class); LOG .info("Starting Xtext Language Server for client " + socketChannel.getRemoteAddress()); Launcher<LanguageClient> launcher = Launcher.createLauncher(languageServer, LanguageClient.class, in, out, validate, trace); languageServer.connect(launcher.getRemoteProxy()); launcher.startListening(); LOG.info("Xtext Language Server has been started."); } } catch (Throwable t) { t.printStackTrace(); } }
Example #6
Source File: DebugIntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testResponse() throws Exception { String clientMessage = "{\"type\":\"request\"," + "\"seq\":1,\n" + "\"command\":\"askServer\",\n" + " \"arguments\": { value: \"bar\" }\n" + "}"; String clientMessages = getHeader(clientMessage.getBytes().length) + clientMessage; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServer() { @Override public CompletableFuture<MyParam> askServer(MyParam param) { return CompletableFuture.completedFuture(param); } }; Launcher<MyClient> serverSideLauncher = DebugLauncher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 103\r\n\r\n" + "{\"type\":\"response\",\"seq\":1,\"request_seq\":1,\"command\":\"askServer\",\"success\":true,\"body\":{\"value\":\"bar\"}}", out.toString()); }
Example #7
Source File: SendNotificationTest.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
@Before public void setUp() throws IOException { this.client = mock(ExecuteCommandProposedClient.class); PipedOutputStream clientWritesTo = new PipedOutputStream(); PipedInputStream clientReadsFrom = new PipedInputStream(); PipedInputStream serverReadsFrom = new PipedInputStream(); PipedOutputStream serverWritesTo = new PipedOutputStream(); serverWritesTo.connect(clientReadsFrom); clientWritesTo.connect(serverReadsFrom); this.closeables = new Closeable[] { clientWritesTo, clientReadsFrom, serverReadsFrom, serverWritesTo }; Launcher<JavaLanguageClient> serverLauncher = Launcher.createLauncher(new Object(), JavaLanguageClient.class, serverReadsFrom, serverWritesTo); serverLauncher.startListening(); Launcher<LanguageServer> clientLauncher = Launcher.createLauncher(client, LanguageServer.class, clientReadsFrom, clientWritesTo); clientLauncher.startListening(); this.clientConnection = serverLauncher.getRemoteProxy(); }
Example #8
Source File: DefaultLanguageServerWrapper.java From MSPaintIDE with MIT License | 6 votes |
@Override public CompletableFuture<Void> start(File rootPath) { setStatus(STARTING); this.client = new LSPClient(this.startupLogic); this.rootPath = rootPath; try { var processedArgs = this.argumentPreprocessor.apply(this, new ArrayList<>(this.lspArgs)); var streamConnectionProvider = new LSPProvider( () -> requestManager, processedArgs, serverPath.get()); streamConnectionProvider.start(); Launcher<LanguageServer> launcher = Launcher.createLauncher(client, LanguageServer.class, streamConnectionProvider.getInputStream(), streamConnectionProvider.getOutputStream()); languageServer = launcher.getRemoteProxy(); client.connect(languageServer); launcherFuture = launcher.startListening(); return (startingFuture = languageServer.initialize(getInitParams()).thenApply(res -> { LOGGER.info("Started LSP"); requestManager = new DefaultRequestManager(this, languageServer, client, res.getCapabilities()); setStatus(STARTED); requestManager.initialized(new InitializedParams()); setStatus(INITIALIZED); return res; }).thenRun(() -> LOGGER.info("Done starting LSP!"))); } catch (Exception e) { LOGGER.error("Can't launch language server for project", e); } return CompletableFuture.runAsync(() -> {}); }
Example #9
Source File: TeiidDdlLanguageServerRunner.java From syndesis with Apache License 2.0 | 6 votes |
@SuppressWarnings({"try", "FutureReturnValueIgnored"}) public static void main(String[] args) throws DeploymentException, InterruptedException { LOGGER.info(" -- >>> TeiidDdlLanguageServerRunner.main()"); List<String> arguments = Arrays.asList(args); if (arguments.contains(WEBSOCKET_PARAMETER)) { LOGGER.info(" -- >>> Started Teiid LS as WEB SOCKET"); int port = extractPort(arguments); String hostname = extractHostname(arguments); String contextPath = extractContextPath(arguments); try (TeiidDdlWebSocketRunner runner = new TeiidDdlWebSocketRunner(hostname, port, contextPath);) { Thread.currentThread().join(); } } else { LOGGER.info(" -- >>> Started Teiid LS as JAVA SERVER"); server = new TeiidDdlLanguageServer(null); Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, System.in, System.out); server.connect(launcher.getRemoteProxy()); launcher.startListening(); LOGGER.info(" -- >>> Teiid LS Started. launch listening started"); } }
Example #10
Source File: DebugLauncherTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testCanceled() throws Exception { A a = new A() { @Override public void say(Param p) { } }; Launcher<A> launcher = DebugLauncher.createLauncher(a, A.class, new InputStream() { @Override public int read() throws IOException { try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } return '\n'; } }, new ByteArrayOutputStream()); Future<?> startListening = launcher.startListening(); startListening.cancel(true); Assert.assertTrue(startListening.isDone()); Assert.assertTrue(startListening.isCancelled()); }
Example #11
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testEither() throws Exception { // create client message String requestMessage = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": 42,\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"either\": \"bar\", \"value\": \"foo\" }\n" + "}"; String clientMessage = getHeader(requestMessage.getBytes().length) + requestMessage; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessage.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 65" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":42,\"result\":{\"value\":\"foo\",\"either\":\"bar\"}}", out.toString()); }
Example #12
Source File: LspServer.java From n4js with Eclipse Public License 1.0 | 6 votes |
private void run(XLanguageServerImpl languageServer, Builder<LanguageClient> lsBuilder, InputStream in, OutputStream out) { Launcher<LanguageClient> launcher = lsBuilder .setInput(in) .setOutput(out) .create(); languageServer.connect(launcher.getRemoteProxy()); Future<Void> future = launcher.startListening(); N4jscConsole.println("LSP Server connected"); Futures.getUnchecked(future); N4jscConsole.println("Shutdown connection to LSP client"); languageServer.getLSPExecutorService().shutdown(); }
Example #13
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testEitherNull() throws Exception { // create client message String requestMessage = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": 42,\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"either\": null, \"value\": \"foo\" }\n" + "}"; String clientMessage = getHeader(requestMessage.getBytes().length) + requestMessage; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessage.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 50" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":42,\"result\":{\"value\":\"foo\"}}", out.toString()); }
Example #14
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testResponse2() throws Exception { // create client message String requestMessage = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": 42,\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}"; String clientMessage = getHeader(requestMessage.getBytes().length) + requestMessage; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessage.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 50" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":42,\"result\":{\"value\":\"bar\"}}", out.toString()); }
Example #15
Source File: Runner.java From camel-language-server with Apache License 2.0 | 6 votes |
public static void main(String[] args) { List<String> arguments = Arrays.asList(args); if (arguments.contains(HELP_PARAMETER)) { System.out.println(HELP_MESSAGE); } else if (arguments.contains(WEBSOCKET_PARAMETER)) { int port = extractPort(arguments); String hostname = extractHostname(arguments); webSocketRunner = new WebSocketRunner(); String contextPath = extractContextPath(arguments); webSocketRunner.runWebSocketServer(hostname, port, contextPath); } else { server = new CamelLanguageServer(); Launcher<LanguageClient> launcher = LSPLauncher.createServerLauncher(server, System.in, System.out); server.connect(launcher.getRemoteProxy()); launcher.startListening(); } }
Example #16
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 6 votes |
@Test public void testResponse1() throws Exception { // create client message String requestMessage = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"42\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}"; String clientMessage = getHeader(requestMessage.getBytes().length) + requestMessage; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessage.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 52" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"42\",\"result\":{\"value\":\"bar\"}}", out.toString()); }
Example #17
Source File: XMLServerSocketLauncher.java From lemminx with Eclipse Public License 2.0 | 6 votes |
/** * Launches {@link XMLLanguageServer} using asynchronous server-socket channel and makes it accessible through the JSON * RPC protocol defined by the LSP. * * @param args standard launch arguments. may contain <code>--port</code> argument to change the default port 5008 */ public void launch(String[] args) throws Exception { AsynchronousServerSocketChannel _open = AsynchronousServerSocketChannel.open(); int _port = getPort(args); InetSocketAddress _inetSocketAddress = new InetSocketAddress("0.0.0.0", _port); final AsynchronousServerSocketChannel serverSocket = _open.bind(_inetSocketAddress); while (true) { final AsynchronousSocketChannel socketChannel = serverSocket.accept().get(); final InputStream in = Channels.newInputStream(socketChannel); final OutputStream out = Channels.newOutputStream(socketChannel); final ExecutorService executorService = Executors.newCachedThreadPool(); XMLLanguageServer languageServer = new XMLLanguageServer(); final Launcher<LanguageClient> launcher = Launcher.createIoLauncher(languageServer, LanguageClient.class, in, out, executorService, (MessageConsumer it) -> { return it; }); languageServer.setClient(launcher.getRemoteProxy()); launcher.startListening(); } }
Example #18
Source File: RunSingleServer.java From xtext-languageserver-example with Eclipse Public License 1.0 | 5 votes |
static <T> Launcher<T> createSocketLauncher(Object localService, Class<T> remoteInterface, SocketAddress socketAddress, ExecutorService executorService, Function<MessageConsumer, MessageConsumer> wrapper, InputStream inputStream, OutputStream outputStream) throws IOException { return Launcher.createIoLauncher(localService, remoteInterface, inputStream, outputStream, executorService, wrapper); }
Example #19
Source File: DSPDebugServer.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testDebugServerCanBeLaunched() throws IOException { TestDebugServer testDebugServer = new TestDebugServer(); Launcher<IDebugProtocolClient> launcher = DSPLauncher.createServerLauncher(testDebugServer, new PipedInputStream(), new PipedOutputStream()); Future<Void> listening = launcher.startListening(); listening.cancel(true); }
Example #20
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testValidationIssue1() throws Exception { String requestMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"1\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": null }\n" + "}"; String requestMessage2 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"2\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}"; String clientMessages = getHeader(requestMessage1.getBytes().length) + requestMessage1 + getHeader(requestMessage2.getBytes().length) + requestMessage2; ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out, true, null); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 157" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32602,\"message\":\"The accessor \\u0027MyParam.getValue()\\u0027 must return a non-null value. Path: $.params.value\"}}" + "Content-Length: 51" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"2\",\"result\":{\"value\":\"bar\"}}", out.toString()); }
Example #21
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testMalformedJson4() throws Exception { String requestMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"1\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}}"; String requestMessage2 = "{\"jsonrpc\":\"2.0\",\n" + "\"id\":\"2\",\n" + "\"method\":\"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}"; String clientMessages = getHeader(requestMessage1.getBytes().length) + requestMessage1 + getHeader(requestMessage2.getBytes().length) + requestMessage2; ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 195" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32700,\"message\":\"Message could not be parsed.\"," + "\"data\":{\"message\":\"Use JsonReader.setLenient(true) to accept malformed JSON at line 5 column 3 path $\"}}}" + "Content-Length: 51" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"2\",\"result\":{\"value\":\"bar\"}}", out.toString()); }
Example #22
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testMalformedJson3() throws Exception { String requestMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"1\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "]"; String requestMessage2 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"2\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}"; String clientMessages = getHeader(requestMessage1.getBytes().length) + requestMessage1 + getHeader(requestMessage2.getBytes().length) + requestMessage2; ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 165" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32700,\"message\":\"Message could not be parsed.\"," + "\"data\":{\"message\":\"Unterminated object at line 5 column 2 path $.params\"}}}" + "Content-Length: 51" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"2\",\"result\":{\"value\":\"bar\"}}", out.toString()); }
Example #23
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testMalformedJson2() throws Exception { // intercept log messages LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(StreamMessageProducer.class); String requestMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"params\": { \"value\": }\n" + "\"id\": \"1\",\n" + "\"method\":\"askServer\",\n" + "}"; String requestMessage2 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"2\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}"; String clientMessages = getHeader(requestMessage1.getBytes().length) + requestMessage1 + getHeader(requestMessage2.getBytes().length) + requestMessage2; ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening(); logMessages.await(Level.SEVERE, "com.google.gson.stream.MalformedJsonException: Expected value at line 2 column 22 path $.params.value"); Assert.assertEquals("Content-Length: 51" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"2\",\"result\":{\"value\":\"bar\"}}", out.toString()); } finally { logMessages.unregister(); } }
Example #24
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testMalformedJson1() throws Exception { String requestMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"1\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": }\n" + "}"; String requestMessage2 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"2\",\n" + "\"method\": \"askServer\",\n" + "\"params\": { \"value\": \"bar\" }\n" + "}"; String clientMessages = getHeader(requestMessage1.getBytes().length) + requestMessage1 + getHeader(requestMessage2.getBytes().length) + requestMessage2; ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening().get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertEquals("Content-Length: 214" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32700,\"message\":\"Message could not be parsed.\"," + "\"data\":{\"message\":\"com.google.gson.stream.MalformedJsonException: Expected value at line 4 column 22 path $.params.value\"}}}" + "Content-Length: 51" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"2\",\"result\":{\"value\":\"bar\"}}", out.toString()); }
Example #25
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testUnexpectedParams() throws Exception { // intercept log messages LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(GenericEndpoint.class); // create client messages String notificationMessage = "{\"jsonrpc\": \"2.0\",\n" + "\"method\": \"myNotification\",\n" + "\"params\": { \"value\": \"foo\" }\n" + "}"; String clientMessages = getHeader(notificationMessage.getBytes().length) + notificationMessage; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); UnexpectedParamsTestServer server = new UnexpectedParamsTestServer() { public void myNotification() { } }; Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening(); logMessages.await(Level.WARNING, "Unexpected params '{\"value\":\"foo\"}' for " + "'public abstract void org.eclipse.lsp4j.jsonrpc.test.IntegrationTest$UnexpectedParamsTestServer.myNotification()' is ignored"); } finally { logMessages.unregister(); } }
Example #26
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testUnknownOptionalMessages() throws Exception { // intercept log messages LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(GenericEndpoint.class); // create client messages String clientMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"method\": \"$/foo1\",\n" + "\"params\": \"bar\"\n" + "}"; String clientMessage2 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"1\",\n" + "\"method\": \"$/foo2\",\n" + "\"params\": \"bar\"\n" + "}"; String clientMessages = getHeader(clientMessage1.getBytes().length) + clientMessage1 + getHeader(clientMessage2.getBytes().length) + clientMessage2; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening(); logMessages.await(Level.INFO, "Unsupported notification method: $/foo1"); logMessages.await(Level.INFO, "Unsupported request method: $/foo2"); Assert.assertEquals("Content-Length: 40" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":null}", out.toString()); } finally { logMessages.unregister(); } }
Example #27
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testBothDirectionRequests() throws Exception { // create client side PipedInputStream in = new PipedInputStream(); PipedOutputStream out = new PipedOutputStream(); PipedInputStream in2 = new PipedInputStream(); PipedOutputStream out2 = new PipedOutputStream(); in.connect(out2); out.connect(in2); MyClient client = new MyClientImpl(); Launcher<MyServer> clientSideLauncher = Launcher.createLauncher(client, MyServer.class, in, out); // create server side MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in2, out2); clientSideLauncher.startListening(); serverSideLauncher.startListening(); CompletableFuture<MyParam> fooFuture = clientSideLauncher.getRemoteProxy().askServer(new MyParam("FOO")); CompletableFuture<MyParam> barFuture = serverSideLauncher.getRemoteProxy().askClient(new MyParam("BAR")); Assert.assertEquals("FOO", fooFuture.get(TIMEOUT, TimeUnit.MILLISECONDS).value); Assert.assertEquals("BAR", barFuture.get(TIMEOUT, TimeUnit.MILLISECONDS).value); }
Example #28
Source File: IntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testUnknownMessages() throws Exception { // intercept log messages LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(GenericEndpoint.class); // create client messages String clientMessage1 = "{\"jsonrpc\": \"2.0\",\n" + "\"method\": \"foo1\",\n" + "\"params\": \"bar\"\n" + "}"; String clientMessage2 = "{\"jsonrpc\": \"2.0\",\n" + "\"id\": \"1\",\n" + "\"method\": \"foo2\",\n" + "\"params\": \"bar\"\n" + "}"; String clientMessages = getHeader(clientMessage1.getBytes().length) + clientMessage1 + getHeader(clientMessage2.getBytes().length) + clientMessage2; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); MyServer server = new MyServerImpl(); Launcher<MyClient> serverSideLauncher = Launcher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening(); logMessages.await(Level.WARNING, "Unsupported notification method: foo1"); logMessages.await(Level.WARNING, "Unsupported request method: foo2"); Assert.assertEquals("Content-Length: 95" + CRLF + CRLF + "{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"error\":{\"code\":-32601,\"message\":\"Unsupported request method: foo2\"}}", out.toString()); } finally { logMessages.unregister(); } }
Example #29
Source File: DebugIntegrationTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testUnexpectedParams() throws Exception { // intercept log messages LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(GenericEndpoint.class.getName()); // create client messages String notificationMessage = "{\"type\":\"event\"," + "\"event\":\"myNotification\",\n" + "\"body\": { \"value\": \"foo\" }\n" + "}"; String clientMessages = getHeader(notificationMessage.getBytes().length) + notificationMessage; // create server side ByteArrayInputStream in = new ByteArrayInputStream(clientMessages.getBytes()); ByteArrayOutputStream out = new ByteArrayOutputStream(); UnexpectedParamsTestServer server = new UnexpectedParamsTestServer() { public void myNotification() { } }; Launcher<MyClient> serverSideLauncher = DebugLauncher.createLauncher(server, MyClient.class, in, out); serverSideLauncher.startListening(); logMessages.await(Level.WARNING, "Unexpected params '{\"value\":\"foo\"}' for " + "'public abstract void " + UnexpectedParamsTestServer.class.getName() + ".myNotification()' is ignored"); } finally { logMessages.unregister(); } }
Example #30
Source File: DebugLauncherTest.java From lsp4j with Eclipse Public License 2.0 | 5 votes |
@Test public void testDone() throws Exception { A a = new A() { @Override public void say(Param p) { } }; Launcher<A> launcher = DebugLauncher.createLauncher(a, A.class, new ByteArrayInputStream("".getBytes()), new ByteArrayOutputStream()); Future<?> startListening = launcher.startListening(); startListening.get(TIMEOUT, TimeUnit.MILLISECONDS); Assert.assertTrue(startListening.isDone()); Assert.assertFalse(startListening.isCancelled()); }