private String postPlain()

in src/main/java/org/apache/nlpcraft/client/impl/NCClientImpl.java [357:401]


    private String postPlain(String url, List<Pair<String, ?>> ps) throws NCClientException, IOException {
        HttpPost post = new HttpPost(baseUrl + url);
        
        try {
            post.setConfig(reqCfg);
    
            StringEntity entity = new StringEntity(
                gson.toJson(ps.stream().collect(Collectors.toMap(Pair::getKey, Pair::getValue))),
                "UTF-8"
            );
            
            post.setHeader("Content-Type", "application/json");
            post.setEntity(entity);
            
            ResponseHandler<String> h = resp -> {
                int code = resp.getStatusLine().getStatusCode();
                
                HttpEntity e = resp.getEntity();
                
                String js = e != null ? EntityUtils.toString(e) : null;
    
                if (js == null)
                    throw new NCClientException(String.format("Unexpected empty response [code=%d]", code));

                if (code == 200)
                    return js;

                NCErrorMessageBean err;
                
                try {
                     err = gson.fromJson(js, NCErrorMessageBean.class);
                }
                catch (Exception e1) {
                    throw new NCClientException(String.format("Unexpected server error [code=%d]", code));
                }

                throw new NCClientException(err.getMessage(), err.getCode());
            };
            
            return httpCli.execute(post, h);
        }
        finally {
            post.releaseConnection();
        }
    }