stream.flush(); return RawData.outbound(stream.toByteArray(), getDestination(address), callback, false);
public static Observation deserialize(byte[] data) { JsonObject v = (JsonObject) Json.parse(new String(data)); EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject()); byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray()); RawData rawData = RawData.outbound(req, endpointContext, null, false); Request request = (Request) parser.parseMessage(rawData); request.setDestinationContext(endpointContext); JsonValue ctxValue = v.get("context"); if (ctxValue != null) { Map<String, String> context = new HashMap<>(); JsonObject ctxObject = (JsonObject) ctxValue; for (String name : ctxObject.names()) { context.put(name, ctxObject.getString(name, null)); } request.setUserContext(context); } return new Observation(request, endpointContext); }
public static Observation deserialize(byte[] data) { JsonObject v = (JsonObject) Json.parse(new String(data)); EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject()); byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray()); RawData rawData = RawData.outbound(req, endpointContext, null, false); Request request = (Request) parser.parseMessage(rawData); request.setDestinationContext(endpointContext); JsonValue ctxValue = v.get("context"); if (ctxValue != null) { Map<String, String> context = new HashMap<>(); JsonObject ctxObject = (JsonObject) ctxValue; for (String name : ctxObject.names()) { context.put(name, ctxObject.getString(name, null)); } request.setUserContext(context); } return new Observation(request, endpointContext); }
/** * Serializes a request and caches the result on the request object to skip future serializations. * <p> * NB: The byte array cached in the message is encoded according to the specific serializer implementation's * supported wire format. Any subsequent invocation of this method with the same request object will therefore * simply return the cached byte array. This may cause problems when the first invocation was done on a different * type of serializer than the second. * <p> * Clients should use the {@link #getByteArray(Request)} method in order to prevent caching of the resulting * byte array. * * @param request The request to serialize. * @param outboundCallback The callback to invoke once the message's correlation context * has been established. * @return The object containing the serialized request and the callback. */ public final RawData serializeRequest(final Request request, final MessageCallback outboundCallback) { if (request.getBytes() == null) { request.setBytes(getByteArray(request)); } return RawData.outbound( request.getBytes(), new InetSocketAddress(request.getDestination(), request.getDestinationPort()), outboundCallback, false); }