@SuppressWarnings("unchecked")
    public static void handleStandardPost(EntityEnclosingMethod methodProxyRequest,
                                          HttpServletRequest httpServletRequest,
                                          History history) throws Exception {
        String deserialisedMessages = "";
        byte[] requestByteArray = null;
        // Create a new StringBuffer with the data to be passed
        StringBuilder requestBody = new StringBuilder();
        InputStream body = httpServletRequest.getInputStream();
        RequestEntity requestEntity = null;

        if (httpServletRequest.getContentType() != null &&
            httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_FORM_URLENCODED)
            && httpServletRequest.getHeader("content-encoding") == null) {
            requestByteArray = IOUtils.toByteArray(body);
            history.setRawPostData(requestByteArray);

            // this is binary.. just return it as is
            requestEntity = new ByteArrayRequestEntity(requestByteArray);

            // Get the client POST data as a Map if content type is: application/x-www-form-urlencoded
            // We do this manually since some data is not properly parseable by the servlet request
            Map<String, String[]> mapPostParameters = HttpUtilities.mapUrlEncodedParameters(requestByteArray);

            // Iterate the parameter names
            for (String stringParameterName : mapPostParameters.keySet()) {
                // Iterate the values for each parameter name
                String[] stringArrayParameterValues = mapPostParameters
                    .get(stringParameterName);
                for (String stringParameterValue : stringArrayParameterValues) {
                    // Create a NameValuePair and store in list

                    // add an & if there is already data
                    if (requestBody.length() > 0) {
                        requestBody.append("&");
                    }

                    requestBody.append(stringParameterName);

                    // not everything has a value so lets check
                    if (stringParameterValue.length() > 0) {
                        requestBody.append("=");
                        requestBody.append(stringParameterValue);
                    }
                }
            }
            /**
             * Process the post data string so it can be added to history
             * Separates individual params out and applies post data override as applicable
             */
            Proxy.QueryInformation queryInformation = Proxy.processPostDataString(requestBody.toString());
            // Set request body which is added to history
            requestBody = new StringBuilder(queryInformation.queryString);
            // Rewrite the post data if it is modified
            if (queryInformation.modified) {
                String postData = queryInformation.queryString;
                requestBody = new StringBuilder(postData);
                requestByteArray = postData.getBytes();
                requestEntity = new ByteArrayRequestEntity(requestByteArray);
            }
        } else if (httpServletRequest.getContentType() != null &&
            httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_MESSAGEPACK)) {

            /**
             * Convert input stream to bytes for it to be read by the deserializer
             * Unpack and iterate the list to see the contents
             */
            requestByteArray = IOUtils.toByteArray(body);
            history.setRawPostData(requestByteArray);
            requestEntity = new ByteArrayRequestEntity(requestByteArray);
            ByteArrayInputStream byteArrayIS = new ByteArrayInputStream(requestByteArray);
            MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(byteArrayIS);

            while (unpacker.hasNext()) {
                ImmutableValue message = unpacker.unpackValue();
                deserialisedMessages += message;
                deserialisedMessages += "\n";
            }

            history.setRequestBodyDecoded(true);
            requestBody = new StringBuilder(Proxy.processPostDataString(requestBody.toString()).queryString);
        } else {
            requestByteArray = IOUtils.toByteArray(body);
            history.setRawPostData(requestByteArray);

            // this is binary.. just return it as is
            requestEntity = new ByteArrayRequestEntity(requestByteArray);

            // decode this for history if it is encoded
            String requestBodyString = PluginHelper.getByteArrayDataAsString(httpServletRequest.getHeader("content-encoding"), requestByteArray);
            requestBody.append(requestBodyString);

            // mark in history if the body has been decoded
            if (!requestBodyString.equals(new String(requestByteArray))) {
                history.setRequestBodyDecoded(true);
            }
            requestBody = new StringBuilder(Proxy.processPostDataString(requestBody.toString()).queryString);
        }

        // set post body in history object
        history.setRequestPostData(requestBody.toString());

        // set post body in proxy request object
        methodProxyRequest.setRequestEntity(requestEntity);

        /**
         * Set the history to have decoded messagepack. Pass the byte data back to request
         */
        if (httpServletRequest.getContentType() != null &&
            httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_MESSAGEPACK)) {
            history.setRequestPostData(deserialisedMessages);
            ByteArrayRequestEntity byteRequestEntity = new ByteArrayRequestEntity(requestByteArray);
            methodProxyRequest.setRequestEntity(byteRequestEntity);
        }
    }
