List of usage examples for java.lang IllegalStateException getMessage
public String getMessage()
From source file:org.eclipse.gyrex.jobs.internal.commands.LsCmd.java
private String getActiveNodeId(final String storageId) { try {/* ww w. j a v a2 s . c o m*/ return JobHungDetectionHelper.getProcessingNodeId(storageId, null); } catch (final IllegalStateException e) { return String.format("[%s]", e.getMessage()); } }
From source file:org.exist.webstart.JnlpWriter.java
void sendImage(JnlpHelper jh, JnlpJarFiles jf, String filename, HttpServletResponse response) throws IOException { logger.debug("Send image " + filename); String type = null;/* w ww . j a v a2 s . c o m*/ if (filename.endsWith(".gif")) { type = "image/gif"; } else if (filename.endsWith(".png")) { type = "image/png"; } else { type = "image/jpeg"; } final InputStream is = this.getClass().getResourceAsStream("resources/" + filename); if (is == null) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Image file '" + filename + "' not found."); return; } // Copy data final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(is, baos); IOUtils.closeQuietly(is); // It is very improbable that a 64 bit jar is needed, but // it is better to be ready response.setContentType(type); response.setContentLength(baos.size()); //response.setHeader("Content-Length", ""+baos.size()); final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); final ServletOutputStream os = response.getOutputStream(); try { IOUtils.copy(bais, os); } catch (final IllegalStateException ex) { logger.debug(ex.getMessage()); } catch (final IOException ex) { logger.debug("Ignored IOException for '" + filename + "' " + ex.getMessage()); } // Release resources os.flush(); os.close(); bais.close(); }
From source file:org.exist.webstart.JnlpWriter.java
/** * Send JAR or JAR.PACK.GZ file to end user. * * @param filename Name of JAR file/*from ww w . j a v a 2 s.c o m*/ * @param response Object for writing to end user. * @throws java.io.IOException */ void sendJar(JnlpJarFiles jnlpFiles, String filename, HttpServletRequest request, HttpServletResponse response) throws IOException { logger.debug("Send jar file " + filename); final File localFile = jnlpFiles.getJarFile(filename); if (localFile == null || !localFile.exists()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Jar file '" + filename + "' not found."); return; } logger.debug("Actual file " + localFile.getAbsolutePath()); if (localFile.getName().endsWith(".jar")) { //response.setHeader(CONTENT_ENCODING, JAR_MIME_TYPE); response.setContentType(JAR_MIME_TYPE); } else if (localFile.getName().endsWith(".jar.pack.gz")) { response.setHeader(CONTENT_ENCODING, PACK200_GZIP_ENCODING); response.setContentType(PACK_MIME_TYPE); } // It is very improbable that a 64 bit jar is needed, but // it is better to be ready // response.setContentLength(Integer.parseInt(Long.toString(localFile.length()))); response.setHeader("Content-Length", Long.toString(localFile.length())); response.setDateHeader("Last-Modified", localFile.lastModified()); final FileInputStream fis = new FileInputStream(localFile); final ServletOutputStream os = response.getOutputStream(); try { // Transfer bytes from in to out final byte[] buf = new byte[4096]; int len; while ((len = fis.read(buf)) > 0) { os.write(buf, 0, len); } } catch (final IllegalStateException ex) { logger.debug(ex.getMessage()); } catch (final IOException ex) { logger.debug("Ignore IOException for '" + filename + "'"); } os.flush(); os.close(); fis.close(); }
From source file:org.apache.maven.dotnet.PackMojo.java
/** * Manage dotnet.pack.files property/* ww w . ja v a 2 s.c o m*/ * * Pattern example : <dotnet.pack.files> * files=${basedir}\/..\/**\/*.idl to-dir=idl/database * files=**\/changes.xml to-dir=xml * files=..\/..\/**\/*.xml to-dir=xml * </dotnet.pack.files> */ private void doPackFiles(ZipArchiver zipPack) throws IOException, MojoExecutionException { BufferedReader br = new BufferedReader(new StringReader(packFiles)); String line; while ((line = br.readLine()) != null) { line = line.trim().replace('\t', ' ').replace(WINDOWS_FILE_SEP, File.separator).replace(UNIX_FILE_SEP, File.separator); while (!StringUtils.isEmpty(line)) { line = " " + line + " "; int filesPos = line.indexOf(PACK_FILES_ATTR); if (filesPos >= 0) { int toDirPos = line.indexOf(PACK_TO_DIR_ATTR); if (toDirPos < 0) { throw new MojoExecutionException("could not find " + PACK_TO_DIR_ATTR); } getLog().info("parsing " + line); int endFilesPos = line.indexOf(" ", filesPos + PACK_FILES_ATTR.length()); int endToDirPos = line.indexOf(" ", toDirPos + PACK_TO_DIR_ATTR.length()); String source = line.substring(filesPos + PACK_FILES_ATTR.length(), endFilesPos); if (source.length() == 0) { throw new MojoExecutionException("bad copy source " + PACK_FILES_ATTR); } String targetDir = line.substring(toDirPos + PACK_TO_DIR_ATTR.length(), endToDirPos); if (targetDir.length() == 0) { throw new MojoExecutionException("bad copy target " + PACK_FILES_ATTR); } String basedir = ".", includePattern = ""; int starPos = source.indexOf('*'); if (starPos < 0) { starPos = source.length() - 1; } int lastSlashPos = source.lastIndexOf(File.separator, starPos); if (lastSlashPos > 0) { basedir = source.substring(0, lastSlashPos); includePattern = source.substring(lastSlashPos + 1); } else if (lastSlashPos == 0) { basedir = File.separator; includePattern = source.substring(lastSlashPos + 1); } else { includePattern = source; } CopyFileCollector copyCollector = new CopyFileCollector(zipPack, targetDir); DirectoryWalker dw = new DirectoryWalker(); dw.setBaseDir(new File(basedir)); dw.addInclude(includePattern); dw.addDirectoryWalkListener(copyCollector); try { dw.scan(); } catch (IllegalStateException e) { throw new MojoExecutionException(basedir + " : " + e.getMessage(), e); } line = line.substring(endToDirPos); } else { break; } } } }
From source file:com.rubika.aotalk.market.Market.java
@Override protected void onStart() { super.onStart(); try {//from w ww .j ava 2s .c om EasyTracker.getInstance().activityStart(this); } catch (IllegalStateException e) { Logging.log(APP_TAG, e.getMessage()); } }
From source file:com.rubika.aotalk.market.Market.java
@Override protected void onStop() { super.onStop(); try {//w w w . ja v a 2s. c o m EasyTracker.getInstance().activityStop(this); } catch (IllegalStateException e) { Logging.log(APP_TAG, e.getMessage()); } }
From source file:org.cloudfoundry.tools.timeout.HotSwappingTimeoutProtectionStrategyTest.java
@Test public void shouldHandleInterruptedWatingForAfterRequest() throws Exception { given(this.requestCoordinator.isPollResponseConsumed()).willReturn(true); willThrow(new InterruptedException()).given(this.requestCoordinator).awaitFinish(FAIL_TIMEOUT); try {/*from www . ja v a 2s. com*/ this.strategy.handlePoll(this.request, this.response); fail("Did not throw"); } catch (IllegalStateException e) { // Expected assertThat(e.getMessage(), is("Timeout waiting for cleanup")); } verify(this.requestCoordinators).delete(this.request); }
From source file:immf.growl.GrowlApiClient.java
private GrowlApiResult analyzeResponse(HttpResponse res) { GrowlApiResult result = GrowlApiResult.ERROR; if (res == null) { GrowlNotifier.log.info("HttpResponse is null"); this.incrementInternalServerErrorCount(); return GrowlApiResult.ERROR; } else {//w ww. j av a 2 s . com decrementCallsRemaining(); int status = res.getStatusLine().getStatusCode(); switch (status) { case 200: log.info("Api call is success."); result = GrowlApiResult.SUCCESS; break; case 400: log.error("The data supplied is in the wrong format, invalid length or null."); result = GrowlApiResult.INVALID; break; case 401: log.error("The 'apikey' provided is not valid."); result = GrowlApiResult.INVALID; break; case 402: case 406: log.error("Maximum number of API calls exceeded."); result = GrowlApiResult.EXCEEDED; break; case 500: log.error("Internal server error."); this.incrementInternalServerErrorCount(); result = GrowlApiResult.ERROR; break; default: ; } if (status == 200 || status == 402 || status == 406) { HttpEntity entity = res.getEntity(); try { final InputStream in = entity.getContent(); final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); final Document resDoc = builder.parse(in); // ?? Element rootNode = resDoc.getDocumentElement(); if (rootNode != null && this.topLevelTag.equals(rootNode.getNodeName())) { NodeList rootChildren = rootNode.getChildNodes(); for (int i = 0, max = rootChildren.getLength(); i < max; i++) { Node node = rootChildren.item(i); if (TAG_ERROR.equals(node.getNodeName()) || TAG_SUCCESS.equals(node.getNodeName())) { NamedNodeMap attrs = node.getAttributes(); if (attrs != null) { Node attrNode = attrs.getNamedItem(ATTR_RESETTIMER); if (attrNode != null && attrNode.getNodeValue().length() > 0) { setResetTimer(Integer.parseInt(attrNode.getNodeValue())); } attrNode = attrs.getNamedItem(ATTR_RESETDATE); if (attrNode != null && attrNode.getNodeValue().length() > 0) { setResetDate(Integer.parseInt(attrNode.getNodeValue())); } attrNode = attrs.getNamedItem(ATTR_REMAINING); if (attrNode != null && attrNode.getNodeValue().length() > 0) { int remaining = Integer.parseInt(attrNode.getNodeValue()); setCallsRemaining(remaining); } } } } } } catch (IllegalStateException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } catch (ParserConfigurationException e) { log.error(e.getMessage()); } catch (SAXException e) { log.error(e.getMessage()); } } return result; } }
From source file:com.impetus.ankush.common.utils.UploadHandler.java
/** * Upload file./*from w w w. j a v a 2s .c o m*/ * * @return the string */ public String uploadFile() { if (multipartFile == null) { throw new ControllerException(HttpStatus.BAD_REQUEST, HttpStatus.BAD_REQUEST.toString(), "No payload with name \"file\" found in the request "); } // file path to upload. String realFilePath = null; try { // getting original file name. String originalFileName = multipartFile.getOriginalFilename(); // making real file path. realFilePath = this.getUploadFolderPath() + originalFileName; // destination file. File dest = new File(realFilePath); multipartFile.transferTo(dest); } catch (IllegalStateException e) { throw new ControllerException(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage()); } catch (IOException e) { throw new ControllerException(HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage()); } return realFilePath; }
From source file:com.github.horrorho.inflatabledonkey.cloud.Donkey.java
public void apply(HttpClient httpClient, Optional<ForkJoinPool> aux, Set<Asset> assets, FileAssembler consumer) {/*from ww w . ja v a 2 s . co m*/ logger.trace("<< apply() - assets: {}", assets.size()); if (assets.isEmpty()) { return; } if (logger.isDebugEnabled()) { int bytes = assets.stream().mapToInt(u -> u.size().map(Long::intValue).orElse(0)).sum(); logger.debug("-- apply() - assets total: {} size (bytes): {}", assets.size(), bytes); } AssetPool pool = new AssetPool(assets); while (true) { try { if (assets.size() > fragmentationThreshold && aux.isPresent()) { processConcurrent(httpClient, aux.get(), pool, consumer); } else { process(httpClient, pool, consumer); } break; } catch (IllegalStateException ex) { // Our StorageHostChunkLists have expired. // TOFIX potentially unsafe. Use a more specific exception. logger.debug("-- apply() - IllegalStateException: {}", ex.getMessage()); } catch (IllegalArgumentException | IOException ex) { logger.warn("-- apply() - {} {}", ex.getClass().getCanonicalName(), ex.getMessage()); break; } } logger.trace(">> apply() - pool empty: {}", pool.isEmpty()); }