Example usage for java.lang IllegalArgumentException getMessage

List of usage examples for java.lang IllegalArgumentException getMessage

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.iaeste.iws.core.services.ExchangeCSVService.java

public OfferCSVUploadResponse uploadOffers(final Authentication authentication,
        final OfferCSVUploadRequest request) {
    final Map<String, OfferCSVUploadResponse.ProcessingResult> processingResult = new HashMap<>();
    final OfferCSVUploadResponse response = new OfferCSVUploadResponse();
    final Map<String, CSVProcessingErrors> errors = new HashMap<>();

    try (Reader reader = new StringReader(request.getCsv());
            CSVParser parser = getDefaultCsvParser(reader, request.getDelimiter().getDescription())) {
        final Set<String> headers = readHeader(parser);
        final Set<String> expectedHeaders = new HashSet<>(createFirstRow(OfferFields.Type.UPLOAD));
        if (headers.containsAll(expectedHeaders)) {
            for (final CSVRecord record : parser.getRecords()) {
                process(processingResult, errors, authentication, record);
            }/*from ww w .  j av a2 s.co m*/
        } else {
            throw new IWSException(IWSErrors.PROCESSING_FAILURE, "Invalid CSV header");
        }
    } catch (IllegalArgumentException e) {
        throw new IWSException(IWSErrors.PROCESSING_FAILURE, "The header is invalid: " + e.getMessage() + '.',
                e);
    } catch (IOException e) {
        throw new IWSException(IWSErrors.PROCESSING_FAILURE, "CSV upload processing failed", e);
    }

    response.setProcessingResult(processingResult);
    response.setErrors(errors);
    return response;
}

From source file:com.marklogic.contentpump.CompressedAggXMLReader.java

@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
    if (zipIn == null || xmlSR == null) {
        hasNext = false;/*  w w w. j  av  a2s  . c o m*/
        return false;
    }
    try {
        if (codec.equals(CompressionCodec.ZIP)) {
            ZipInputStream zis = (ZipInputStream) zipIn;

            if (xmlSR.hasNext()) {
                hasNext = nextRecordInAggregate();
                if (hasNext) {
                    return true;
                }
            }
            // xmlSR does not hasNext, 
            // if there is next zipEntry, close xmlSR then create a new one
            ByteArrayOutputStream baos;
            while (true) {
                try {
                    currZipEntry = ((ZipInputStream) zipIn).getNextEntry();
                    if (currZipEntry == null) {
                        break;
                    }
                    if (currZipEntry.getSize() == 0) {
                        continue;
                    }
                    subId = currZipEntry.getName();
                    long size = currZipEntry.getSize();
                    if (size == -1) {
                        baos = new ByteArrayOutputStream();
                    } else {
                        baos = new ByteArrayOutputStream((int) size);
                    }
                    int nb;
                    while ((nb = zis.read(buf, 0, buf.length)) != -1) {
                        baos.write(buf, 0, nb);
                    }
                    xmlSR.close();
                    start = 0;
                    end = baos.size();
                    xmlSR = f.createXMLStreamReader(new ByteArrayInputStream(baos.toByteArray()), encoding);
                    nameSpaces.clear();
                    baos.close();
                    return nextRecordInAggregate();
                } catch (IllegalArgumentException e) {
                    LOG.warn("Skipped a zip entry in : " + file.toUri() + ", reason: " + e.getMessage());
                }
            }
            // end of zip
            if (iterator != null && iterator.hasNext()) {
                //close previous zip and streams
                close();
                initStreamReader(iterator.next());
                return nextRecordInAggregate();
            }
            //current split doesn't have more zip
            return false;

        } else if (codec.equals(CompressionCodec.GZIP)) {
            if (nextRecordInAggregate()) {
                return true;
            }
            // move to next gzip file in this split
            if (iterator != null && iterator.hasNext()) {
                // close previous zip and streams
                close();
                initStreamReader(iterator.next());
                return nextRecordInAggregate();
            }
            return false;
        }
    } catch (XMLStreamException e) {
        LOG.error(e.getMessage(), e);
    }
    return true;
}

