public ResponseError(ResponseErrorCode code, String message, Object data) { this(code.getValue(), message, data); }
public ResponseError(ResponseErrorCode code, String message, Object data) { this(code.getValue(), message, data); }
public void setCode(ResponseErrorCode code) { this.setCode(code.getValue()); }
public void setCode(ResponseErrorCode code) { this.setCode(code.getValue()); }
@Override public void consume(Message message) throws MessageIssueException, JsonRpcException { List<MessageIssue> result = new ArrayList<>(); try { validate(message, result, new LinkedList<>(), new LinkedList<>()); } catch (Exception e) { LOG.log(Level.SEVERE, "Error during message validation: " + e.getMessage(), e); result.add(new MessageIssue("Message validation failed, please check the logs of the remote endpoint.", ResponseErrorCode.InvalidParams.getValue())); } if (!result.isEmpty()) { // Sort the messages in order to get a stable order (otherwise it depends on the JVM's reflection implementation) Collections.sort(result, (issue1, issue2) -> issue1.getText().compareTo(issue2.getText())); throw new MessageIssueException(message, result); } else if (delegate != null) { delegate.consume(message); } }
public Message parseMessage(Reader input) throws JsonParseException { JsonReader jsonReader = new JsonReader(input); Message message = gson.fromJson(jsonReader, Message.class); if (message != null) { // Check whether the input has been fully consumed try { if (jsonReader.peek() != JsonToken.END_DOCUMENT) { MessageIssue issue = new MessageIssue("JSON document was not fully consumed.", ResponseErrorCode.ParseError.getValue()); throw new MessageIssueException(message, issue); } } catch (MalformedJsonException e) { MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), e); throw new MessageIssueException(message, issue); } catch (IOException e) { throw new JsonIOException(e); } } return message; }
public Message parseMessage(Reader input) throws JsonParseException { JsonReader jsonReader = new JsonReader(input); Message message = gson.fromJson(jsonReader, Message.class); if (message != null) { // Check whether the input has been fully consumed try { if (jsonReader.peek() != JsonToken.END_DOCUMENT) { MessageIssue issue = new MessageIssue("JSON document was not fully consumed.", ResponseErrorCode.ParseError.getValue()); throw new MessageIssueException(message, issue); } } catch (MalformedJsonException e) { MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), e); throw new MessageIssueException(message, issue); } catch (IOException e) { throw new JsonIOException(e); } } return message; }
@Override public void consume(Message message) throws MessageIssueException, JsonRpcException { List<MessageIssue> result = new ArrayList<>(); try { validate(message, result, new LinkedList<>(), new LinkedList<>()); } catch (Exception e) { LOG.log(Level.SEVERE, "Error during message validation: " + e.getMessage(), e); result.add(new MessageIssue("Message validation failed, please check the logs of the remote endpoint.", ResponseErrorCode.InvalidParams.getValue())); } if (!result.isEmpty()) { // Sort the messages in order to get a stable order (otherwise it depends on the JVM's reflection implementation) Collections.sort(result, (issue1, issue2) -> issue1.getText().compareTo(issue2.getText())); throw new MessageIssueException(message, result); } else if (delegate != null) { delegate.consume(message); } }
issues.add(new MessageIssue("An element of the message has a direct or indirect reference to itself." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); return; issues.add(new MessageIssue("Lists must not contain null references." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); issues.add(new MessageIssue("An Either instance must not be empty." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); + "." + method.getName() + "()' must return a non-null value." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue()));
issues.add(new MessageIssue("An element of the message has a direct or indirect reference to itself." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); return; issues.add(new MessageIssue("Lists must not contain null references." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); issues.add(new MessageIssue("An Either instance must not be empty." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); + "." + method.getName() + "()' must return a non-null value." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue()));
MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); throw new MessageIssueException(message, issue); } else {
MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); throw new MessageIssueException(resultMessage, issue); } else {
MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); throw new MessageIssueException(message, issue); } else {
@Test public void testCancellation() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new DebugRemoteEndpoint(consumer, endp); endpoint.consume(new RequestMessage() {{ setId("1"); setMethod("foo"); setParams("myparam"); }}); Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next(); entry.getValue().cancel(true); ResponseMessage message = (ResponseMessage) consumer.messages.get(0); assertNotNull(message); ResponseError error = message.getError(); assertNotNull(error); assertEquals(error.getCode(), ResponseErrorCode.RequestCancelled.getValue()); assertEquals(error.getMessage(), "The request (id: 1, method: 'foo') has been cancelled"); }
@Test public void testCancellation() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); Entry<RequestMessage, CompletableFuture<Object>> entry = endp.requests.entrySet().iterator().next(); entry.getValue().cancel(true); ResponseMessage message = (ResponseMessage) consumer.messages.get(0); assertNotNull(message); ResponseError error = message.getError(); assertNotNull(error); assertEquals(error.getCode(), ResponseErrorCode.RequestCancelled.getValue()); assertEquals(error.getMessage(), "The request (id: 1, method: 'foo') has been cancelled"); }
ResponseMessage response = (ResponseMessage) consumer.messages.get(0); assertNotNull("Check response has error", response.getError()); assertEquals(ResponseErrorCode.InternalError.getValue(), response.getError().getCode()); } finally { logMessages.unregister();
@Test public void testExceptionHandlerMisbehaving1() { LogMessageAccumulator logMessages = new LogMessageAccumulator(); try { // Don't show the exception in the test execution log logMessages.registerTo(RemoteEndpoint.class); TestEndpoint endp = new TestEndpoint() { @Override public CompletableFuture<Object> request(String method, Object parameter) { throw new RuntimeException("BAAZ"); } }; TestMessageConsumer consumer = new TestMessageConsumer(); // Misbehaving exception handler that returns null RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp, (e) -> null); endpoint.consume(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); })); assertEquals("Check some response received", 1, consumer.messages.size()); ResponseMessage response = (ResponseMessage) consumer.messages.get(0); assertEquals(ResponseErrorCode.InternalError.getValue(), response.getError().getCode()); } finally { logMessages.unregister(); } }
assertEquals(ResponseErrorCode.InternalError.getValue(), response.getError().getCode()); String exception = (String) response.getError().getData(); String expected = "java.lang.RuntimeException: BAAZ\n\tat org.eclipse.lsp4j.jsonrpc.test.RemoteEndpointTest";