@Override
 public FindRequestsResult findRequestsMatching(RequestPattern requestPattern) {
   String body =
       postJsonAssertOkAndReturnBody(
           urlFor(FindRequestsTask.class), Json.write(requestPattern), HTTP_OK);
   return Json.read(body, FindRequestsResult.class);
 }
  @Override
  public FindNearMissesResult findTopNearMissesFor(LoggedRequest loggedRequest) {
    String body =
        postJsonAssertOkAndReturnBody(
            urlFor(FindNearMissesForRequestTask.class), Json.write(loggedRequest), HTTP_OK);

    return Json.read(body, FindNearMissesResult.class);
  }
 @Override
 public VerificationResult countRequestsMatching(RequestPattern requestPattern) {
   String body =
       postJsonAssertOkAndReturnBody(
           urlFor(GetRequestCountTask.class), Json.write(requestPattern), HTTP_OK);
   return VerificationResult.from(body);
 }
  private <B, R> R executeRequest(
      RequestSpec requestSpec,
      PathParams pathParams,
      B requestBody,
      Class<R> responseType,
      int expectedStatus) {
    String url =
        String.format(
            ADMIN_URL_PREFIX + requestSpec.path(pathParams), scheme, host, port, urlPathPrefix);
    RequestBuilder requestBuilder =
        RequestBuilder.create(requestSpec.method().getName()).setUri(url);

    if (requestBody != null) {
      requestBuilder.setEntity(jsonStringEntity(Json.write(requestBody)));
    }

    String responseBodyString = safelyExecuteRequest(url, expectedStatus, requestBuilder.build());

    return responseType == Void.class ? null : Json.read(responseBodyString, responseType);
  }
 @Override
 public void updateGlobalSettings(GlobalSettings settings) {
   postJsonAssertOkAndReturnBody(
       urlFor(GlobalSettingsUpdateTask.class), Json.write(settings), HTTP_OK);
 }
 @Override
 public FindNearMissesResult findNearMissesForUnmatchedRequests() {
   String body =
       getJsonAssertOkAndReturnBody(urlFor(FindNearMissesForUnmatchedTask.class), HTTP_OK);
   return Json.read(body, FindNearMissesResult.class);
 }
 @Override
 public void removeStubMapping(StubMapping stubbMapping) {
   postJsonAssertOkAndReturnBody(
       urlFor(OldRemoveStubMappingTask.class), Json.write(stubbMapping), HTTP_OK);
 }
 @Override
 public void editStubMapping(StubMapping stubMapping) {
   postJsonAssertOkAndReturnBody(
       urlFor(OldEditStubMappingTask.class), Json.write(stubMapping), HTTP_NO_CONTENT);
 }
 @Override
 public ListStubMappingsResult listAllStubMappings() {
   String body = getJsonAssertOkAndReturnBody(urlFor(RootTask.class), HTTP_OK);
   return Json.read(body, ListStubMappingsResult.class);
 }
 @Override
 public void addStubMapping(StubMapping stubMapping) {
   postJsonAssertOkAndReturnBody(
       urlFor(NewStubMappingTask.class), Json.write(stubMapping), HTTP_CREATED);
 }
 @Override
 public void addSocketAcceptDelay(RequestDelaySpec spec) {
   postJsonAssertOkAndReturnBody(urlFor(SocketDelayTask.class), Json.write(spec), HTTP_OK);
 }