From source file:de.vandermeer.skb.datatool.commons.DataSet.java

/**
 * Loads a data set from file system, does many consistency checks as well.
 * @param fsl list of files to load data from
 * @param fileExt the file extension used (translated to "." + fileExt + ".json"), empty if none used
 * @return 0 on success, larger than zero on JSON parsing error (number of found errors)
 *///ww  w  .  j  av  a2s . c o m
@SuppressWarnings("unchecked")
public int load(List<FileSource> fsl, String fileExt) {
    int ret = 0;
    String commonPath = this.calcCommonPath(fsl);

    for (FileSource fs : fsl) {
        String keyStart = this.calcKeyStart(fs, commonPath);
        ObjectMapper om = new ObjectMapper();
        om.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
        try {
            List<Map<String, Object>> jsonList = om.readValue(fs.asFile(),
                    new TypeReference<ArrayList<HashMap<String, Object>>>() {
                    });
            for (Map<String, Object> entryMap : jsonList) {
                E entry = this.factory.newInstanceLoaded(keyStart, entryMap);
                if (entry.getKey().contains("#dummy")) {
                    continue;
                }

                String dup = entry.testDuplicate((Collection<DataEntry>) this.entries.values());
                if (this.entries.containsKey(entry.getKey())) {
                    Skb_Console.conError("{}: duplicate key <{}> found in file <{}>",
                            new Object[] { this.cs.getAppName(), entry.getKey(), fs.getAbsoluteName() });
                } else if (dup != null) {
                    Skb_Console.conError("{}: entry already in map: k1 <{}> <> k2 <{}> found in file <{}>",
                            new Object[] { this.cs.getAppName(), dup, entry.getKey(), fs.getAbsoluteName() });
                } else {
                    if (this.excluded == null
                            || (!ArrayUtils.contains(this.excluded, entry.getCompareString()))) {
                        this.entries.put(entry.getKey(), (E) entry);
                    }
                }
            }
            this.files++;
        } catch (IllegalArgumentException iaex) {
            Skb_Console.conError("{}: problem creating entry: <{}> in file <{}>",
                    new Object[] { this.cs.getAppName(), iaex.getMessage(), fs.getAbsoluteName() });
            ret++;
        } catch (URISyntaxException ue) {
            Skb_Console.conError("{}: problem creating a URI for a link: <{}> in file <{}>",
                    new Object[] { this.cs.getAppName(), ue.getMessage(), fs.getAbsoluteName() });
            ret++;
        } catch (NullPointerException npe) {
            npe.printStackTrace();
            ret++;
        } catch (Exception ex) {
            Skb_Console.conError(
                    "reading acronym from JSON failed with exception <{}>, cause <{}> and message <{}> in file <{}>",
                    new Object[] { ex.getClass().getSimpleName(), ex.getCause(), ex.getMessage(),
                            fs.getAbsoluteName() });
            ret++;
        }
    }

    return ret;
}

From source file:com.github.springtestdbunit.DbUnitTestExecutionListenerPrepareTest.java

