@Override public Response _apply(Request request) { try { // Serialize the request to "send to the server" byte[] serializedRequest = translation.serializeRequest(request); // *some transport would normally happen here* // Fake deserializing that request somewhere else Request request2 = translation.parseRequest(serializedRequest); // Serialize the response from the service to "send to the client" byte[] serializedResponse = translation.serializeResponse(request2.accept(service)); // *some transport would normally happen here* // Deserialize the response on "the client" return translation.parseResponse(serializedResponse); } catch (IOException e) { throw new RuntimeException(e); } } }
public Response apply(Response response) throws IOException { // Serialize and then re-pare the response return translation.parseResponse(translation.serializeResponse(response)); } }
public Request apply(Request request) throws IOException { // Serialize and then re-parse the request return translation.parseRequest(translation.serializeRequest(request)); } }
@Override public Response _apply(Request request) { final Response resp; try { byte[] response = client.send(translation.serializeRequest(request)); resp = translation.parseResponse(response); } catch (IOException e) { // Not a protobuf that we could parse. throw new RuntimeException(e); } // The server had an error, throw an Exception for that. if (resp instanceof ErrorResponse) { throw ((ErrorResponse) resp).toException(); } return resp; } }
FetchResponse response = new FetchResponse(frame, false, false, metadata); when(translation.parseRequest(serializedRequest)).thenReturn(request); when(service.apply(request)).thenReturn(response); when(translation.serializeResponse(response)) .thenReturn(response.serialize().toByteArray());
@Override Service.Request decode(byte[] serializedRequest) throws IOException { return translation.parseRequest(serializedRequest); }
@Override byte[] encode(Response response) throws IOException { return translation.serializeResponse(response); } }
@Override public Response _apply(Request request) { final Response resp; byte[] response = null; try { response = client.send(translation.serializeRequest(request)); } catch (IOException e) { LOG.debug("Failed to execute remote request: {}", request); // Failed to get a response from the server for the request. throw new RuntimeException(e); } try { resp = translation.parseResponse(response); } catch (IOException e) { LOG.debug("Failed to deserialize reponse to {}. '{}'", request, new String(response, StandardCharsets.UTF_8)); // Not a protobuf that we could parse. throw new RuntimeException(e); } // The server had an error, throw an Exception for that. if (resp instanceof ErrorResponse) { throw ((ErrorResponse) resp).toException(); } return resp; } }
public Response apply(Response response) throws IOException { // Serialize and then re-pare the response return translation.parseResponse(translation.serializeResponse(response)); } }
public Request apply(Request request) throws IOException { // Serialize and then re-parse the request return translation.parseRequest(translation.serializeRequest(request)); } }
FetchResponse response = new FetchResponse(frame, false, false, metadata); when(translation.parseRequest(serializedRequest)).thenReturn(request); when(service.apply(request)).thenReturn(response); when(translation.serializeResponse(response)) .thenReturn(response.serialize().toByteArray());
@Override Service.Request decode(byte[] serializedRequest) throws IOException { try (final Context ctx = serializationTimer.start()) { return translation.parseRequest(serializedRequest); } }
@Override byte[] encode(Response response) throws IOException { try (final Context ctx = serializationTimer.start()) { return translation.serializeResponse(response); } } }
@Override public Response _apply(Request request) { try { // Serialize the request to "send to the server" byte[] serializedRequest = translation.serializeRequest(request); // *some transport would normally happen here* // Fake deserializing that request somewhere else Request request2 = translation.parseRequest(serializedRequest); // Serialize the response from the service to "send to the client" byte[] serializedResponse = translation.serializeResponse(request2.accept(service)); // *some transport would normally happen here* // Deserialize the response on "the client" return translation.parseResponse(serializedResponse); } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public Response _apply(Request request) { final Response resp; byte[] response = null; try { response = client.send(translation.serializeRequest(request)); } catch (IOException e) { LOG.debug("Failed to execute remote request: {}", request); // Failed to get a response from the server for the request. throw new RuntimeException(e); } try { resp = translation.parseResponse(response); } catch (IOException e) { LOG.debug("Failed to deserialize reponse to {}. '{}'", request, new String(response, StandardCharsets.UTF_8)); // Not a protobuf that we could parse. throw new RuntimeException(e); } // The server had an error, throw an Exception for that. if (resp instanceof ErrorResponse) { throw ((ErrorResponse) resp).toException(); } return resp; } }
public Response apply(Response response) throws IOException { // Serialize and then re-pare the response return translation.parseResponse(translation.serializeResponse(response)); } }
public Request apply(Request request) throws IOException { // Serialize and then re-parse the request return translation.parseRequest(translation.serializeRequest(request)); } }
FetchResponse response = new FetchResponse(frame, false, false, metadata); when(translation.parseRequest(serializedRequest)).thenReturn(request); when(service.apply(request)).thenReturn(response); when(translation.serializeResponse(response)) .thenReturn(response.serialize().toByteArray());
@Override Service.Request decode(byte[] serializedRequest) throws IOException { try (final Context ctx = serializationTimer.start()) { return translation.parseRequest(serializedRequest); } }
@Override byte[] encode(Response response) throws IOException { try (final Context ctx = serializationTimer.start()) { return translation.serializeResponse(response); } } }