@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); } }
@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; }
issues.add(new MessageIssue("An element of the message has a direct or indirect reference to itself." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); Object element = iter.next(); if (element == null) { issues.add(new MessageIssue("Lists must not contain null references." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); validate(either.getRight(), issues, objectStack, accessorStack); } else { issues.add(new MessageIssue("An Either instance must not be empty." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); Object value = method.invoke(object); if (value == null && method.getAnnotation(NonNull.class) != null) { issues.add(new MessageIssue("The accessor '" + method.getDeclaringClass().getSimpleName() + "." + method.getName() + "()' must return a non-null value." + " Path: " + createPathString(accessorStack),
issues.add(new MessageIssue("An element of the message has a direct or indirect reference to itself." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); Object element = iter.next(); if (element == null) { issues.add(new MessageIssue("Lists must not contain null references." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); validate(either.getRight(), issues, objectStack, accessorStack); } else { issues.add(new MessageIssue("An Either instance must not be empty." + " Path: " + createPathString(accessorStack), ResponseErrorCode.InvalidParams.getValue())); Object value = method.invoke(object); if (value == null && method.getAnnotation(NonNull.class) != null) { issues.add(new MessageIssue("The accessor '" + method.getDeclaringClass().getSimpleName() + "." + method.getName() + "()' must return a non-null value." + " Path: " + createPathString(accessorStack),
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 {
MessageIssue issue = new MessageIssue("Message could not be parsed.", ResponseErrorCode.ParseError.getValue(), exception); throw new MessageIssueException(message, issue); } else {
@Test public void testHandleRequestIssues() { TestEndpoint endp = new TestEndpoint(); TestMessageConsumer consumer = new TestMessageConsumer(); RemoteEndpoint endpoint = new RemoteEndpoint(consumer, endp); endpoint.handle(init(new RequestMessage(), it -> { it.setId("1"); it.setMethod("foo"); it.setParams("myparam"); }), Collections.singletonList(new MessageIssue("bar"))); ResponseMessage responseMessage = (ResponseMessage) consumer.messages.get(0); assertNotNull(responseMessage.getError()); assertEquals("bar", responseMessage.getError().getMessage()); }