@ SuppressWarnings ( "unchecked" ) public static void handleStandardPost ( EntityEnclosingMethod methodProxyRequest , HttpServletRequest httpServletRequest , History history ) throws Exception { String deserialisedMessages = "" ; byte [ ] requestByteArray = null ; StringBuilder requestBody = new StringBuilder ( ) ; InputStream body = httpServletRequest . getInputStream ( ) ; RequestEntity requestEntity = null ; if ( httpServletRequest . getContentType ( ) != null && httpServletRequest . getContentType ( ) . contains ( STRING_CONTENT_TYPE_FORM_URLENCODED ) && httpServletRequest . getHeader ( "content-encoding" ) == null ) { requestByteArray = IOUtils . toByteArray ( body ) ; history . setRawPostData ( requestByteArray ) ; requestEntity = new ByteArrayRequestEntity ( requestByteArray ) ; Map < String , String [ ] > mapPostParameters = HttpUtilities . mapUrlEncodedParameters ( requestByteArray ) ; for ( String stringParameterName : mapPostParameters . keySet ( ) ) { String [ ] stringArrayParameterValues = mapPostParameters . get ( stringParameterName ) ; for ( String stringParameterValue : stringArrayParameterValues ) { if ( requestBody . length ( ) > 0 ) { requestBody . append ( "&" ) ; } requestBody . append ( stringParameterName ) ; if ( stringParameterValue . length ( ) > 0 ) { requestBody . append ( "=" ) ; requestBody . append ( stringParameterValue ) ; } } } Proxy . QueryInformation queryInformation = Proxy . processPostDataString ( requestBody . toString ( ) ) ; requestBody = new StringBuilder ( queryInformation . queryString ) ; if ( queryInformation . modified ) { String postData = queryInformation . queryString ; requestBody = new StringBuilder ( postData ) ; requestByteArray = postData . getBytes ( ) ; requestEntity = new ByteArrayRequestEntity ( requestByteArray ) ; } } else if ( httpServletRequest . getContentType ( ) != null && httpServletRequest . getContentType ( ) . contains ( STRING_CONTENT_TYPE_MESSAGEPACK ) ) { requestByteArray = IOUtils . toByteArray ( body ) ; history . setRawPostData ( requestByteArray ) ; requestEntity = new ByteArrayRequestEntity ( requestByteArray ) ; ByteArrayInputStream byteArrayIS = new ByteArrayInputStream ( requestByteArray ) ; MessageUnpacker unpacker = MessagePack . newDefaultUnpacker ( byteArrayIS ) ; while ( unpacker . hasNext ( ) ) { ImmutableValue message = unpacker . unpackValue ( ) ; deserialisedMessages += message ; deserialisedMessages += "\n" ; } history . setRequestBodyDecoded ( true ) ; requestBody = new StringBuilder ( Proxy . processPostDataString ( requestBody . toString ( ) ) . queryString ) ; } else { requestByteArray = IOUtils . toByteArray ( body ) ; history . setRawPostData ( requestByteArray ) ; requestEntity = new ByteArrayRequestEntity ( requestByteArray ) ; String requestBodyString = PluginHelper . getByteArrayDataAsString ( httpServletRequest . getHeader ( "content-encoding" ) , requestByteArray ) ; requestBody . append ( requestBodyString ) ; if ( ! requestBodyString . equals ( new String ( requestByteArray ) ) ) { history . setRequestBodyDecoded ( true ) ; } requestBody = new StringBuilder ( Proxy . processPostDataString ( requestBody . toString ( ) ) . queryString ) ; } history . setRequestPostData ( requestBody . toString ( ) ) ; methodProxyRequest . setRequestEntity ( requestEntity ) ; if ( httpServletRequest . getContentType ( ) != null && httpServletRequest . getContentType ( ) . contains ( STRING_CONTENT_TYPE_MESSAGEPACK ) ) { history . setRequestPostData ( deserialisedMessages ) ; ByteArrayRequestEntity byteRequestEntity = new ByteArrayRequestEntity ( requestByteArray ) ; methodProxyRequest . setRequestEntity ( byteRequestEntity ) ; } }
Sets up the given {@link org.apache.commons.httpclient.methods.PostMethod} to send the same standard POST data
as was sent in the given {@link HttpServletRequest}

@param methodProxyRequest The {@link org.apache.commons.httpclient.methods.PostMethod} that we are configuring to send a
standard POST request
@param httpServletRequest The {@link HttpServletRequest} that contains the POST data to
be sent via the {@link org.apache.commons.httpclient.methods.PostMethod}
@param history The {@link com.groupon.odo.proxylib.models.History} log for this request