//}
private String prepareHeadersAndBodyForService(HttpServletRequest request, String method, String url,
                                                   List<String> clientRequestHeaders, Interactor.Interaction interaction,
                                                   String clientRequestContentType,
                                                   InteractionManipulations interactionManipulations) throws IOException {
        Enumeration<String> hdrs = request.getHeaderNames();
        ServletInputStream is = request.getInputStream();
        Object clientRequestBody = null;
        //if (is.available() > 0) {
            if (isText(clientRequestContentType)) {
                clientRequestBody = null;
                String characterEncoding = request.getCharacterEncoding();
                if (characterEncoding == null) {
                    characterEncoding = "utf-8";
                }
                try (Scanner scanner = new Scanner(is, characterEncoding)) {
                    if(scanner.hasNext()) {
                        clientRequestBody = scanner.useDelimiter("\\A").next();
                    }
                }
                if (shouldHavePrettyPrintedTextBodies() && clientRequestBody != null) {
                    clientRequestBody = prettifyDocOrNot((String) clientRequestBody);
                }
            } else if(is.available() > 0){
                byte[] targetArray = new byte[is.available()];
                is.read(targetArray);
                clientRequestBody = targetArray;
            }
        //}
        while (hdrs.hasMoreElements()) {
            // TODO - make this cater for multiple lines with the same name
            String hdrName = hdrs.nextElement();
            String hdrVal = request.getHeader(hdrName);
            hdrVal = interactionManipulations.headerReplacement(hdrName, hdrVal);
            final String fullHeader = (getLowerCaseHeaders() ? hdrName.toLowerCase() : hdrName) + ": " + hdrVal;
            clientRequestHeaders.add(fullHeader);
            interactionManipulations.changeSingleHeaderForRequestToService(method, fullHeader, clientRequestHeaders);
        }
        interactionManipulations.changeAnyHeadersForRequestToService(clientRequestHeaders);
        if (clientRequestBody instanceof String) {
            clientRequestBody = interactionManipulations.changeBodyForRequestToService((String) clientRequestBody);
        }
        if (clientRequestBody == null) {
            clientRequestBody = "";
        }
        interaction.noteClientRequestHeadersAndBody(clientRequestHeaders, clientRequestBody, clientRequestContentType);
        return interactionManipulations.changeUrlForRequestToService(url);
    }
clientRequestBody = targetArray;
}
//}
while (hdrs.hasMoreElements()) {
// TODO - make this cater for multiple lines with the same name
}
}
if (shouldHavePrettyPrintedTextBodies() && clientRequestBody != null) {
clientRequestBody = prettifyDocOrNot((String) clientRequestBody);
}
} else if(is.available() > 0){
byte[] targetArray = new byte[is.available()];
is.read(targetArray);
clientRequestBody = targetArray;
}
//}
while (hdrs.hasMoreElements()) {
// TODO - make this cater for multiple lines with the same name
String hdrName = hdrs.nextElement();
String hdrVal = request.getHeader(hdrName);
hdrVal = interactionManipulations.headerReplacement(hdrName, hdrVal);
final String fullHeader = (getLowerCaseHeaders() ? hdrName.toLowerCase() : hdrName) + ": " + hdrVal;
clientRequestHeaders.add(fullHeader);
interactionManipulations.changeSingleHeaderForRequestToService(method, fullHeader, clientRequestHeaders);
}
interactionManipulations.changeAnyHeadersForRequestToService(clientRequestHeaders);
//if (is.available() > 0) {
if (isText(clientRequestContentType)) {
clientRequestBody = null;
String characterEncoding = request.getCharacterEncoding();
if (characterEncoding == null) {
characterEncoding = "utf-8";
}
try (Scanner scanner = new Scanner(is, characterEncoding)) {
if(scanner.hasNext()) {
clientRequestBody = scanner.useDelimiter("\\A").next();
}
}
if (shouldHavePrettyPrintedTextBodies() && clientRequestBody != null) {
clientRequestBody = prettifyDocOrNot((String) clientRequestBody);
}
} else if(is.available() > 0){
byte[] targetArray = new byte[is.available()];
is.read(targetArray);
clientRequestBody = targetArray;
}
//}
while (hdrs.hasMoreElements()) {
// TODO - make this cater for multiple lines with the same name
String hdrName = hdrs.nextElement();
String hdrVal = request.getHeader(hdrName);
hdrVal = interactionManipulations.headerReplacement(hdrName, hdrVal);
final String fullHeader = (getLowerCaseHeaders() ? hdrName.toLowerCase() : hdrName) + ": " + hdrVal;
clientRequestHeaders.add(fullHeader);
interactionManipulations.changeSingleHeaderForRequestToService(method, fullHeader, clientRequestHeaders);
}
interactionManipulations.changeAnyHeadersForRequestToService(clientRequestHeaders);
if (clientRequestBody instanceof String) {
clientRequestBody = interactionManipulations.changeBodyForRequestToService((String) clientRequestBody);
}
if (clientRequestBody == null) {
clientRequestBody = "";
}
interaction.noteClientRequestHeadersAndBody(clientRequestHeaders, clientRequestBody, clientRequestContentType);
return interactionManipulations.changeUrlForRequestToService(url);
}