Example usage for java.lang IllegalStateException getMessage

List of usage examples for java.lang IllegalStateException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.umd.cs.submitServer.filters.RegisterStudentsFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    if (!request.getMethod().equals("POST")) {
        throw new ServletException("Only POST accepted");
    }//from  w  ww .j  av  a 2s  . co  m
    Connection conn = null;
    BufferedReader reader = null;
    FileItem fileItem = null;
    TreeSet<StudentRegistration> registeredStudents = new TreeSet<StudentRegistration>();
    List<String> errors = new ArrayList<String>();
    try {
        conn = getConnection();

        // MultipartRequestFilter is required
        MultipartRequest multipartRequest = (MultipartRequest) request.getAttribute(MULTIPART_REQUEST);

        Course course = (Course) request.getAttribute("course");

        // open the uploaded file
        fileItem = multipartRequest.getFileItem();
        reader = new BufferedReader(new InputStreamReader(fileItem.getInputStream()));

        int lineNumber = 1;

        while (true) {
            String line = reader.readLine();
            if (line == null)
                break;
            lineNumber++;

            // hard-coded skip of first two lines for Maryland-specific
            // format
            if (line.startsWith("Last,First,UID,section,ClassAcct,DirectoryID"))
                continue;
            if (line.startsWith(",,,,,")) {
                if (line.equals(",,,,,"))
                    continue;
                String ldap = line.substring(5);
                Student student = Student.lookupByLoginName(ldap, conn);
                if (student != null) {
                    StudentRegistration sr = StudentForUpload.registerStudent(course, student, "", ldap, null,
                            conn);
                    registeredStudents.add(sr);
                } else
                    errors.add("Did not find " + ldap);

                continue;

            }
            if (line.startsWith("#"))
                continue;

            // skip blank lines
            if (line.trim().equals(""))
                continue;

            try {
                StudentForUpload s = new StudentForUpload(line, delimiter);

                Student student = s.lookupOrInsert(conn);
                StudentRegistration sr = StudentForUpload.registerStudent(course, student, s.section,
                        s.classAccount, null, conn);
                registeredStudents.add(sr);

            } catch (IllegalStateException e) {
                errors.add(e.getMessage());
                ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request,
                        "error while registering " + line, null, e);

            } catch (Exception e1) {
                errors.add("Problem processing line: '" + line + "' at line number: " + lineNumber);
                ServletExceptionFilter.logError(conn, ServerError.Kind.EXCEPTION, request,
                        "error while registering " + line, null, e1);
            }
        }
    } catch (SQLException e) {
        throw new ServletException(e);
    } finally {
        releaseConnection(conn);
        if (reader != null)
            reader.close();
        if (fileItem != null)
            fileItem.delete();
    }
    request.setAttribute("registeredStudents", registeredStudents);
    request.setAttribute("errors", errors);
    chain.doFilter(request, response);
}

From source file:de.zib.gndms.infra.system.PluggableTaskFlowProvider.java

public void loadPlugins(boolean checkDeps) {

    Map<String, TaskFlowFactory> plugins = new HashMap<String, TaskFlowFactory>(10);

    ServiceLoader<TaskFlowFactory> sl;
    if (getCl() != null)
        sl = ServiceLoader.load(TaskFlowFactory.class, getCl());
    else/*from  ww  w .j a  v  a 2  s.  co  m*/
        sl = ServiceLoader.load(TaskFlowFactory.class);

    for (TaskFlowFactory bp : sl) {
        try {
            register(bp, plugins);
        } catch (IllegalStateException e) {
            logger.warn(e.getMessage());
        }
    }

    setFactories(plugins);

    if (checkDeps)
        checkDeps();

    // call all PostConstruct methods
    for (TaskFlowFactory bp : sl) {
        for (Method method : bp.getClass().getDeclaredMethods()) {
            if (method.getAnnotation(PostConstruct.class) != null) {
                ReflectionUtils.makeAccessible(method);
                try {
                    method.invoke(bp, (Object[]) null);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(
                            "THIS IS NOT HAPPENING!!! Method had been made accessible but is not accessible anyway",
                            e);
                } catch (InvocationTargetException e) {
                    throw new RuntimeException(
                            "Could not call PostConstruct method (" + method.toGenericString() + ")", e);
                }
            }
        }
    }

    // todo this is just for development change this for releases:
    //        if ( getFactories().size() == 0 )
    //            throw new IllegalStateException( "no plugs found" );
}