@Test
public void shouldFailIfDatabaseConnectionOfWrongTypeIsFound() throws Exception {
    addBean("dbUnitDatabaseConnection", new Integer(0));
    ExtendedTestContextManager testContextManager = new ExtendedTestContextManager(NoDbUnitConfiguration.class);
    try {//  w ww. j a v a2s.  c o  m
        testContextManager.prepareTestInstance();
    } catch (IllegalArgumentException ex) {
        assertEquals("Object of class [java.lang.Integer] must be an instance of interface "
                + "org.dbunit.database.IDatabaseConnection", ex.getMessage());
    }
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTPermission.java

@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    try {/*www  .j  a  v  a2  s.c  om*/
        JAXBList<ObjectPermission> perm = (JAXBList<ObjectPermission>) restUtils.unmarshal(req.getInputStream(),
                JAXBList.class, ObjectPermissionImpl.class, UserImpl.class, RoleImpl.class);
        for (int i = 0; i < perm.size(); i++) {
            if (isValidObjectPermission(perm.get(i)) && canUpdateObjectPermissions(perm.get(i)))
                try {
                    permissionsService.putPermission(perm.get(i));
                } catch (IllegalArgumentException e) {
                    throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
                } catch (RemoteException e) {
                    throw new ServiceException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                            e.getClass().getName() + (e.getMessage() != null ? ": " + e.getMessage() : ""));
                }
            else {
                if (perm.get(i).getPermissionRecipient() instanceof User) {
                    throw new AccessDeniedException("could not set permissions for: "
                            + ((User) perm.get(i).getPermissionRecipient()).getUsername());
                } else if (perm.get(i).getPermissionRecipient() instanceof Role) {
                    throw new AccessDeniedException("could not set permissions for: "
                            + ((Role) perm.get(i).getPermissionRecipient()).getRoleName());
                } else {
                    throw new AccessDeniedException(
                            "could not set permissions for: " + (perm.get(i).getPermissionRecipient() != null
                                    ? perm.get(i).getPermissionRecipient().toString()
                                    : "null"));
                }
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("finished PUT permissions " + perm.size() + " permissions were added");
        }
        restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, "");
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST,
                "please check the request job descriptor");
    } catch (IOException e) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST,
                "please check the request job descriptor");
    } catch (JAXBException e) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST,
                "please check the request job descriptor");
    }
}

From source file:net.amigocraft.unusuals.Main.java

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (label.equalsIgnoreCase("unusual") || label.equalsIgnoreCase("unusuals")) {
        if (args.length > 0) {
            if (args[0].equalsIgnoreCase("spawn")) {
                if (sender instanceof Player) {
                    if (sender.hasPermission("unusual.spawn")) {
                        if (args.length > 1) {
                            Material mat = Material.matchMaterial(args[1]);
                            if (mat != null) {
                                if (args.length > 2) {
                                    String effectName = "";
                                    for (int i = 2; i < args.length; i++)
                                        effectName += args[i] + (i < args.length - 1 ? " " : "");
                                    try {
                                        ((Player) sender).getInventory()
                                                .addItem(createUnusual(mat, effectName));
                                        sender.sendMessage(ChatColor.DARK_PURPLE + "Enjoy your Unusual!");
                                    } catch (IllegalArgumentException ex) {
                                        if (ex.getMessage().contains("particle"))
                                            sender.sendMessage(ChatColor.RED
                                                    + "The specified effect has an invalid particle type. "
                                                    + "Please report this to an administrator.");
                                        else
                                            sender.sendMessage(
                                                    ChatColor.RED + "Invalid effect! Usage: /unusual spawn "
                                                            + mat.toString() + " [effect name]");
                                    }/*from   w  ww .  j a  va 2  s. com*/
                                } else
                                    sender.sendMessage(
                                            ChatColor.RED + "Too few arguments! Usage: /unusual spawn "
                                                    + mat.toString() + " [effect name]");
                            } else
                                sender.sendMessage(ChatColor.RED
                                        + "Invalid material! Usage: /unusual spawn [materal] [effect name]");
                        } else
                            sender.sendMessage(ChatColor.RED
                                    + "Too few arguments! Usage: /unusual spawn [material] [effect name]");
                    } else
                        sender.sendMessage(ChatColor.RED + "You do not have permission to use this command!");
                } else
                    sender.sendMessage(ChatColor.RED + "You must be a player to use this command!");
            } else if (args[0].equalsIgnoreCase("reload")) {
                if (sender.hasPermission("unsuual.reload")) {
                    Bukkit.getPluginManager().disablePlugin(plugin);
                    reloadConfig();
                    Bukkit.getPluginManager().enablePlugin(Bukkit.getPluginManager().getPlugin("Unusuals"));
                    sender.sendMessage(ChatColor.GREEN + "[Unusuals] Successfully reloaded!");
                } else
                    sender.sendMessage(ChatColor.RED + "You do not have permission to use this command!");
            } else
                sender.sendMessage(ChatColor.RED + "Invalid arguments! Usage: /unusual [args]");
        } else
            sender.sendMessage(ChatColor.LIGHT_PURPLE + "This server is running Unusuals v"
                    + plugin.getDescription().getVersion() + " by Maxim Roncace");
        return true;
    }
    return false;
}

