/** * removed header (only used for authorization for PP) 2015.08 * * @param url the url * @return the JSON object * @throws MalformedURLException the malformed url exception * @throws IOException Signals that an I/O exception has occurred. * @throws JSONException the JSON exception */ static JSONObject readJsonFromUrlWithCmsHeader(String url) throws MalformedURLException, IOException, JSONException { InputStream is = null; JSONObject jObj = new JSONObject(); try { HttpURLConnection.setFollowRedirects(false); HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod("GET"); con.setConnectTimeout(ParallecGlobalConfig.urlConnectionConnectTimeoutMillis); con.setReadTimeout(ParallecGlobalConfig.urlConnectionReadTimeoutMillis); is = con.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); String jsonText = PcFileNetworkIoUtils.readAll(rd); jObj = new JSONObject(jsonText); rd.close(); } catch (Exception t) { logger.error( "readJsonFromUrl() exception: " + t.getLocalizedMessage() + PcDateUtils.getNowDateTimeStrStandard()); } finally { if (is != null) { is.close(); } } return jObj; }
@Ignore // @Test public void hitTop100WebsitesViaIps() { List<String> hostNames = PcFileNetworkIoUtils.getListFromLineByLineText(FILEPATH_TOP_100, SOURCE_LOCAL); List<String> hostIps = new ArrayList<String>(); int count = 0; for (String hostName : hostNames) { logger.info("get ip for host # {}", ++count); InetAddress address; try { address = InetAddress.getByName(hostName); hostIps.add(address.getHostAddress()); } catch (UnknownHostException e) { e.printStackTrace(); } } ParallelTask pt = pc.prepareHttpGet("") .setConcurrency(1000) .setTargetHostsFromList(hostIps) // .setTargetHostsFromLineByLineText(FILEPATH_TOP_100, // SOURCE_LOCAL) .execute( new ParallecResponseHandler() { @Override public void onCompleted( ResponseOnSingleTask res, Map<String, Object> responseContext) { logger.info( "Responose Code:" + res.getStatusCode() + " host: " + res.getHost()); } }); logger.info( "Result Summary\n{}", PcStringUtils.renderJson(pt.getAggregateResultCountSummary())); }