/** * Route for getting getting schemas from client side and injecting them into yaml language server * * @param yamlDto A yamlDTO containing the list of schemas you would like to add */ @POST @Path("schemas") @Consumes(MediaType.APPLICATION_JSON) public void putSchemas(YamlDTO yamlDto) throws ApiException { LanguageServer yamlLS = YamlLanguageServerConfig.getYamlLanguageServer(); if (yamlDto != null && yamlLS != null) { Endpoint endpoint = ServiceEndpoints.toEndpoint(yamlLS); YamlSchemaAssociations serviceObject = ServiceEndpoints.toServiceObject(endpoint, YamlSchemaAssociations.class); Map<String, String[]> schemaAssociations = new HashMap<>(); Map<String, String> yamlDtoSchemas = yamlDto.getSchemas(); for (Map.Entry<String, String> schema : yamlDtoSchemas.entrySet()) { schemaAssociations.put( schema.getKey(), new Gson().fromJson(schema.getValue(), String[].class)); } serviceObject.yamlSchemaAssociation(schemaAssociations); } } }
extensions.put(entry.getKey(), existing); } else { final Endpoint endpoint = ServiceEndpoints.toEndpoint(ext); this.extensionProviders.put(entry.getKey(), endpoint); supportedMethods.put(entry.getKey(), entry.getValue());
/** * Create the remote endpoint that communicates with the local services. */ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler); outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream); RemoteEndpoint remoteEndpoint = new RemoteEndpoint(outgoingMessageStream, ServiceEndpoints.toEndpoint(localServices)); jsonHandler.setMethodProvider(remoteEndpoint); return remoteEndpoint; } }
/** * Create the remote endpoint that communicates with the local services. */ protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler); outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream); RemoteEndpoint remoteEndpoint = new RemoteEndpoint(outgoingMessageStream, ServiceEndpoints.toEndpoint(localServices)); jsonHandler.setMethodProvider(remoteEndpoint); return remoteEndpoint; } }
public void onLanguageServerInitialized(LanguageServerInitializedEvent event) { try { Map<String, String> preferences = requestFactory.fromUrl(apiUrl + "/preferences").useGetMethod().request().asProperties(); Endpoint endpoint = ServiceEndpoints.toEndpoint(event.getLanguageServer()); YamlSchemaAssociations serviceObject = ServiceEndpoints.toServiceObject(endpoint, YamlSchemaAssociations.class); Map<String, String[]> associations = jsonToSchemaAssociations(preferences.get("yaml.preferences")); serviceObject.yamlSchemaAssociation(associations); } catch (ApiException | IOException e) { LOG.error(e.getLocalizedMessage(), e); } }
@Override protected RemoteEndpoint createRemoteEndpoint(MessageJsonHandler jsonHandler) { MessageConsumer outgoingMessageStream = new StreamMessageConsumer(output, jsonHandler); outgoingMessageStream = wrapMessageConsumer(outgoingMessageStream); RemoteEndpoint remoteEndpoint = new DebugRemoteEndpoint(outgoingMessageStream, ServiceEndpoints.toEndpoint(localServices)); jsonHandler.setMethodProvider(remoteEndpoint); return remoteEndpoint; }
@Test public void testBackAndForth() throws Exception { Endpoint endpoint = new Endpoint() { @Override public CompletableFuture<?> request(String method, Object parameter) { assertEquals("foo/doStuff", method); assertEquals("param", parameter.toString()); return CompletableFuture.completedFuture("result"); } @Override public void notify(String method, Object parameter) { assertEquals("foo/myNotification", method); assertEquals("notificationParam", parameter.toString()); } }; Foo intermediateFoo = ServiceEndpoints.toServiceObject(endpoint, Foo.class); Endpoint secondEndpoint = ServiceEndpoints.toEndpoint(intermediateFoo); Foo foo = ServiceEndpoints.toServiceObject(secondEndpoint, Foo.class); foo.myNotification("notificationParam"); assertEquals("result", foo.doStuff("param").get(TIMEOUT, TimeUnit.MILLISECONDS)); }
@Test public void testNullResponse() throws InterruptedException, ExecutionException { LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { logMessages.registerTo(GenericEndpoint.class); Endpoint endpoint = ServiceEndpoints.toEndpoint(this); Map<String, JsonRpcMethod> methods = ServiceEndpoints.getSupportedMethods(LanguageServer.class); MessageJsonHandler handler = new MessageJsonHandler(methods); List<Message> msgs = new ArrayList<>(); MessageConsumer consumer = (message) -> { msgs.add(message); }; RemoteEndpoint re = new RemoteEndpoint(consumer, endpoint); RequestMessage request = new RequestMessage(); request.setId("1"); request.setMethod("shutdown"); re.consume(request); Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":null}", handler.serialize(msgs.get(0))); msgs.clear(); shutdownReturn = new Object(); re.consume(request); Assert.assertEquals("{\"jsonrpc\":\"2.0\",\"id\":\"1\",\"result\":{}}", handler.serialize(msgs.get(0))); } finally { logMessages.unregister(); } }