From source file:$.ManagerService.java

/**
     * This will give link to generated agent
     *// ww  w . j  av  a  2s. c  om
     * @param deviceName name of the device which is to be created
     * @param sketchType name of sketch type
     * @return link to generated agent
     */
    @Path("manager/device/{sketch_type}/generate_link")
    @GET
    public Response generateSketchLink(@QueryParam("deviceName") String deviceName,
            @PathParam("sketch_type") String sketchType) {

        try {
            ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType);
            ResponsePayload responsePayload = new ResponsePayload();
            responsePayload.setStatusCode(HttpStatus.SC_OK);
            responsePayload.setMessageFromServer(
                    "Sending Requested sketch by type: " + sketchType + " and id: " + zipFile.getDeviceId() + ".");
            responsePayload.setResponseContent(zipFile.getDeviceId());
            return Response.status(HttpStatus.SC_OK).entity(responsePayload).build();
        } catch (IllegalArgumentException ex) {
            return Response.status(HttpStatus.SC_BAD_REQUEST).entity(ex.getMessage()).build();
        } catch (DeviceManagementException ex) {
            log.error("Error occurred while creating device with name " + deviceName + "\n", ex);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
        } catch (AccessTokenException ex) {
            log.error(ex.getMessage(), ex);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
        } catch (DeviceControllerException ex) {
            log.error(ex.getMessage(), ex);
            return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
        }
    }

From source file:com.blackducksoftware.integration.hub.builder.HubProxyInfoBuilder.java

public void validatePort(final ValidationResults<GlobalFieldKey, HubProxyInfo> result) {
    if (StringUtils.isBlank(host) && StringUtils.isBlank(port)) {
        result.addResult(HubProxyInfoFieldEnum.PROXYHOST, new ValidationResult(ValidationResultEnum.OK, ""));
        result.addResult(HubProxyInfoFieldEnum.PROXYPORT, new ValidationResult(ValidationResultEnum.OK, ""));
        return;/*from   w w  w.  ja  va  2s.c o  m*/
    } else if (StringUtils.isBlank(host) && StringUtils.isNotBlank(port)) {
        result.addResult(HubProxyInfoFieldEnum.PROXYHOST,
                new ValidationResult(ValidationResultEnum.ERROR, MSG_PROXY_HOST_REQUIRED));
    } else if (StringUtils.isNotBlank(host) && StringUtils.isBlank(port)) {
        result.addResult(HubProxyInfoFieldEnum.PROXYPORT,
                new ValidationResult(ValidationResultEnum.ERROR, MSG_PROXY_PORT_REQUIRED));
        return;
    }
    int portToValidate = 0;
    try {
        portToValidate = stringToInteger(port);
    } catch (final IllegalArgumentException e) {
        result.addResult(HubProxyInfoFieldEnum.PROXYPORT,
                new ValidationResult(ValidationResultEnum.ERROR, e.getMessage(), e));
        return;
    }
    if (StringUtils.isNotBlank(host) && portToValidate < 0) {
        result.addResult(HubProxyInfoFieldEnum.PROXYPORT,
                new ValidationResult(ValidationResultEnum.ERROR, MSG_PROXY_PORT_INVALID));
    } else {
        result.addResult(HubProxyInfoFieldEnum.PROXYPORT, new ValidationResult(ValidationResultEnum.OK, ""));
    }

}

From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java

@Test
public void testRenewInitParamThrows() throws Exception {
    final AuthenticationFilter f = new AuthenticationFilter();
    final MockFilterConfig config = new MockFilterConfig();
    config.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
    config.addInitParameter("service", CAS_SERVICE_URL);
    config.addInitParameter("renew", "true");
    try {/*from   w w  w.  jav a2 s  .  co m*/
        f.init(config);
        fail("Should have thrown IllegalArgumentException.");
    } catch (final IllegalArgumentException e) {
        assertTrue(e.getMessage().contains("Renew MUST"));
    }
}