List of usage examples for java.io IOException getCause
public synchronized Throwable getCause()
From source file:org.openhab.tools.analysis.utils.CachingHttpClientTest.java
@Test public void testMultipleUnsuccessfulRequests() throws Exception { // Unique URL is needed for each test as once the URL is used it will be cached URL unreachableURL = getUniqueURL(PATH_TO_MISSING_RESOURCE); // First request throws exception, because a get request is sent try {//from w w w . j a va 2 s .co m testClient.get(unreachableURL); } catch (IOException e) { assertThat(e, instanceOf(IOException.class)); assertThat(e.getMessage(), equalTo("Unable to get " + unreachableURL.toString())); assertThat(e.getCause(), instanceOf(FileNotFoundException.class)); } // Next requests do not throw exception assertNull(testClient.get(unreachableURL)); assertNull(testClient.get(unreachableURL)); verify(server.getHandler(), times(1)).handle(any(), any(), any(), any()); }
From source file:com.starit.diamond.server.controller.AdminController.java
/** * ??/*from ww w. j a v a 2s .co m*/ * * @param request * @param dataId * @param group * @param content * @param modelMap * @return */ @RequestMapping(value = "/postConfig", method = RequestMethod.POST) public String postConfig(HttpServletRequest request, HttpServletResponse response, @RequestParam("dataId") String dataId, @RequestParam("group") String group, @RequestParam("description") String description, @RequestParam("content") String content, ModelMap modelMap) { response.setCharacterEncoding("GBK"); boolean checkSuccess = true; String errorMessage = "?"; if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) { checkSuccess = false; errorMessage = "DataId"; } if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim())) { checkSuccess = false; errorMessage = ""; } if (!StringUtils.hasLength(content)) { checkSuccess = false; errorMessage = ""; } if (!checkSuccess) { modelMap.addAttribute("message", errorMessage); try { response.sendError(FORBIDDEN_403, errorMessage); } catch (IOException ioe) { log.error(ioe.getMessage(), ioe.getCause()); } return "/admin/confignew"; } String userName = (String) request.getSession().getAttribute("user"); this.configService.addConfigInfo(dataId, group, userName, content, description); request.getSession().setAttribute("message", "???!"); return "redirect:" + listConfig(request, response, null, null, 1, 10, modelMap); }
From source file:com.relicum.ipsum.Locale.PropertyManager.java
/** * Read properties to the specified string name of the file. * * @throws IOException the {@link java.io.IOException} if their was a problem reading from the file. *//* w w w.ja v a2 s .co m*/ public void readFromFile() throws IOException { try { this.readFromFile(file); } catch (IOException e) { log.log(Level.SEVERE, e.getMessage(), e.getCause()); throw e; } }
From source file:com.baidu.qa.service.test.parser.CaseFolderParserImpl.java
/** * ?suitecase/*from w ww . j av a 2 s . c o m*/ * @param casepath case * @return ?case? * @throws Exception */ private CaseData parsecase(String casepath) throws Exception { CaseData casedata = new CaseData(); File caseinfo = new File(casepath + Constant.FILENAME_CASEINFO); File input = new File(casepath + Constant.FILENAME_INPUT); // ?case? InputStream in_caseinfo = new BufferedInputStream( new FileInputStream(casepath + Constant.FILENAME_CASEINFO)); Properties Info_caseinfo = new Properties(); try { Info_caseinfo.load(in_caseinfo); casedata.setCaseid(Info_caseinfo.getProperty("caseid")); casedata.setDesc(Info_caseinfo.getProperty("desc")); casedata.setAction(Info_caseinfo.getProperty("action")); casedata.setStatus(Info_caseinfo.getProperty("status")); if (Info_caseinfo.containsKey("requesttype")) { casedata.setRequesttype(Info_caseinfo.getProperty("requesttype")); } //?var? if (Info_caseinfo.containsKey("var") && Info_caseinfo.getProperty("var").trim().length() != 0) { casedata.setHasVar(true); } in_caseinfo.close(); // ?case??vargen?? casedata.setVarGen(VariableGenerator.getGenerator(casepath + Constant.FILENAME_CASEINFO)); casedata = parseCaseinfo(casedata, casepath); return casedata; } catch (IOException e) { throw new RuntimeException("parse case folder error", e.getCause()); } }
From source file:com.relicum.ipsum.Locale.PropertyManager.java
/** * Check file the existents of a file and creates it if it is not found; * * @param file the file/*from w ww . ja v a 2 s .co m*/ * @return the file * @throws IOException the iO exception */ @SuppressWarnings("ResultOfMethodCallIgnored") private File checkFile(String file) throws IOException { log.info("The path tried is " + file); File tmp = new File(file); try { tmp.createNewFile(); } catch (IOException e) { log.log(Level.SEVERE, e.getMessage(), e.getCause()); throw e; } return tmp; }
From source file:com.relicum.ipsum.Locale.PropertyManager.java
/** * Read properties to the specified string name of the file. * * @param file the {@link String } name of the file to read the properties from. * @throws IOException the {@link java.io.IOException} if the file was not found or there were problems reading from it. *///from w w w. java 2 s .c o m public void readFromFile(String file) throws IOException { try { reader = new FileReader(checkFile(file)); properties.load(reader); } catch (IOException e) { log.log(Level.SEVERE, e.getMessage(), e.getCause()); throw e; } finally { if (reader != null) reader.close(); } }
From source file:com.relicum.ipsum.Locale.PropertyManager.java
/** * Write properties to the specified string name of the file. * <p>If the file doesn't exist it will attempt to create it for you. * * @param file the {@link String } name of the file to store the properties under. * @throws IOException the {@link java.io.IOException} if their was a problem writing to the file. */// ww w . j av a 2s. c o m public void writeToFile(String file) throws IOException { try { writer = new FileWriter(checkFile(file)); properties.store(writer, "Plugin Messages"); } catch (IOException e) { log.log(Level.SEVERE, e.getMessage(), e.getCause()); throw e; } finally { if (writer != null) { writer.flush(); writer.close(); } } }
From source file:org.immutables.gson.stream.GsonMessageBodyProvider.java
@Override public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { try {/*from w w w . j a v a 2 s . c om*/ return streamer.read(gson, genericType, entityStream); } catch (IOException ex) { // Experimental if (ex.getCause() instanceof RuntimeException) { String json = gson.toJson(new Error(ex.getCause().getMessage())); throw new WebApplicationException(Response.status(400).type(mediaType).entity(json).build()); } throw ex; } }
From source file:monasca.common.middleware.HttpAuthClient.java
private HttpResponse sendPost(HttpPost httpPost) throws ClientProtocolException { HttpResponse response;//from w w w . j ava2s. co m try { response = client.execute(httpPost); int code = response.getStatusLine().getStatusCode(); if (!(code == 201 || code == 200 || code == 203)) { adminToken = null; throw new AdminAuthException("Failed to authenticate admin credentials " + code + response.getStatusLine().getReasonPhrase()); } } catch (IOException e) { final String message; if ((e.getMessage() == null) && (e.getCause() != null)) { message = e.getCause().getMessage(); } else { message = e.getMessage(); } logger.error("Failure authenticating adminUser: {}", message); httpPost.abort(); throw new AdminAuthException("Failure authenticating adminUser :" + message, e); } return response; }
From source file:com.alibaba.jstorm.utils.JStormUtils.java
/** * @param command// ww w .ja va2s . c o m * @param environment * @param backend * @return * @throws IOException * @@@ it should use DefaultExecutor to start a process, but some little problem have been found, such as exitCode/output string so still use the old method * to start process */ public static Process launch_process(final String command, final Map<String, String> environment, boolean backend) throws IOException { if (backend == true) { new Thread(new Runnable() { @Override public void run() { String[] cmdlist = (new String("nohup " + command + " &")).split(" "); try { launchProcess(cmdlist, environment); } catch (IOException e) { LOG.error("Failed to run " + command + ":" + e.getCause(), e); } } }).start(); return null; } else { String[] cmdlist = command.split(" "); return launchProcess(cmdlist, environment); } }