From source file:com.microsoft.tfs.core.httpclient.auth.AuthChallengeProcessor.java

/**
 * Determines the preferred {@link AuthScheme authentication scheme} that
 * can be used to respond to the given collection of challenges.
 *
 * @param challenges//from   ww w. j a v a2  s  . c o m
 *        the collection of authentication challenges
 *
 * @return the preferred {@link AuthScheme authentication scheme}
 *
 * @throws AuthChallengeException
 *         if the preferred authentication scheme cannot be determined or is
 *         not supported
 */
public AuthScheme selectAuthScheme(final Map challenges, final Credentials credentials)
        throws AuthChallengeException {
    if (challenges == null) {
        throw new IllegalArgumentException("Challenge map may not be null");
    }
    Collection authPrefs = (Collection) params.getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY);
    if (authPrefs == null || authPrefs.isEmpty()) {
        authPrefs = AuthPolicy.getDefaultAuthPrefs();
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Supported authentication schemes in the order of preference: " + authPrefs);
    }
    AuthScheme authscheme = null;
    String challenge = null;
    final Iterator item = authPrefs.iterator();
    while (item.hasNext()) {
        final String id = (String) item.next();
        challenge = (String) challenges.get(id.toLowerCase());

        if (challenge != null) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(id + " authentication scheme selected");
            }
            try {
                final AuthScheme testScheme = AuthPolicy.getAuthScheme(id);

                // If we were passed credentials, see if the auth scheme
                // supports them
                if (credentials == null || testScheme.supportsCredentials(credentials)) {
                    authscheme = testScheme;
                    break;
                }
            } catch (final IllegalStateException e) {
                throw new AuthChallengeException(e.getMessage());
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Challenge for " + id + " authentication scheme not available");
                // Try again
            }
        }
    }

    if (authscheme == null) {
        // If none selected, something is wrong
        throw new AuthChallengeException("Unable to respond to any of these challenges: " + challenges);
    }

    return authscheme;
}

From source file:org.apache.phoenix.schema.stats.UpdateStatisticsTool.java

void parseArgs(String[] args) {
    CommandLine cmdLine = null;// www.j  av  a2s .  co m
    try {
        cmdLine = parseOptions(args);
    } catch (IllegalStateException e) {
        printHelpAndExit(e.getMessage(), getOptions());
    }

    if (getConf() == null) {
        setConf(HBaseConfiguration.create());
    }

    tableName = cmdLine.getOptionValue(TABLE_NAME_OPTION.getOpt());
    snapshotName = cmdLine.getOptionValue(SNAPSHOT_NAME_OPTION.getOpt());
    if (snapshotName == null) {
        snapshotName = "UpdateStatisticsTool_" + tableName + "_" + System.currentTimeMillis();
    }

    String restoreDirOptionValue = cmdLine.getOptionValue(RESTORE_DIR_OPTION.getOpt());
    if (restoreDirOptionValue == null) {
        restoreDirOptionValue = getConf().get(FS_DEFAULT_NAME_KEY) + "/tmp";
    }

    restoreDir = new Path(restoreDirOptionValue);
    manageSnapshot = cmdLine.hasOption(MANAGE_SNAPSHOT_OPTION.getOpt());
    isForeground = cmdLine.hasOption(RUN_FOREGROUND_OPTION.getOpt());
}

From source file:net.sf.ehcache.jcache.JCacheStatisticsTest.java

