@Override public ResponseMessage createObject(final Map<String, Object> data) { final Map<String, Object> status = (Map<String, Object>) data.get(SerTokens.TOKEN_STATUS); final Map<String, Object> result = (Map<String, Object>) data.get(SerTokens.TOKEN_RESULT); return ResponseMessage.build(UUID.fromString(data.get(SerTokens.TOKEN_REQUEST).toString())) .code(ResponseStatusCode.getFromValue((Integer) status.get(SerTokens.TOKEN_CODE))) .statusMessage(status.get(SerTokens.TOKEN_MESSAGE).toString()) .statusAttributes((Map<String, Object>) status.get(SerTokens.TOKEN_ATTRIBUTES)) .result(result.get(SerTokens.TOKEN_DATA)) .responseMetaData((Map<String, Object>) result.get(SerTokens.TOKEN_META)) .create(); } }
@Override public ResponseMessage deserializeResponse(final ByteBuf msg) throws SerializationException { try { final byte[] payload = new byte[msg.readableBytes()]; msg.readBytes(payload); final Map<String, Object> responseData = mapper.readValue(payload, mapTypeReference); final Map<String, Object> status = (Map<String, Object>) responseData.get(SerTokens.TOKEN_STATUS); final Map<String, Object> result = (Map<String, Object>) responseData.get(SerTokens.TOKEN_RESULT); return ResponseMessage.build(UUID.fromString(responseData.get(SerTokens.TOKEN_REQUEST).toString())) .code(ResponseStatusCode.getFromValue((Integer) status.get(SerTokens.TOKEN_CODE))) .statusMessage(status.get(SerTokens.TOKEN_MESSAGE).toString()) .statusAttributes((Map<String, Object>) status.get(SerTokens.TOKEN_ATTRIBUTES)) .result(result.get(SerTokens.TOKEN_DATA)) .responseMetaData((Map<String, Object>) result.get(SerTokens.TOKEN_META)) .create(); } catch (Exception ex) { logger.warn("Response [{}] could not be deserialized by {}.", msg, AbstractGraphSONMessageSerializerV1d0.class.getName()); throw new SerializationException(ex); } }
@Override public ResponseMessage deserializeResponse(final String msg) throws SerializationException { try { final Map<String, Object> responseData = mapper.readValue(msg, mapTypeReference); final Map<String, Object> status = (Map<String, Object>) responseData.get(SerTokens.TOKEN_STATUS); final Map<String, Object> result = (Map<String, Object>) responseData.get(SerTokens.TOKEN_RESULT); return ResponseMessage.build(UUID.fromString(responseData.get(SerTokens.TOKEN_REQUEST).toString())) .code(ResponseStatusCode.getFromValue((Integer) status.get(SerTokens.TOKEN_CODE))) .statusMessage(status.get(SerTokens.TOKEN_MESSAGE).toString()) .statusAttributes((Map<String, Object>) status.get(SerTokens.TOKEN_ATTRIBUTES)) .result(result.get(SerTokens.TOKEN_DATA)) .responseMetaData((Map<String, Object>) result.get(SerTokens.TOKEN_META)) .create(); } catch (Exception ex) { logger.warn("Response [{}] could not be deserialized by {}.", msg, AbstractGraphSONMessageSerializerV1d0.class.getName()); throw new SerializationException(ex); } }
metadata.put(Tokens.ARGS_SASL, BASE64_ENCODER.encodeToString(saslMessage)); final ResponseMessage authenticate = ResponseMessage.build(requestMessage) .statusAttributes(metadata) .code(ResponseStatusCode.AUTHENTICATE).create(); ctx.writeAndFlush(authenticate);
return new Frame(serializer.serializeResponseAsBinary(ResponseMessage.build(msg) .code(code) .statusAttributes(statusAttributes) .responseMetaData(responseMetaData) .result(aggregate).create(), ctx.alloc())); return new Frame(textSerializer.serializeResponseAsString(ResponseMessage.build(msg) .code(code) .statusAttributes(statusAttributes) .responseMetaData(responseMetaData) .result(aggregate).create()));
@Override public ResponseMessage deserializeResponse(final ByteBuf msg) throws SerializationException { try { final Kryo kryo = kryoThreadLocal.get(); final byte[] payload = new byte[msg.capacity()]; msg.readBytes(payload); try (final Input input = new Input(payload)) { final UUID requestId = kryo.readObjectOrNull(input, UUID.class); final int status = input.readShort(); final String statusMsg = input.readString(); final Map<String,Object> statusAttributes = (Map<String,Object>) kryo.readClassAndObject(input); final Object result = kryo.readClassAndObject(input); final Map<String,Object> metaAttributes = (Map<String,Object>) kryo.readClassAndObject(input); return ResponseMessage.build(requestId) .code(ResponseStatusCode.getFromValue(status)) .statusMessage(statusMsg) .statusAttributes(statusAttributes) .result(result) .responseMetaData(metaAttributes) .create(); } } catch (Exception ex) { logger.warn(String.format("Response [%s] could not be deserialized by %s.", msg, AbstractGryoMessageSerializerV1d0.class.getName()), ex); throw new SerializationException(ex); } }
@Override public ByteBuf serializeResponseAsBinary(final ResponseMessage responseMessage, final ByteBufAllocator allocator) throws SerializationException { ByteBuf encodedMessage = null; try { final Kryo kryo = kryoThreadLocal.get(); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final Output output = new Output(baos, bufferSize); final ResponseMessage msgToWrite = !serializeToString ? responseMessage : ResponseMessage.build(responseMessage.getRequestId()) .code(responseMessage.getStatus().getCode()) .statusAttributes(responseMessage.getStatus().getAttributes()) .responseMetaData(responseMessage.getResult().getMeta()) .result(serializeResultToString(responseMessage)) .statusMessage(responseMessage.getStatus().getMessage()).create(); kryo.writeObject(output, msgToWrite); final long size = output.total(); if (size > Integer.MAX_VALUE) throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size)); output.flush(); encodedMessage = allocator.buffer((int) size); encodedMessage.writeBytes(baos.toByteArray()); } return encodedMessage; } catch (Exception ex) { if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage); logger.warn(String.format("Response [%s] could not be serialized by %s.", responseMessage, AbstractGryoMessageSerializerV3d0.class.getName()), ex); throw new SerializationException(ex); } }
@Override public ResponseMessage deserializeResponse(final String msg) throws SerializationException { try { final Map<String, Object> responseData = mapper.readValue(msg, mapTypeReference); final Map<String, Object> status = (Map<String, Object>) responseData.get(SerTokens.TOKEN_STATUS); final Map<String, Object> result = (Map<String, Object>) responseData.get(SerTokens.TOKEN_RESULT); return ResponseMessage.build(UUID.fromString(responseData.get(SerTokens.TOKEN_REQUEST).toString())) .code(ResponseStatusCode.getFromValue((Integer) status.get(SerTokens.TOKEN_CODE))) .statusMessage(status.get(SerTokens.TOKEN_MESSAGE).toString()) .statusAttributes((Map<String, Object>) status.get(SerTokens.TOKEN_ATTRIBUTES)) .result(result.get(SerTokens.TOKEN_DATA)) .responseMetaData((Map<String, Object>) result.get(SerTokens.TOKEN_META)) .create(); } catch (Exception ex) { logger.warn("Response [{}] could not be deserialized by {}.", msg, AbstractGraphSONMessageSerializerV1d0.class.getName()); throw new SerializationException(ex); } }
@Override public ResponseMessage deserializeResponse(final ByteBuf msg) throws SerializationException { try { final byte[] payload = new byte[msg.readableBytes()]; msg.readBytes(payload); final Map<String, Object> responseData = mapper.readValue(payload, mapTypeReference); final Map<String, Object> status = (Map<String, Object>) responseData.get(SerTokens.TOKEN_STATUS); final Map<String, Object> result = (Map<String, Object>) responseData.get(SerTokens.TOKEN_RESULT); return ResponseMessage.build(UUID.fromString(responseData.get(SerTokens.TOKEN_REQUEST).toString())) .code(ResponseStatusCode.getFromValue((Integer) status.get(SerTokens.TOKEN_CODE))) .statusMessage(status.get(SerTokens.TOKEN_MESSAGE).toString()) .statusAttributes((Map<String, Object>) status.get(SerTokens.TOKEN_ATTRIBUTES)) .result(result.get(SerTokens.TOKEN_DATA)) .responseMetaData((Map<String, Object>) result.get(SerTokens.TOKEN_META)) .create(); } catch (Exception ex) { logger.warn("Response [{}] could not be deserialized by {}.", msg, AbstractGraphSONMessageSerializerV1d0.class.getName()); throw new SerializationException(ex); } }
@Override public <I extends InputShim> ResponseMessage read(final KryoShim<I, ?> kryo, final I input, final Class<ResponseMessage> clazz) { final UUID requestId = kryo.readObjectOrNull(input, UUID.class); final int status = input.readShort(); final String statusMsg = input.readString(); final Map<String,Object> statusAttributes = (Map<String,Object>) kryo.readClassAndObject(input); final Object result = kryo.readClassAndObject(input); final Map<String,Object> metaAttributes = (Map<String,Object>) kryo.readClassAndObject(input); return ResponseMessage.build(requestId) .code(ResponseStatusCode.getFromValue(status)) .statusMessage(statusMsg) .statusAttributes(statusAttributes) .result(result) .responseMetaData(metaAttributes) .create(); } }
@Override public ResponseMessage createObject(final Map<String, Object> data) { final Map<String, Object> status = (Map<String, Object>) data.get(SerTokens.TOKEN_STATUS); final Map<String, Object> result = (Map<String, Object>) data.get(SerTokens.TOKEN_RESULT); return ResponseMessage.build(UUID.fromString(data.get(SerTokens.TOKEN_REQUEST).toString())) .code(ResponseStatusCode.getFromValue((Integer) status.get(SerTokens.TOKEN_CODE))) .statusMessage(status.get(SerTokens.TOKEN_MESSAGE).toString()) .statusAttributes((Map<String, Object>) status.get(SerTokens.TOKEN_ATTRIBUTES)) .result(result.get(SerTokens.TOKEN_DATA)) .responseMetaData((Map<String, Object>) result.get(SerTokens.TOKEN_META)) .create(); } }
public ResponseMessage readValue(final ByteBuf buffer, final GraphBinaryReader context, final boolean nullable) throws SerializationException { final int version = buffer.readByte(); assert version >>> 31 == 1; return ResponseMessage.build(context.readValue(buffer, UUID.class, true)) .code(ResponseStatusCode.getFromValue(context.readValue(buffer, Integer.class, false))) .statusMessage(context.readValue(buffer, String.class, true)) .statusAttributes(context.readValue(buffer, Map.class, false)) .responseMetaData(context.readValue(buffer, Map.class, false)) .result(context.read(buffer)) .create(); }
.statusAttributes(generateStatusAttributes(ctx, msg, ResponseStatusCode.NO_CONTENT, itty, settings)) .create()); return;
rhc.writeAndFlush(ResponseMessage.build(msg) .code(ResponseStatusCode.NO_CONTENT) .statusAttributes(generateStatusAttributes(ctx, msg, ResponseStatusCode.NO_CONTENT, itty, settings)) .create()); return;
metadata.put(Tokens.ARGS_SASL, BASE64_ENCODER.encodeToString(saslMessage)); final ResponseMessage authenticate = ResponseMessage.build(requestMessage) .statusAttributes(metadata) .code(ResponseStatusCode.AUTHENTICATE).create(); ctx.writeAndFlush(authenticate);
@Override public ByteBuf serializeResponseAsBinary(final ResponseMessage responseMessage, final ByteBufAllocator allocator) throws SerializationException { ByteBuf encodedMessage = null; try { final Kryo kryo = kryoThreadLocal.get(); try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final Output output = new Output(baos, bufferSize); final ResponseMessage msgToWrite = !serializeToString ? responseMessage : ResponseMessage.build(responseMessage.getRequestId()) .code(responseMessage.getStatus().getCode()) .statusAttributes(responseMessage.getStatus().getAttributes()) .responseMetaData(responseMessage.getResult().getMeta()) .result(serializeResultToString(responseMessage)) .statusMessage(responseMessage.getStatus().getMessage()).create(); kryo.writeObject(output, msgToWrite); final long size = output.total(); if (size > Integer.MAX_VALUE) throw new SerializationException(String.format("Message size of %s exceeds allocatable space", size)); output.flush(); encodedMessage = allocator.buffer((int) size); encodedMessage.writeBytes(baos.toByteArray()); } return encodedMessage; } catch (Exception ex) { if (encodedMessage != null) ReferenceCountUtil.release(encodedMessage); logger.warn(String.format("Response [%s] could not be serialized by %s.", responseMessage, AbstractGryoMessageSerializerV3d0.class.getName()), ex); throw new SerializationException(ex); } }
return new Frame(serializer.serializeResponseAsBinary(ResponseMessage.build(msg) .code(code) .statusAttributes(statusAttributes) .responseMetaData(responseMetaData) .result(aggregate).create(), ctx.alloc())); return new Frame(textSerializer.serializeResponseAsString(ResponseMessage.build(msg) .code(code) .statusAttributes(statusAttributes) .responseMetaData(responseMetaData) .result(aggregate).create()));
@Override public ResponseMessage deserializeResponse(final ByteBuf msg) throws SerializationException { try { final Kryo kryo = kryoThreadLocal.get(); final byte[] payload = new byte[msg.capacity()]; msg.readBytes(payload); try (final Input input = new Input(payload)) { final UUID requestId = kryo.readObjectOrNull(input, UUID.class); final int status = input.readShort(); final String statusMsg = input.readString(); final Map<String,Object> statusAttributes = (Map<String,Object>) kryo.readClassAndObject(input); final Object result = kryo.readClassAndObject(input); final Map<String,Object> metaAttributes = (Map<String,Object>) kryo.readClassAndObject(input); return ResponseMessage.build(requestId) .code(ResponseStatusCode.getFromValue(status)) .statusMessage(statusMsg) .statusAttributes(statusAttributes) .result(result) .responseMetaData(metaAttributes) .create(); } } catch (Exception ex) { logger.warn(String.format("Response [%s] could not be deserialized by %s.", msg, AbstractGryoMessageSerializerV1d0.class.getName()), ex); throw new SerializationException(ex); } }
@Override public <I extends InputShim> ResponseMessage read(final KryoShim<I, ?> kryo, final I input, final Class<ResponseMessage> clazz) { final UUID requestId = kryo.readObjectOrNull(input, UUID.class); final int status = input.readShort(); final String statusMsg = input.readString(); final Map<String,Object> statusAttributes = (Map<String,Object>) kryo.readClassAndObject(input); final Object result = kryo.readClassAndObject(input); final Map<String,Object> metaAttributes = (Map<String,Object>) kryo.readClassAndObject(input); return ResponseMessage.build(requestId) .code(ResponseStatusCode.getFromValue(status)) .statusMessage(statusMsg) .statusAttributes(statusAttributes) .result(result) .responseMetaData(metaAttributes) .create(); } }
public ResponseMessage readValue(final ByteBuf buffer, final GraphBinaryReader context, final boolean nullable) throws SerializationException { final int version = buffer.readByte(); assert version >>> 31 == 1; return ResponseMessage.build(context.readValue(buffer, UUID.class, true)) .code(ResponseStatusCode.getFromValue(context.readValue(buffer, Integer.class, false))) .statusMessage(context.readValue(buffer, String.class, true)) .statusAttributes(context.readValue(buffer, Map.class, false)) .responseMetaData(context.readValue(buffer, Map.class, false)) .result(context.read(buffer)) .create(); }