List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:org.dataone.proto.trove.mn.http.client.DataHttpClientHandler.java
public static synchronized String executePost(HttpClient httpclient, HttpPost httpPost) throws ServiceFailure, NotFound, InvalidToken, NotAuthorized, IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidCredentials, InvalidRequest, AuthenticationTimeout, UnsupportedMetadataType, HttpException { String response = null;//from w w w .j a v a2s. c o m try { HttpResponse httpResponse = httpclient.execute(httpPost); if (httpResponse.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_OK) { HttpEntity resEntity = httpResponse.getEntity(); if (resEntity != null) { logger.debug("Response content length: " + resEntity.getContentLength()); logger.debug("Chunked?: " + resEntity.isChunked()); BufferedInputStream in = new BufferedInputStream(resEntity.getContent()); ByteArrayOutputStream resOutputStream = new ByteArrayOutputStream(); byte[] buff = new byte[32 * 1024]; int len; while ((len = in.read(buff)) > 0) { resOutputStream.write(buff, 0, len); } response = new String(resOutputStream.toByteArray()); logger.debug(response); resOutputStream.close(); in.close(); } } else { HttpExceptionHandler.deserializeAndThrowException(httpResponse); } } catch (IOException ex) { throw new ServiceFailure("1002", ex.getMessage()); } return response; }
From source file:eionet.gdem.utils.HttpUtils.java
/** * Method checks whether the resource behind the given URL exist. The method calls HEAD request and if the resonse code is 200, * then returns true. If exception is thrown or response code is something else, then the result is false. * * @param url URL// w w w . j a v a2 s . c o m * @return True if resource behind the url exists. */ public static boolean urlExists(String url) { CloseableHttpClient client = HttpClients.createDefault(); // Create a method instance. HttpHead method = new HttpHead(url); CloseableHttpResponse response = null; try { // Execute the method. response = client.execute(method); int statusCode = response.getStatusLine().getStatusCode(); return statusCode == HttpStatus.SC_OK; /*} catch (HttpException e) { LOGGER.error("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); return false;*/ } catch (IOException e) { LOGGER.error("Fatal transport error: " + e.getMessage()); e.printStackTrace(); return false; } finally { // Release the connection. method.releaseConnection(); try { response.close(); } catch (IOException e) { // do nothing } } }
From source file:eu.optimis.ip.gui.client.resources.ConfigManager.java
private static void createDefaultConfigFile(File fileObject) throws Exception { log.debug("File " + fileObject.getAbsolutePath() + " didn't exist. Creating one with default values..."); //Create parent directories. log.debug("Creating parent directories."); new File(fileObject.getParent()).mkdirs(); //Create an empty file to copy the contents of the default file. log.debug("Creating empty file."); new File(fileObject.getAbsolutePath()).createNewFile(); //Copy file./* ww w .ja v a 2 s .c o m*/ log.debug("Copying file " + fileObject.getName()); InputStream streamIn = ConfigManager.class.getResourceAsStream("/" + fileObject.getName()); FileOutputStream streamOut = new FileOutputStream(fileObject.getAbsolutePath()); byte[] buf = new byte[8192]; while (true) { int length = streamIn.read(buf); if (length < 0) { break; } streamOut.write(buf, 0, length); } //Close streams after copying. try { streamIn.close(); } catch (IOException ex) { log.error("Couldn't close input stream"); log.error(ex.getMessage()); } try { streamOut.close(); } catch (IOException ex) { log.error("Couldn't close file output stream"); log.error(ex.getMessage()); } }
From source file:gov.nih.nci.caintegrator.application.lists.UserListGenerator.java
public static List<String> generateList(File file) { List<String> tempList = new ArrayList<String>(); if (file != null && (file.getName().endsWith(".txt") || file.getName().endsWith(".TXT"))) { try {/*from w w w. j ava2 s.co m*/ BufferedReader in = new BufferedReader(new FileReader(file)); String inputLine = null; do { inputLine = in.readLine(); if (inputLine != null) { if (isAscii(inputLine)) { // make sure all data is ASCII tempList.add(inputLine); } } else { System.out.println("null line"); while (tempList.contains("")) { tempList.remove(""); } in.close(); break; } } while (true); } catch (EOFException eof) { logger.error("Errors when reading empty lines in file:" + eof.getMessage()); } catch (IOException ex) { logger.error("Errors when uploading file:" + ex.getMessage()); } } return tempList; }
From source file:com.sonyericsson.hudson.plugins.gerrit.trigger.utils.GerritPluginChecker.java
/** * Query Gerrit to determine if plugin is enabled. * @param config Gerrit Server Config/*w w w . java2 s .c o m*/ * @param pluginName The Gerrit Plugin name. * @return true if enabled. */ public static boolean isPluginEnabled(IGerritHudsonTriggerConfig config, String pluginName) { String restUrl = buildURL(config); if (restUrl == null) { logger.warn(Messages.PluginInstalledRESTApiNull(pluginName)); return false; } logger.trace("{}plugins/{}/", restUrl, pluginName); HttpResponse execute = null; try { execute = HttpUtils.performHTTPGet(config, restUrl + "plugins/" + pluginName + "/"); } catch (IOException e) { logger.warn(Messages.PluginHttpConnectionGeneralError(pluginName, e.getMessage()), e); return false; } int statusCode = execute.getStatusLine().getStatusCode(); logger.debug("status code: {}", statusCode); return decodeStatus(statusCode, pluginName); }
From source file:au.csiro.casda.sodalint.SodaLinter.java
private static String getSodaLintVersion() { Properties props = new Properties(); try {//ww w . j ava 2 s . c o m InputStream resourceAsStream = SodaLinter.class.getResourceAsStream("/version.properties"); if (resourceAsStream != null) { props.load(resourceAsStream); } } catch (IOException e) { System.out.println("Unable to load version.properties: " + e.getMessage()); } String version = props.getProperty("build.number"); return version == null ? "" : version; }
From source file:net.emotivecloud.scheduler.drp4one.ConfigManager.java
private static void createDefaultConfigFile(File fileObject) throws Exception { log.debug("File " + fileObject.getAbsolutePath() + " didn't exist. Creating one with default values..."); System.out.println(// ww w .ja v a2s . com "File " + fileObject.getAbsolutePath() + " didn't exist. Creating one with default values..."); //Create parent directories. log.debug("Creating parent directories."); new File(fileObject.getParent()).mkdirs(); //Create an empty file to copy the contents of the default file. log.debug("Creating empty file."); new File(fileObject.getAbsolutePath()).createNewFile(); //Copy file. log.debug("Copying file " + fileObject.getName()); InputStream streamIn = ConfigManager.class.getResourceAsStream("/" + fileObject.getName()); FileOutputStream streamOut = new FileOutputStream(fileObject.getAbsolutePath()); byte[] buf = new byte[8192]; while (true) { int length = streamIn.read(buf); if (length < 0) { break; } streamOut.write(buf, 0, length); } //Close streams after copying. try { streamIn.close(); } catch (IOException ex) { log.error("Couldn't close input stream"); log.error(ex.getMessage()); } try { streamOut.close(); } catch (IOException ex) { log.error("Couldn't close file output stream"); log.error(ex.getMessage()); } }
From source file:com.streamreduce.util.MessageUtils.java
public static String readJSONFromClasspath(String resource) { InputStream inputStream = MessageUtils.class.getResourceAsStream(resource); StringWriter writer = new StringWriter(); try {/* w w w. java2 s .c om*/ IOUtils.copy(inputStream, writer, "UTF-8"); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return writer.toString(); }
From source file:net.lldp.checksims.ChecksimsRunner.java
/** * Get current version./*from ww w . ja va 2 s .com*/ * * @return Current version of Checksims */ public static String getChecksimsVersion() throws ChecksimsException { InputStream resource = ChecksimsCommandLine.class.getResourceAsStream("version.txt"); if (resource == null) { throw new ChecksimsException("Error obtaining resource for version!"); } try { return IOUtils.toString(resource); } catch (IOException e) { throw new ChecksimsException("IO Exception reading version: " + e.getMessage(), e); } }
From source file:password.pwm.ws.client.rest.RestClientHelper.java
public static String makeOutboundRestWSCall(final PwmApplication pwmApplication, final Locale locale, final String url, final String jsonRequestBody) throws PwmOperationalException, PwmUnrecoverableException { final HttpPost httpPost = new HttpPost(url); httpPost.setHeader("Accept", PwmConstants.AcceptValue.json.getHeaderValue()); if (locale != null) { httpPost.setHeader("Accept-Locale", locale.toString()); }//from ww w.j a v a 2s . c o m httpPost.setHeader("Content-Type", PwmConstants.ContentTypeValue.json.getHeaderValue()); final HttpResponse httpResponse; try { final StringEntity stringEntity = new StringEntity(jsonRequestBody); stringEntity.setContentType(PwmConstants.AcceptValue.json.getHeaderValue()); httpPost.setEntity(stringEntity); LOGGER.debug("beginning external rest call to: " + httpPost.toString() + ", body: " + jsonRequestBody); httpResponse = PwmHttpClient.getHttpClient(pwmApplication.getConfig()).execute(httpPost); final String responseBody = EntityUtils.toString(httpResponse.getEntity()); LOGGER.trace("external rest call returned: " + httpResponse.getStatusLine().toString() + ", body: " + responseBody); if (httpResponse.getStatusLine().getStatusCode() != 200) { final String errorMsg = "received non-200 response code (" + httpResponse.getStatusLine().getStatusCode() + ") when executing web-service"; LOGGER.error(errorMsg); throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg)); } return responseBody; } catch (IOException e) { final String errorMsg = "http response error while executing external rest call, error: " + e.getMessage(); LOGGER.error(errorMsg); throw new PwmOperationalException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg), e); } }