public WilmaHttpResponse callSecondaryServer()

in wilma-extras/replicator/src/main/java/com/epam/wilma/extras/replicator/secondaryClient/SecondaryClient.java [56:92]


    public WilmaHttpResponse callSecondaryServer(final WilmaHttpRequest wilmaHttpRequest) {
        URI uri = wilmaHttpRequest.getUri();
        WilmaHttpResponse wilmaResponse = null;

        try {
            if (wilmaHttpRequest.getRequestLine().startsWith("GET")) {
                //get method
                HttpGet httpGet = new HttpGet(uri.toString());

                //send/receive message
                wilmaResponse = secondaryRequestHandler.sendReceive(wilmaHttpRequest, httpGet);
            } else if (wilmaHttpRequest.getRequestLine().startsWith("POST")) {
                //post method
                HttpPost httpPost = new HttpPost(uri.toString());

                //prepare body
                InputStream inputStream = new ByteArrayInputStream(wilmaHttpRequest.getBody().getBytes("UTF-8"));
                String encoding = wilmaHttpRequest.getHeader("Content-Encoding");
                if ((encoding != null) && (encoding.toLowerCase().contains("gzip"))) {
                    inputStream = gzipCompressor.compress(inputStream);
                }
                String contentType = wilmaHttpRequest.getHeader("Content-Type");
                if (contentType == null) {
                    contentType = "text/plain";
                }
                InputStreamEntity reqEntity = new InputStreamEntity(inputStream, -1, ContentType.create(contentType));
                httpPost.setEntity(reqEntity);

                //send/receive message
                wilmaResponse = secondaryRequestHandler.sendReceive(wilmaHttpRequest, httpPost);
            }
        } catch (IOException e) {
            logger.error("Secondary Request Issue", e);
        }

        return wilmaResponse;
    }