class HttpRequestTransformer {

    public WilmaHttpRequest transformRequest(final BrowserMobHttpRequest browserMobHttpRequest) throws ApplicationException {
        WilmaHttpRequest result = requestFactory.createNewWilmaHttpRequest();
        HttpRequestBase requestBase = browserMobHttpRequest.getMethod();
        result.setRequestLine(requestBase.getRequestLine().toString());
        for (Header header : requestBase.getAllHeaders()) {
            result.addHeader(header.getName(), header.getValue());
        }
        InputStream clonedInputStream = browserMobHttpRequest.getPlayGround();
        result.setInputStream(clonedInputStream);
        result.setBody(inputStreamConverter.getStringFromStream(clonedInputStream));
        result.setUri(requestBase.getURI());
        result.setResponseVolatile(browserMobHttpRequest.getResponseVolatile());
        //prepare instance prefix
        MessagePropertyDTO properties = configurationAccess.getProperties();
        String instancePrefix = properties.getInstancePrefix();
        if (instancePrefix != null) {
            instancePrefix += "_";  // "prefix_"
        } else {
            instancePrefix = "";
        }

        //set Wilma Message Id
        result.setWilmaMessageId(instancePrefix + browserMobHttpRequest.getWilmaMessageId());

        //set remote addr
        String ipAddress = browserMobHttpRequest.getProxyRequest().getRemoteAddr();
        result.setRemoteAddr(ipAddress);

        return result;
    }

}