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:com.streamsets.pipeline.stage.bigquery.destination.BigQueryTarget.java

/**
 * Convert the root field to a java map object implicitly mapping each field to the column (only non nested objects)
 * @param record record to be converted/*from  w ww .j  av  a 2  s .  c om*/
 * @return Java row representation for the record
 */
private Map<String, Object> convertToRowObjectFromRecord(Record record) throws OnRecordErrorException {
    Field rootField = record.get();
    Map<String, Object> rowObject = new LinkedHashMap<>();
    if (rootField.getType().isOneOf(Field.Type.MAP, Field.Type.LIST_MAP)) {
        Map<String, Field> fieldMap = rootField.getValueAsMap();
        for (Map.Entry<String, Field> fieldEntry : fieldMap.entrySet()) {
            Field field = fieldEntry.getValue();
            //Skip null value fields
            if (field.getValue() != null) {
                try {
                    rowObject.put(fieldEntry.getKey(), getValueFromField("/" + fieldEntry.getKey(), field));
                } catch (IllegalArgumentException e) {
                    throw new OnRecordErrorException(record, Errors.BIGQUERY_13, e.getMessage());
                }
            }
        }
    } else {
        throw new OnRecordErrorException(record, Errors.BIGQUERY_16);
    }
    return rowObject;
}

From source file:com.izforge.izpack.installer.bootstrap.Installer.java

private void start(String[] args) {
    // OS X tweaks
    if (System.getProperty("mrj.version") != null) {
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "IzPack");
        System.setProperty("com.apple.mrj.application.growbox.intrudes", "false");
        System.setProperty("com.apple.mrj.application.live-resize", "true");
    }/*from w  w  w .  j  a v  a  2  s  . c o m*/

    try {
        Iterator<String> args_it = Arrays.asList(args).iterator();

        int type = INSTALLER_GUI;
        ConsoleInstallerAction consoleAction = ConsoleInstallerAction.CONSOLE_INSTALL;
        String path = null;
        String langcode = null;
        String media = null;
        String defaultsFile = null;
        String logFileName = null;

        while (args_it.hasNext()) {
            String arg = args_it.next().trim();
            try {
                if ("-logfile".equalsIgnoreCase(arg)) {
                    logFileName = fetchArgument(args_it, logFileName);
                    checkPath(logFileName);
                } else if ("-debug".equalsIgnoreCase(arg)) {
                    Debug.setDEBUG(true);
                } else if ("-trace".equalsIgnoreCase(arg)) {
                    Debug.setTRACE(true);
                } else if ("-stacktrace".equalsIgnoreCase(arg)) {
                    Debug.setSTACKTRACE(true);
                } else if ("-console".equalsIgnoreCase(arg)) {
                    type = INSTALLER_CONSOLE;
                } else if ("-auto".equalsIgnoreCase(arg)) {
                    type = INSTALLER_AUTO;
                } else if ("-defaults-file".equalsIgnoreCase(arg)) {
                    defaultsFile = fetchArgument(args_it, defaultsFile);
                    checkPath(defaultsFile);
                } else if ("-options-template".equalsIgnoreCase(arg)) {
                    path = fetchArgument(args_it, path);
                    checkPath(path);
                    type = INSTALLER_CONSOLE;
                    consoleAction = ConsoleInstallerAction.CONSOLE_GEN_TEMPLATE;
                } else if ("-options".equalsIgnoreCase(arg)) {
                    path = fetchArgument(args_it, path);
                    checkPath(path);
                    type = INSTALLER_CONSOLE;
                    consoleAction = ConsoleInstallerAction.CONSOLE_FROM_TEMPLATE;
                } else if ("-options-system".equalsIgnoreCase(arg)) {
                    type = INSTALLER_CONSOLE;
                    consoleAction = ConsoleInstallerAction.CONSOLE_FROM_SYSTEMPROPERTIES;
                } else if ("-options-auto".equalsIgnoreCase(arg)) {
                    path = fetchArgument(args_it, path);
                    checkPath(path);
                    type = INSTALLER_CONSOLE;
                    consoleAction = ConsoleInstallerAction.CONSOLE_FROM_SYSTEMPROPERTIESMERGE;
                } else if ("-language".equalsIgnoreCase(arg)) {
                    langcode = fetchArgument(args_it, langcode);
                    if (langcode == null || langcode.startsWith("-")) {
                        throw new IllegalArgumentException("Option must be followed by a language code");
                    }
                } else if ("-media".equalsIgnoreCase(arg)) {
                    media = fetchArgument(args_it, media);
                    checkPath(media);
                } else {
                    type = INSTALLER_AUTO;
                    path = arg;
                }
            } catch (IllegalArgumentException e) {
                logger.severe("Wrong usage of command line argument \"" + arg + "\": " + e.getMessage());
                System.exit(1);
            }
        }

        initializeLogging(logFileName);

        logger.info("Command line arguments: " + StringTool.stringArrayToSpaceSeparatedString(args));

        Overrides defaults = getDefaults(defaultsFile);
        if (type == INSTALLER_AUTO && path == null && defaults == null) {
            logger.log(Level.SEVERE,
                    "Unattended installation mode needs either a defaults file specified by '-defaults-file'"
                            + " or an installation record XML file as argument");
            System.exit(1);
        }

        launchInstall(type, consoleAction, path, langcode, media, defaults, args);

    } catch (Exception e) {
        logger.log(Level.SEVERE, e.getMessage(), e);
        System.exit(1);
    }
}

