private void makeACall(String url, String oldUrl, HttpServletResponse res) throws ClientProtocolException, IOException { HttpGet httpget = new HttpGet(url); byte[] b = null; CloseableHttpClient httpclient = HttpClients.createDefault(); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); if (entity != null) { InputStream in = entity.getContent(); PrintWriter writer = res.getWriter(); try { // read remote host respponse // copy from one response to another one ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while (true) { int r = in.read(buffer); if (r == -1) break; out.write(buffer, 0, r); } byte[] ret = out.toByteArray(); out.write(buffer); out.flush(); out.close(); // populate local host response writer.print(new String(ret)); res.setStatus(HttpServletResponse.SC_CREATED); res.setContentLength(ret.length); res.setContentType("text/json"); res.setHeader("Location", oldUrl); res.setHeader("Access-Control-Allow-Origin", oldUrl); res.setHeader("Content-Type", "application/json"); } finally { writer.flush(); writer.close(); in.close(); } } } finally { response.close(); } }
This blog about how to analyse data and prepare it for visualization. Will be used Clojure, C2: Clojure(Script) for data visualization. How to use Variance charts. About using Clojure where Java and JScript are stuck and sucks. GitHub: csv-statistic
Saturday, July 23, 2016
How I could copy one response to another by httpClient
I trtied to copy content of one response to another but still failed:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment