@Test void testSerializeResponse() { Map<String, ?> metadata = new HashMap<String, Object>() {{ this.put("firstKey", "firstValue"); this.put("secondKey", "secondValue"); }}; QueryResponseMessage message = new GenericQueryResponseMessage<>(BigDecimal.class, BigDecimal.ONE, metadata); QueryResponse grpcMessage = testSubject.serializeResponse(message, "requestMessageId"); QueryResponseMessage<BigDecimal> deserialized = testSubject.deserializeResponse(grpcMessage, instanceOf(BigDecimal.class)); assertEquals(message.getIdentifier(), deserialized.getIdentifier()); assertEquals(message.getMetaData(), deserialized.getMetaData()); assertEquals(message.getPayloadType(), deserialized.getPayloadType()); assertEquals(message.getPayload(), deserialized.getPayload()); }
public QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, String requestMessageId) { QueryResponse.Builder responseBuilder = QueryResponse.newBuilder(); if (queryResponse.isExceptional()) { Throwable exceptionResult = queryResponse.exceptionResult(); responseBuilder.setErrorCode(ErrorCode.QUERY_EXECUTION_ERROR.errorCode()); responseBuilder.setErrorMessage( ExceptionSerializer.serialize(configuration.getClientId(), exceptionResult) ); queryResponse.exceptionDetails() .ifPresent(details -> responseBuilder.setPayload(exceptionDetailsSerializer.apply(details))); } else { responseBuilder.setPayload(payloadSerializer.apply(queryResponse)); } return responseBuilder.putAllMetaData(metadataSerializer.apply(queryResponse.getMetaData())) .setMessageIdentifier(queryResponse.getIdentifier()) .setRequestIdentifier(requestMessageId) .build(); }
QuerySerializer { public QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, String requestMessageId) { QueryResponse.Builder responseBuilder = QueryResponse.newBuilder(); if (queryResponse.isExceptional()) { Throwable exceptionResult = queryResponse.exceptionResult(); responseBuilder.setErrorCode(ErrorCode.QUERY_EXECUTION_ERROR.errorCode()); responseBuilder.setErrorMessage( ExceptionSerializer.serialize(configuration.getClientId(), exceptionResult) ); queryResponse.exceptionDetails() .ifPresent(details -> responseBuilder.setPayload(exceptionDetailsSerializer.apply(details))); } else { responseBuilder.setPayload(payloadSerializer.apply(queryResponse)); } return responseBuilder.putAllMetaData(metadataSerializer.apply(queryResponse.getMetaData())) .setMessageIdentifier(queryResponse.getIdentifier()) .setRequestIdentifier(requestMessageId) .build(); } }
QuerySerializer { public QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, String requestMessageId) { QueryResponse.Builder responseBuilder = QueryResponse.newBuilder(); if (queryResponse.isExceptional()) { Throwable exceptionResult = queryResponse.exceptionResult(); responseBuilder.setErrorCode(ErrorCode.QUERY_EXECUTION_ERROR.errorCode()); responseBuilder.setErrorMessage( ExceptionSerializer.serialize(configuration.getClientId(), exceptionResult) ); queryResponse.exceptionDetails() .ifPresent(details -> responseBuilder.setPayload(exceptionDetailsSerializer.apply(details))); } else { responseBuilder.setPayload(payloadSerializer.apply(queryResponse)); } return responseBuilder.putAllMetaData(metadataSerializer.apply(queryResponse.getMetaData())) .setMessageIdentifier(queryResponse.getIdentifier()) .setRequestIdentifier(requestMessageId) .build(); } QuerySerializer(Serializer messageSerializer,
                           Serializer serializer,
                           AxonServerConfiguration configuration); }
QuerySerializer { public QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, String requestMessageId) { QueryResponse.Builder responseBuilder = QueryResponse.newBuilder(); if (queryResponse.isExceptional()) { Throwable exceptionResult = queryResponse.exceptionResult(); responseBuilder.setErrorCode(ErrorCode.QUERY_EXECUTION_ERROR.errorCode()); responseBuilder.setErrorMessage( ExceptionSerializer.serialize(configuration.getClientId(), exceptionResult) ); queryResponse.exceptionDetails() .ifPresent(details -> responseBuilder.setPayload(exceptionDetailsSerializer.apply(details))); } else { responseBuilder.setPayload(payloadSerializer.apply(queryResponse)); } return responseBuilder.putAllMetaData(metadataSerializer.apply(queryResponse.getMetaData())) .setMessageIdentifier(queryResponse.getIdentifier()) .setRequestIdentifier(requestMessageId) .build(); } QuerySerializer(Serializer messageSerializer,
                           Serializer serializer,
                           AxonServerConfiguration configuration); QueryRequest serializeRequest(QueryMessage<Q, R> queryMessage,
                                                int nrResults,
                                                long timeout,
                                                int priority); QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, String requestMessageId); QueryMessage<Q, R> deserializeRequest(QueryRequest queryRequest); QueryResponseMessage<R> deserializeResponse(QueryResponse queryResponse,
                                                           ResponseType<R> expectedResponseType); }
QuerySerializer { public QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, String requestMessageId) { QueryResponse.Builder responseBuilder = QueryResponse.newBuilder(); if (queryResponse.isExceptional()) { Throwable exceptionResult = queryResponse.exceptionResult(); responseBuilder.setErrorCode(ErrorCode.QUERY_EXECUTION_ERROR.errorCode()); responseBuilder.setErrorMessage( ExceptionSerializer.serialize(configuration.getClientId(), exceptionResult) ); queryResponse.exceptionDetails() .ifPresent(details -> responseBuilder.setPayload(exceptionDetailsSerializer.apply(details))); } else { responseBuilder.setPayload(payloadSerializer.apply(queryResponse)); } return responseBuilder.putAllMetaData(metadataSerializer.apply(queryResponse.getMetaData())) .setMessageIdentifier(queryResponse.getIdentifier()) .setRequestIdentifier(requestMessageId) .build(); } QuerySerializer(Serializer messageSerializer,
                           Serializer serializer,
                           AxonServerConfiguration configuration); QueryRequest serializeRequest(QueryMessage<Q, R> queryMessage,
                                                int nrResults,
                                                long timeout,
                                                int priority); QueryResponse serializeResponse(QueryResponseMessage<?> queryResponse, String requestMessageId); QueryMessage<Q, R> deserializeRequest(QueryRequest queryRequest); QueryResponseMessage<R> deserializeResponse(QueryResponse queryResponse,
                                                           ResponseType<R> expectedResponseType);  }