/**
 * CacheStatistics should always be sensible when the cache has not started.
 *//*  ww w  . ja v  a  2 s  .  c om*/
public void testCacheStatisticsDegradesElegantlyWhenCacheDisposed() {
    Ehcache ehcache = new net.sf.ehcache.Cache("test", 1, true, false, 5, 2);
    Cache cache = new JCache(ehcache, null);
    try {
        CacheStatistics statistics = cache.getCacheStatistics();
        fail();
    } catch (IllegalStateException e) {
        assertEquals("The test Cache is not alive.", e.getMessage());
    }

}

From source file:com.puppycrawl.tools.checkstyle.checks.javadoc.AbstractTypeAwareCheckTest.java

@Test
public void testWithoutLogErrors() throws Exception {
    DefaultConfiguration config = createCheckConfig(JavadocMethodCheck.class);
    config.addAttribute("logLoadErrors", "false");
    config.addAttribute("allowUndeclaredRTE", "true");
    final String[] expected = { "7:8: " + getCheckMessage(MSG_CLASS_INFO, "@throws", "InvalidExceptionName"), };
    try {/*from ww  w  .j a va 2  s .com*/
        verify(config, getPath("InputLoadErrors.java"), expected);
    } catch (IllegalStateException ex) {
        assertEquals("Unable to get" + " class information for @throws tag 'InvalidExceptionName'.",
                ex.getMessage());
    }
}

From source file:org.jboss.aerogear.android.unifiedpush.test.gcm.AeroGearGCMPushRegistrarTest.java

public void testAsRegistrarFailsOnNullPushServerURI() {
    try {/*from  ww w. j  a v  a  2s  . c om*/
        AeroGearGCMPushConfiguration config = new AeroGearGCMPushConfiguration().addSenderId(TEST_SENDER_ID);

        config.asRegistrar();

    } catch (IllegalStateException ex) {
        assertEquals("PushServerURI can't be null", ex.getMessage());
        return; // pass
    }
    fail();
}

From source file:org.jboss.aerogear.android.unifiedpush.test.gcm.AeroGearGCMPushRegistrarTest.java

public void testAsRegistrarFailsOnNullSenderId() throws URISyntaxException {
    try {//from   w  ww . ja  v a 2  s . co m
        AeroGearGCMPushConfiguration config = new AeroGearGCMPushConfiguration()
                .setPushServerURI(new URI("https://testuri"));

        config.asRegistrar();

    } catch (IllegalStateException ex) {
        assertEquals("SenderIds can't be null or empty", ex.getMessage());
        return; // pass
    }
    fail();
}

From source file:org.rhq.plugins.augeas.AugeasConfigurationDiscoveryComponent.java

public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<T> discoveryContext)
        throws InvalidPluginConfigurationException, Exception {
    Set<DiscoveredResourceDetails> discoveredResources = new HashSet<DiscoveredResourceDetails>(1);

    List<String> includes = determineIncludeGlobs(discoveryContext);
    List<String> excludes = determineExcludeGlobs(discoveryContext);

    Configuration pluginConfig = discoveryContext.getDefaultPluginConfiguration();
    PropertySimple includeProps = getGlobList(AugeasConfigurationComponent.INCLUDE_GLOBS_PROP, includes);
    PropertySimple excludeProps = getGlobList(AugeasConfigurationComponent.EXCLUDE_GLOBS_PROP, excludes);
    pluginConfig.put(includeProps);/*ww  w.  j  a v  a  2  s.c o  m*/
    pluginConfig.put(excludeProps);

    try {
        checkFiles(pluginConfig);

        DiscoveredResourceDetails resource = createResourceDetails(discoveryContext, pluginConfig);
        discoveredResources.add(resource);
        log.debug("Discovered " + discoveryContext.getResourceType().getName() + " Resource with key ["
                + resource.getResourceKey() + "].");
    } catch (IllegalStateException e) { // Thrown by augeas if it can not read a file
        log.warn("Discovery failed: " + e.getMessage());
    }

    return discoveredResources;
}