List of usage examples for java.lang IllegalArgumentException getMessage
public String getMessage()
From source file:com.marklogic.contentpump.CompressedRDFReader.java
@Override protected void initStream(InputSplit inSplit) throws IOException, InterruptedException { setFile(((FileSplit) inSplit).getPath()); FSDataInputStream fileIn = fs.open(file); URI zipURI = file.toUri();/*from w ww . j a va2 s. co m*/ String codecString = conf.get(ConfigConstants.CONF_INPUT_COMPRESSION_CODEC, CompressionCodec.ZIP.toString()); if (codecString.equalsIgnoreCase(CompressionCodec.ZIP.toString())) { zipIn = new ZipInputStream(fileIn); codec = CompressionCodec.ZIP; while (true) { try { currZipEntry = ((ZipInputStream) zipIn).getNextEntry(); if (currZipEntry == null) { break; } if (currZipEntry.getSize() != 0) { subId = currZipEntry.getName(); break; } } catch (IllegalArgumentException e) { LOG.warn("Skipped a zip entry in : " + file.toUri() + ", reason: " + e.getMessage()); } } if (currZipEntry == null) { // no entry in zip LOG.warn("No valid entry in zip:" + file.toUri()); return; } ByteArrayOutputStream baos; long size = currZipEntry.getSize(); if (size == -1) { baos = new ByteArrayOutputStream(); // if we don't know the size, assume it's big! initParser(zipURI.toASCIIString() + "/" + subId, INMEMORYTHRESHOLD); } else { baos = new ByteArrayOutputStream((int) size); initParser(zipURI.toASCIIString() + "/" + subId, size); } int nb; while ((nb = zipIn.read(buf, 0, buf.length)) != -1) { baos.write(buf, 0, nb); } parse(subId, new ByteArrayInputStream(baos.toByteArray())); } else if (codecString.equalsIgnoreCase(CompressionCodec.GZIP.toString())) { long size = inSplit.getLength(); zipIn = new GZIPInputStream(fileIn); codec = CompressionCodec.GZIP; initParser(zipURI.toASCIIString(), size * COMPRESSIONFACTOR); parse(file.getName(), zipIn); } else { throw new UnsupportedOperationException("Unsupported codec: " + codec.name()); } }
From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java
protected void upload(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from ww w . j a va2s . c om*/ if (!ServletFileUpload.isMultipartContent(request)) { response.sendError(response.SC_BAD_REQUEST); return; } String media = null, type = null; FileItemFactory fiF = new DiskFileItemFactory(); ServletFileUpload sfU = new ServletFileUpload(fiF); List<FileItem> fileItems = new LinkedList<FileItem>(); Iterator i = sfU.parseRequest(request).iterator(); while (i.hasNext()) { FileItem item = (FileItem) i.next(); if (item.isFormField()) { if (item.getFieldName().equals("media")) media = item.getString(); else if (item.getFieldName().equals("type")) type = item.getString(); } else if (item.getName().matches(zipExtRegex)) { processZipFileItem(fiF, item, fileItems); } else if (uploadFileNameFilter.accept(null, item.getName())) { fileItems.add(item); } } if (fileItems.size() == 0) { setTextResponse(response, response.SC_BAD_REQUEST, "No files provided to upload"); return; } processFileItemList(fileItems, media, type); int len = fileItems.size(); setTextResponse(response, response.SC_OK, "Successfully uploaded " + len + " file" + (len > 1 ? "s" : "")); } catch (FileNotFoundException fnfE) { setTextResponse(response, response.SC_NOT_FOUND, fnfE.getMessage()); } catch (IllegalArgumentException iaE) { setTextResponse(response, response.SC_BAD_REQUEST, iaE.getMessage()); } catch (FileUploadException fuE) { setTextResponse(response, response.SC_INTERNAL_SERVER_ERROR, fuE.getMessage()); } }
From source file:com.marklogic.contentpump.SplitDelimitedTextReader.java
@Override protected void initParser(InputSplit inSplit) throws IOException, InterruptedException { setFile(((DelimitedSplit) inSplit).getPath()); configFileNameAsCollection(conf, file); // get header from the DelimitedSplit TextArrayWritable taw = ((DelimitedSplit) inSplit).getHeader(); fields = taw.toStrings();/* w w w. jav a 2s . c o m*/ try { docBuilder.configFields(conf, fields); } catch (IllegalArgumentException e) { LOG.error("Skipped file: " + file.toUri() + ", reason: " + e.getMessage()); return; } fileIn = fs.open(file); lineSeparator = retrieveLineSeparator(fileIn); if (start != 0) { // in case the cut point is \n, back off 1 char to create a partial // line so that 1st line can be skipped start--; } fileIn.seek(start); instream = new InputStreamReader(fileIn, encoding); bytesRead = 0; fileLen = inSplit.getLength(); if (uriName == null) { generateId = conf.getBoolean(CONF_INPUT_GENERATE_URI, false); if (generateId) { idGen = new IdGenerator(file.toUri().getPath() + "-" + ((FileSplit) inSplit).getStart()); } else { uriId = 0; } } boolean found = generateId || uriId == 0; for (int i = 0; i < fields.length && !found; i++) { if (fields[i].equals(uriName)) { uriId = i; found = true; break; } } if (found == false) { // idname doesn't match any columns LOG.error("Skipped file: " + file.toUri() + ", reason: " + URI_ID + " " + uriName + " is not found"); return; } // keep leading and trailing whitespaces to ensure accuracy of pos // do not skip empty line just in case the split boundary is \n parser = new CSVParser(instream, CSVParserFormatter.getFormat(delimiter, encapsulator, false, false)); parserIterator = parser.iterator(); // skip first line: // 1st split, skip header; other splits, skip partial line if (parserIterator.hasNext()) { String[] values = getLine(); start += getBytesCountFromLine(values); pos = start; } }
From source file:com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolderTest.java
@Test public void testAstWithoutChildren() { SuppressWarningsHolder holder = new SuppressWarningsHolder(); DetailAST methodDef = new DetailAST(); methodDef.setType(TokenTypes.METHOD_DEF); try {/* ww w . ja v a2s . co m*/ holder.visitToken(methodDef); fail("Exception expected"); } catch (IllegalArgumentException ex) { assertEquals("Identifier AST expected, but get null.", ex.getMessage()); } }
From source file:io.blitz.bamboo.CurlTaskConfigurator.java
/** * Used for the task form field validation. * @param params/* w w w. jav a2 s. c o m*/ * @param errorCollection */ @Override public void validate(@NotNull final ActionParametersMap params, @NotNull final ErrorCollection errorCollection) { super.validate(params, errorCollection); //validates the curl command line using the blitz-java curl parser final String command = params.getString(COMMAND); try { Curl.parse(null, null, command); } catch (IllegalArgumentException e) { String message = textProvider.getText("io.blitz.command.error", "Error parsing command"); errorCollection.addError(COMMAND, message + ": " + e.getMessage()); } //validates username required final String username = params.getString(USERNAME); if (StringUtils.isEmpty(username)) { String message = textProvider.getText("io.blitz.username.error", "Username is required"); errorCollection.addError(USERNAME, message); } //validates api-key required final String apiKey = params.getString(API_KEY); if (StringUtils.isEmpty(apiKey)) { String message = textProvider.getText("io.blitz.apiKey.error", "API-Key is required"); errorCollection.addError(API_KEY, message); } //validates percentage between 0 and 100 final String percentage = params.getString(PERCENTAGE); Double percent = null; try { percent = Double.parseDouble(percentage); } catch (NumberFormatException e) { } if (percent == null || percent < 0.0 || percent > 100.0) { String defaultMessage = "Must be a number between 0 and 100"; String message = textProvider.getText("io.blitz.percentage.error", defaultMessage); errorCollection.addError(PERCENTAGE, message); } }
From source file:com.neiljbrown.brighttalk.channels.reportingapi.client.spring.ApiResponseErrorHandlerTest.java
/** * Tests constructor {@link ApiResponseErrorHandler#ApiResponseErrorHandler(java.util.List)} in the error case where * one of the {@link HttpMessageConverter} isn't capable of reading an {@link ApiError} object. *//* w w w . j a v a2 s . c om*/ @Test public void testApiResponseErrorHandlerForUnsupportedConverter() { HttpMessageConverter<?> supportedConverter = new Jaxb2RootElementHttpMessageConverter(); HttpMessageConverter<?> unsupportedConveter = new StringHttpMessageConverter(); try { this.errorHandler = new ApiResponseErrorHandler( Arrays.asList(new HttpMessageConverter<?>[] { supportedConverter, unsupportedConveter })); fail("Expected IllegalArgumentException to be thrown for HttpMessageConverter that doesn't support reading an ApiError."); } catch (IllegalArgumentException e) { assertTrue("Unexpected exception [" + e.toString() + "].", e.getMessage().matches("HttpMessageConverter.*must support reading.*")); } }
From source file:com.sothawo.taboo2.Taboo2Service.java
/** * ExceptionHandler for IllegalArgumentException. returns the exception's error message in the body with the 412 * status code./*from w w w.j ava2s. co m*/ * * @param e * the exception to handle * @return HTTP PRECONDITION_FAILED Response Status and error message */ @ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(HttpStatus.PRECONDITION_FAILED) public final String exceptionHandlerIllegalArgumentException(final IllegalArgumentException e) { return '"' + e.getMessage() + '"'; }
From source file:org.jasig.cas.client.util.CommonUtilsTests.java
public void testAssertNotEmpty() { final String CONST_MESSAGE = "test"; final Collection<Object> c = new ArrayList<Object>(); c.add(new Object()); CommonUtils.assertNotEmpty(c, CONST_MESSAGE); try {/*from w w w .jav a 2 s . c o m*/ CommonUtils.assertNotEmpty(new ArrayList<Object>(), CONST_MESSAGE); } catch (IllegalArgumentException e) { assertEquals(CONST_MESSAGE, e.getMessage()); } try { CommonUtils.assertNotEmpty(null, CONST_MESSAGE); } catch (IllegalArgumentException e) { assertEquals(CONST_MESSAGE, e.getMessage()); } }
From source file:ch.rasc.wampspring.method.InvocableWampHandlerMethod.java
/** * Invoke the handler method with the given argument values. *///from ww w.java 2 s . com protected Object doInvoke(Object... args) throws Exception { ReflectionUtils.makeAccessible(getBridgedMethod()); try { return getBridgedMethod().invoke(getBean(), args); } catch (IllegalArgumentException ex) { assertTargetBean(getBridgedMethod(), getBean(), args); throw new IllegalStateException(getInvocationErrorMessage(ex.getMessage(), args), ex); } catch (InvocationTargetException ex) { // Unwrap for HandlerExceptionResolvers ... Throwable targetException = ex.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } else if (targetException instanceof Error) { throw (Error) targetException; } else if (targetException instanceof Exception) { throw (Exception) targetException; } else { String msg = getInvocationErrorMessage("Failed to invoke controller method", args); throw new IllegalStateException(msg, targetException); } } }
From source file:ext.services.network.TestNetworkUtils.java
/** * Test get connection string proxy invalid url. * //from w w w. j a v a 2s . c o m * * @throws Exception the exception */ public void testGetConnectionStringProxyInvalidURL() throws Exception { // useful content when inet access is allowed Conf.setProperty(Const.CONF_NETWORK_NONE_INTERNET_ACCESS, "false"); try { NetworkUtils.getConnection(FTP_URL, null); fail("Should fail here"); } catch (IllegalArgumentException e) { // make sure the url is part of the error message assertTrue(e.getMessage(), e.getMessage().contains(FTP_URL)); } }