/** * Hits the given Fedora Server URL and returns the response as a String. * Throws an IOException if the response code is not 200(OK). */ private static String getServerResponse(String protocol, String user, String pass, String path) throws IOException { String url = getBaseURL(protocol) + path; logger.info("Getting URL: {}", url); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); return s_webClient.getResponseAsString(url, true, creds); }
/** * Hits the given Fedora Server URL and returns the response as a String. * Throws an IOException if the response code is not 200(OK). */ private static String getServerResponse(String protocol, String user, String pass, String path) throws IOException { String url = getBaseURL(protocol) + path; logger.info("Getting URL: {}", url); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); return s_webClient.getResponseAsString(url, true, creds); }
public String getResponseAsString(String url, boolean failIfNotOK, UsernamePasswordCredentials creds) throws IOException { InputStream in = get(url, failIfNotOK, creds); // Convert the response into a String. try { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuffer buffer = new StringBuffer(); String line = reader.readLine(); while (line != null) { buffer.append(line + "\n"); line = reader.readLine(); } return buffer.toString(); } finally { try { in.close(); } catch (Exception e) { logger.error("Can't close InputStream: " + e.getMessage()); } } }
public String getResponseAsString(String url, boolean failIfNotOK, UsernamePasswordCredentials creds) throws IOException { InputStream in = get(url, failIfNotOK, creds); // Convert the response into a String. try { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); StringBuffer buffer = new StringBuffer(); String line = reader.readLine(); while (line != null) { buffer.append(line + "\n"); line = reader.readLine(); } return buffer.toString(); } finally { try { in.close(); } catch (Exception e) { logger.error("Can't close InputStream: " + e.getMessage()); } } }