class JsonRpcMessageReceiver implements WebSocketMessageReceiver {

  @Override
  public void receive(String combinedEndpointId, String message) {
    checkNotNull(combinedEndpointId, "Endpoint ID must not be null");
    checkArgument(!combinedEndpointId.isEmpty(), "Endpoint ID name must not be empty");
    checkNotNull(message, "Message must not be null");
    checkArgument(!message.isEmpty(), "Message must not be empty");

    LOGGER.trace("Receiving message: {}, from endpoint: {}", message, combinedEndpointId);
    if (!jsonRpcQualifier.isValidJson(message)) {
      String error = "An error occurred on the server while parsing the JSON text";
      errorTransmitter.transmit(combinedEndpointId, new JsonRpcException(-32700, error));
    }

    List<String> messages = jsonRpcUnmarshaller.unmarshalArray(message);
    for (String innerMessage : messages) {
      if (jsonRpcQualifier.isJsonRpcRequest(innerMessage)) {
        String endpointId = combinedEndpointId.split(SEPARATOR)[1];
        ProcessRequestTask task = new ProcessRequestTask(combinedEndpointId, innerMessage);
        requestProcessor.process(endpointId, task);
      } else if (jsonRpcQualifier.isJsonRpcResponse(innerMessage)) {
        processResponse(combinedEndpointId, innerMessage);
      } else {
        processError();
      }
    }
  }

  @Inject public  JsonRpcMessageReceiver(
      RequestDispatcher requestDispatcher,
      ResponseDispatcher responseDispatcher,
      JsonRpcErrorTransmitter errorTransmitter,
      JsonRpcQualifier jsonRpcQualifier,
      JsonRpcUnmarshaller jsonRpcUnmarshaller,
      RequestProcessor requestProcessor);

}