@Override
    public EurekaHttpResponse<InstanceInfo> sendHeartBeat(String appName, String id, InstanceInfo info, InstanceStatus overriddenStatus) {
        String urlPath = "apps/" + appName + '/' + id;
        Response response = null;
        try {
            WebTarget webResource = jerseyClient.target(serviceUrl)
                    .path(urlPath)
                    .queryParam("status", info.getStatus().toString())
                    .queryParam("lastDirtyTimestamp", info.getLastDirtyTimestamp().toString());
            if (overriddenStatus != null) {
                webResource = webResource.queryParam("overriddenstatus", overriddenStatus.name());
            }
            Builder requestBuilder = webResource.request();
            addExtraHeaders(requestBuilder);
            response = requestBuilder.accept(MediaType.APPLICATION_JSON_TYPE).put(Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE)); // Jersey2 refuses to handle PUT with no body
            InstanceInfo infoFromPeer = null;
            if (response.getStatus() == Status.CONFLICT.getStatusCode() && response.hasEntity()) {
                infoFromPeer = response.readEntity(InstanceInfo.class);
            }
            return anEurekaHttpResponse(response.getStatus(), infoFromPeer).type(MediaType.APPLICATION_JSON_TYPE).build();
        } finally {
            if (logger.isDebugEnabled()) {
                logger.debug("[heartbeat] Jersey HTTP PUT {}; statusCode={}", urlPath, response == null ? "N/A" : response.getStatus());
            }
            if (response != null) {
                response.close();
            }
        }
    }
@Test
    public void testHeartbeatReplicationWithResponseBody() throws Exception {
        InstanceInfo remoteInfo = new InstanceInfo(this.instanceInfo);
        remoteInfo.setStatus(InstanceStatus.DOWN);
        byte[] responseBody = toGzippedJson(remoteInfo);

        serverMockClient.when(
                request()
                        .withMethod("PUT")
                        .withHeader(header(PeerEurekaNode.HEADER_REPLICATION, "true"))
                        .withPath("/eureka/v2/apps/" + this.instanceInfo.getAppName() + '/' + this.instanceInfo.getId())
        ).respond(
                response()
                        .withStatusCode(Status.CONFLICT.getStatusCode())
                        .withHeader(header("Content-Type", MediaType.APPLICATION_JSON))
                        .withHeader(header("Content-Encoding", "gzip"))
                        .withBody(responseBody)
        );

        EurekaHttpResponse<InstanceInfo> response = replicationClient.sendHeartBeat(this.instanceInfo.getAppName(), this.instanceInfo.getId(), this.instanceInfo, null);
        assertThat(response.getStatusCode(), is(equalTo(Status.CONFLICT.getStatusCode())));
        assertThat(response.getEntity(), is(notNullValue()));
    }