// CHECKSTYLE: stop IllegalCatch public static HttpURLConnection openOutputConnection( ImmutableClassesGiraphConfiguration conf, String type) throws InterruptedException { String uriFormat = "/graphs/%s/tp/giraph/%s/"; String endpoint = GIRAPH_REXSTER_HOSTNAME.get(conf); boolean isSsl = GIRAPH_REXSTER_USES_SSL.get(conf); int port = GIRAPH_REXSTER_PORT.get(conf); String graph = GIRAPH_REXSTER_OUTPUT_GRAPH.get(conf); try { URL url = new URL(isSsl ? "https" : "http", endpoint, port, String.format(uriFormat, graph, type)); LOG.info(url); String username = GIRAPH_REXSTER_USERNAME.get(conf); String password = GIRAPH_REXSTER_PASSWORD.get(conf); String auth = getHTTPAuthString(username, password); HttpURLConnection connection = createConnection(url, "POST", auth); connection.setRequestProperty("Content-Type", "application/json; cherset=UTF-8"); connection.setDoInput(true); connection.setDoOutput(true); return connection; } catch (Exception e) { throw new InterruptedException(e.getMessage()); } }
// CHECKSTYLE: stop IllegalCatch public static BufferedReader openInputStream( ImmutableClassesGiraphConfiguration conf, long start, long end, String type, String gremlinScript) throws InterruptedException { String uriScriptFormat = "/graphs/%s/tp/gremlin?script=%s" + "&rexster.offset.start=%s&rexster.offset.end=%s"; String uriFormat = "/graphs/%s/tp/giraph/%s/" + "?rexster.offset.start=%s&rexster.offset.end=%s"; String endpoint = GIRAPH_REXSTER_HOSTNAME.get(conf); try { boolean isSsl = GIRAPH_REXSTER_USES_SSL.get(conf); int port = GIRAPH_REXSTER_PORT.get(conf); String graph = GIRAPH_REXSTER_INPUT_GRAPH.get(conf); URL url; if (gremlinScript != null && !gremlinScript.isEmpty()) { url = new URL( isSsl ? "https" : "http", endpoint, port, String.format(uriScriptFormat, graph, gremlinScript, start, end)); } else { url = new URL( isSsl ? "https" : "http", endpoint, port, String.format(uriFormat, graph, type, start, end)); } LOG.info(url); String username = GIRAPH_REXSTER_USERNAME.get(conf); String password = GIRAPH_REXSTER_PASSWORD.get(conf); String auth = getHTTPAuthString(username, password); HttpURLConnection connection = createConnection(url, "GET", auth); connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); connection.setDoInput(true); connection.setDoOutput(false); RexsterUtils.handleResponse(connection, type); InputStream is = connection.getInputStream(); InputStreamReader isr = new InputStreamReader(is, Charset.forName("UTF-8")); return new BufferedReader(isr); } catch (Exception e) { throw new InterruptedException(e.getMessage()); } }