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);
    }
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 (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()) {
           
            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);
    }
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 (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()) { 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); }