title: HttpUrlConnection taking too long, why?
body: <p>i made a HttpUrlConnection GET in Java. And takes a lot to process, the code makes a GET to a URL that returns a JSON. (Which is not that huge, just a couple of rows) Don't know why is taking like A LOT to process from a jQuery ajax call client-side.</p>
  
  <p>This is the Java code:</p>
  
  <pre><code>@RequestMapping(value = "/getchartdata", method = RequestMethod.GET)
      public ResponseEntity&lt;String&gt; graphChartData(ModelMap model, HttpServletRequest request) {
          String graphName = request.getParameter("graphName");
          String subgroup = request.getParameter("subgroup");
  
          HttpURLConnection connection = null;
          try {
              String configURL = EsbConfig.getProperty("graph.url", "http://localhost:8081");
              URL url = new URL(configURL + "/plot/get?graphName="+ graphName+"&amp;subgroup="+subgroup+"&amp;width=100");
              connection = (HttpURLConnection) url.openConnection();
              connection.connect();
  
              BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
              String line = null;
  
              StringBuilder responseData = new StringBuilder();
              while((line = in.readLine()) != null) {
                  responseData.append(line);
              }       
              HttpHeaders responseHeaders = new HttpHeaders();
              responseHeaders.setContentType(MediaType.APPLICATION_JSON);
              return new ResponseEntity&lt;String&gt;(responseData.toString(), responseHeaders, HttpStatus.CREATED);
          } catch (MalformedURLException e1) {
              e1.printStackTrace();
          } catch (IOException e1) {
              e1.printStackTrace();
          } finally {
              if(null != connection) { connection.disconnect(); }
          }
  
          return null;
      }
  </code></pre>
  
  <p>I won't add the ajax call since it's pretty plane and simple, nothing to say about that.
  If i access directly with the entire URL, i get the json response in nano seconds. If i make the call from client-side, it takes like 10 seconds to retrieve the info.</p>
  
  <p>Any ideas on what's wrong? or any other HTTP get i could implement?</p>
  
  <p>Thanks.</p>