private void doExternalServicesBadInputTest(RestMethod[] restMethods, String expectedExceptionMsg,
      boolean expectRouterCall) throws JSONException {
    for (RestMethod restMethod : restMethods) {
      if (restMethod.equals(RestMethod.UNKNOWN)) {
        continue;
      }
      JSONObject headers = new JSONObject();
      List<ByteBuffer> contents = null;
      if (restMethod.equals(RestMethod.POST)) {
        setAmbryHeadersForPut(headers, 7200, !refContainer.isCacheable(), "doExternalServicesBadInputTest",
            "application/octet-stream", "doExternalServicesBadInputTest", refAccount.getName(), refContainer.getName(),
            null);
        contents = new ArrayList<>(1);
        contents.add(null);
      }
      String blobIdStr = new BlobId(blobIdVersion, BlobId.BlobIdType.NATIVE, (byte) -1, Account.UNKNOWN_ACCOUNT_ID,
          Container.UNKNOWN_CONTAINER_ID, clusterMap.getAllPartitionIds(null).get(0), false,
          BlobId.BlobDataType.DATACHUNK).getID();
      try {
        doOperation(createRestRequest(restMethod, blobIdStr, headers, contents), new MockRestResponseChannel());
        fail("Operation " + restMethod
            + " should have failed because an external service would have thrown an exception");
      } catch (Exception e) {
        assertEquals("Unexpected exception message", expectedExceptionMsg, e.getMessage());
        if (expectRouterCall && restMethod == RestMethod.GET) {
          assertNotNull("expected router.getBlob() call to provide a response to responseHandler",
              responseHandler.getResponse());
        }
      }
    }
  }
Does the tests to check for exception pipelining for exceptions returned/thrown by external services.
@param restMethods the {@link RestMethod} types for which the test has to be run.
@param expectedExceptionMsg the expected exception message.
@param expectRouterCall if the router should have returned a value before the exception occurs.
@throws JSONException
ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendRestRequestServiceTest.java