From source file:cz.PA165.vozovyPark.dao.UserDAOTest.java

/**
 *
 *///from   w  ww.  j  a  v a2 s. c o  m
@Test
public void testCreateWithNullArguments() {
    //UserDAO dao = createUserDAOFactory();
    try {
        userDao.createUser(null);
        fail("Exception for null argument was not threw.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        fail("Wrong Exception was threw: " + e + " " + e.getMessage());
    }
}

From source file:cz.PA165.vozovyPark.dao.UserDAOTest.java

/**
 *
 *//*from  w w  w.j  a va 2 s  . com*/
@Test
public void testUpdateWithNullArgument() {
    try {
        userDao.updateUser(null);
        fail("Exception for null argument was not threw.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        fail("Wrong Exception was threw: " + e + " " + e.getMessage());
    }

}

From source file:cz.PA165.vozovyPark.dao.UserDAOTest.java

/**
 *
 *//* www  .  j  a v  a 2 s .  c o  m*/
@Test
public void testRemoveWithNullArgument() {
    // Remove user that is null 
    //UserDAO dao = createUserDAOFactory();
    try {
        userDao.removeUser(null);
        fail("Exception for null argument was not threw.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        fail("Wrong Exception was threw: " + e + " " + e.getMessage());
    }
}

From source file:cz.PA165.vozovyPark.dao.UserDAOTest.java

/**
 *
        /*w w  w .j  a  va  2  s .  c  om*/
/**
 *
 */
@Test
public void testGetUserByIdWithNullArgument() {
    // UserDAO without Entity Manager Factory
    // UserDAO dao = createUserDAOFactory();

    try {
        userDao.getById(null);
        fail("Exception for null argument was not threw.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        fail("Wrong Exception was threw: " + e + " " + e.getMessage());
    }
}

From source file:cz.PA165.vozovyPark.dao.UserDAOTest.java

/**
 *
 *///from www  . j  a v a2 s . com
@Test
public void testFindByNameWithWrongArgument() {
    //UserDAO dao = createUserDAOFactory();

    try {
        userDao.findByLastName(null);
        fail("Exception for null argument was not threw.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        fail("Wrong Exception was threw: " + e + " " + e.getMessage());
    }

    try {
        userDao.findByLastName("");
        fail("Exception for empty string as argument was not threw.");
    } catch (IllegalArgumentException e) {
    } catch (Exception e) {
        fail("Wrong Exception was threw: " + e + " " + e.getMessage());
    }
}

From source file:com.sap.dirigible.runtime.registry.RegistryServlet.java

@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {

    String repositoryPath = null;
    final String requestPath = request.getPathInfo();
    boolean deep = false;
    if (requestPath == null) {
        deep = true;/*from   w  w  w.j av a2 s  .  c  o  m*/
    }
    final OutputStream out = response.getOutputStream();
    try {
        repositoryPath = extractRepositoryPath(request);
        final IEntity entity = getEntity(repositoryPath, request);
        byte[] data;
        if (entity != null) {
            if (entity instanceof IResource) {
                data = buildResourceData(entity, request, response);
            } else if (entity instanceof ICollection) {
                String collectionPath = request.getRequestURI().toString();
                String acceptHeader = request.getHeader(ACCEPT_HEADER);
                if (acceptHeader != null && acceptHeader.contains(JSON)) {
                    if (!collectionPath.endsWith(IRepository.SEPARATOR)) {
                        collectionPath += IRepository.SEPARATOR;
                    }
                    data = buildCollectionData(deep, entity, collectionPath);
                } else {
                    // welcome file support
                    IResource index = ((ICollection) entity).getResource(INDEX_HTML);
                    if (index.exists() && (collectionPath.endsWith(IRepository.SEPARATOR))) {
                        data = buildResourceData(index, request, response);
                    } else {
                        // listing of collections is forbidden
                        exceptionHandler(response, repositoryPath, HttpServletResponse.SC_FORBIDDEN,
                                LISTING_OF_FOLDERS_IS_FORBIDDEN);
                        return;
                    }
                }
            } else {
                exceptionHandler(response, repositoryPath, HttpServletResponse.SC_FORBIDDEN,
                        LISTING_OF_FOLDERS_IS_FORBIDDEN);
                return;
            }
        } else {
            exceptionHandler(response, repositoryPath, HttpServletResponse.SC_NOT_FOUND,
                    String.format("Resource at [%s] does not exist", requestPath));
            return;
        }

        if (entity instanceof IResource) {
            final IResource resource = (IResource) entity;
            String mimeType = null;
            String extension = ContentTypeHelper.getExtension(resource.getName());
            if ((mimeType = ContentTypeHelper.getContentType(extension)) != null) {
                response.setContentType(mimeType);
            } else {
                response.setContentType(resource.getContentType());
            }
        }
        sendData(out, data);
    } catch (final IllegalArgumentException ex) {
        exceptionHandler(response, repositoryPath, HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
    } catch (final MissingResourceException ex) {
        exceptionHandler(response, repositoryPath, HttpServletResponse.SC_NO_CONTENT, ex.getMessage());
    } catch (final RuntimeException ex) {
        exceptionHandler(response, repositoryPath, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                ex.getMessage());
    } finally {
        out.flush();
        out.close();
    }
}

From source file:org.jolokia.client.request.J4pReadIntegrationTest.java

@Test
public void mbeanPatternWithAttributes() throws MalformedObjectNameException, J4pException {
    for (J4pReadRequest req : readRequests("*:type=attribute", "LongSeconds", "List")) {
        assertNull(req.getPath());/*from  w  w w.j  a  va2 s  .  c om*/
        J4pReadResponse resp = j4pClient.execute(req);
        assertEquals(1, resp.getObjectNames().size());
        Map respVal = resp.getValue();
        Map attrs = (Map) respVal.get(itSetup.getAttributeMBean());
        assertEquals(2, attrs.size());
        assertTrue(attrs.containsKey("LongSeconds"));
        assertTrue(attrs.containsKey("List"));

        Double longVal = resp.getValue(new ObjectName(itSetup.getAttributeMBean()), "LongSeconds");
        assertNotNull(longVal);

        try {
            resp.getValue(new ObjectName(itSetup.getAttributeMBean()), "FCN");
            fail();
        } catch (IllegalArgumentException exp) {
            assertTrue(exp.getMessage().contains("FCN"));
        }
    }
}

From source file:com.google.ytd.embed.SubmitExistingVideo.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String json = util.getPostBody(req);

    try {// w w  w  .j a va  2s  .  co  m
        JSONObject jsonObj = new JSONObject(json);

        JSONArray videoIds = jsonObj.getJSONArray("videoIds");
        String location = jsonObj.getString("location");
        String phoneNumber = jsonObj.getString("phoneNumber");
        String date = jsonObj.getString("date");
        String email = jsonObj.getString("email");

        String assignmentId = null;
        if (jsonObj.has("assignmentId")) {
            assignmentId = jsonObj.getString("assignmentId");
        }

        if (videoIds.length() < 1) {
            throw new IllegalArgumentException("No video ids were provided.");
        }

        // Grab user session meta data
        UserSession userSession = userSessionManager.getUserSession(req);
        String youTubeName = userSession.getMetaData("youTubeName");
        String authSubToken = userSession.getMetaData("authSubToken");
        String articleUrl = userSession.getMetaData("articleUrl");

        // Assignment id might be set in the JSON object if there wasn't an assignment associated
        // with the embedded iframe, and the assignment was chosen at run time.
        if (util.isNullOrEmpty(assignmentId)) {
            assignmentId = userSession.getMetaData("assignmentId");
        } else {
            userSession.addMetaData("assignmentId", assignmentId);
        }

        apiManager.setAuthSubToken(authSubToken);

        for (int i = 0; i < videoIds.length(); i++) {
            String videoId = videoIds.getString(i);

            VideoEntry videoEntry = apiManager.getUploadsVideoEntry(videoId);

            if (videoEntry == null) {
                JSONObject responseJsonObj = new JSONObject();
                responseJsonObj.put("success", "false");
                responseJsonObj.put("message", "Cannot find this video in your account.");

                resp.setContentType("text/javascript");
                resp.getWriter().println(responseJsonObj.toString());
            } else {
                String title = videoEntry.getTitle().getPlainText();
                String description = videoEntry.getMediaGroup().getDescription().getPlainTextContent();

                List<String> tags = videoEntry.getMediaGroup().getKeywords().getKeywords();
                String sortedTags = util.sortedJoin(tags, ",");

                long viewCount = -1;

                YtStatistics stats = videoEntry.getStatistics();
                if (stats != null) {
                    viewCount = stats.getViewCount();
                }

                VideoSubmission submission = new VideoSubmission(Long.parseLong(assignmentId));

                submission.setArticleUrl(articleUrl);
                submission.setVideoId(videoId);
                submission.setVideoTitle(title);
                submission.setVideoDescription(description);
                submission.setVideoTags(sortedTags);
                submission.setVideoLocation(location);
                submission.setPhoneNumber(phoneNumber);
                submission.setVideoDate(date);
                submission.setYouTubeName(youTubeName);

                userAuthTokenDao.setUserAuthToken(youTubeName, authSubToken);

                submission.setViewCount(viewCount);
                submission.setVideoSource(VideoSubmission.VideoSource.EXISTING_VIDEO);
                submission.setNotifyEmail(email);

                AdminConfig adminConfig = adminConfigDao.getAdminConfig();
                if (adminConfig.getModerationMode() == AdminConfig.ModerationModeType.NO_MOD.ordinal()) {
                    // NO_MOD is set, auto approve all submission
                    // TODO: This isn't enough, as the normal approval flow (adding the
                    // branding, tags, emails,
                    // etc.) isn't taking place.
                    submission.setStatus(VideoSubmission.ModerationStatus.APPROVED);

                    // Add video to YouTube playlist if it isn't in it already.
                    // This code is kind of ugly and is mostly copy/pasted from UpdateVideoSubmissionStatus
                    // TODO: It should be refactored into a common helper method somewhere...
                    if (!submission.isInPlaylist()) {
                        Assignment assignment = assignmentDao.getAssignmentById(assignmentId);

                        if (assignment == null) {
                            log.warning(String.format("Couldn't find assignment id '%d' for video id '%s'.",
                                    assignmentId, videoId));
                        } else {
                            String playlistId = assignment.getPlaylistId();
                            if (util.isNullOrEmpty(playlistId)) {
                                log.warning(
                                        String.format("Assignment id '%d' doesn't have an associated playlist.",
                                                assignmentId));
                            } else {
                                apiManager.setAuthSubToken(adminConfig.getYouTubeAuthSubToken());
                                if (apiManager.insertVideoIntoPlaylist(playlistId, videoId)) {
                                    submission.setIsInPlaylist(true);
                                }
                            }
                        }
                    }
                }

                pmfUtil.persistJdo(submission);

                emailUtil.sendNewSubmissionEmail(submission);
            }
        }

        JSONObject responseJsonObj = new JSONObject();
        responseJsonObj.put("success", "true");

        resp.setContentType("text/javascript");
        resp.getWriter().println(responseJsonObj.toString());
    } catch (IllegalArgumentException e) {
        log.log(Level.FINE, "", e);
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
    } catch (JSONException e) {
        log.log(Level.WARNING, "", e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}