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:org.geoserver.web.netcdf.layer.NetCDFParserBean.java

public NetCDFParserBean() {
    Resource cfStandardTable = null;
    // Check if an external file has been defined
    if (netcdfFile != null) {
        cfStandardTable = netcdfFile;//from   ww  w. j  a  v  a 2  s.  com
    }
    // Checking if it is contained in the NetCDF Data Directory
    if (cfStandardTable == null && NetCDFUtilities.EXTERNAL_DATA_DIR != null) {
        // Getting the directory file
        File netCDFDir = new File(NetCDFUtilities.EXTERNAL_DATA_DIR);
        // Creating a File filter
        FileFilter filter = FileFilterUtils.nameFileFilter(NETCDF_STANDARD_NAME, IOCase.INSENSITIVE);
        // Getting the filtered file array
        File[] files = netCDFDir.listFiles(filter);
        // Getting the file if present
        if (files != null && files.length > 0) {
            cfStandardTable = Files.asResource(files[0]);
        }
    }

    if (cfStandardTable == null) {
        // Getting geoServer data dir
        GeoServerDataDirectory datadir = GeoServerExtensions.bean(GeoServerDataDirectory.class);
        // Checking if the standard table is present
        try {
            cfStandardTable = datadir.get(NETCDF_STANDARD_NAME);
        } catch (IllegalStateException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
    }

    // Check if the file can be parsed
    if (cfStandardTable != null && cfStandardTable.getType() != Resource.Type.UNDEFINED) {
        NetCDFCFParser parser = null;
        try {
            parser = NetCDFCFParser.unmarshallXml(cfStandardTable.file());
        } catch (JAXBException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        } catch (IllegalStateException e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
        // If so set it as global attribute
        if (parser != null) {
            this.parser = parser;
        }
    } else {
        LOGGER.log(Level.WARNING, "No CF-Standard File found");
    }
}

From source file:org.sakaiproject.nakamura.files.pool.GetAlternativeContentPoolStreamServlet.java

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    try {/*from  w w  w. j a  v  a2 s.  c o m*/
        Resource resource = request.getResource();
        Content node = resource.adaptTo(Content.class);
        ContentManager contentManager = resource.adaptTo(ContentManager.class);
        String alternativeStream = getAlternativeStream(request);

        StreamHelper streamHelper = new StreamHelper();

        ServletContext sc = null;
        try {
            sc = getServletContext();
        } catch (IllegalStateException e) {
            LOGGER.debug(e.getMessage(), e);
        }

        streamHelper.stream(request, contentManager, node, alternativeStream, response, resource, sc);
    } catch (ClientPoolException e) {
        LOGGER.warn(e.getMessage(), e);
        throw new ServletException(e.getMessage(), e);
    } catch (StorageClientException e) {
        LOGGER.warn(e.getMessage(), e);
        throw new ServletException(e.getMessage(), e);
    } catch (AccessDeniedException e) {
        LOGGER.warn(e.getMessage(), e);
        throw new ServletException(e.getMessage(), e);
    }
}

From source file:org.sonar.application.StartServerTest.java

@Test
public void fail_if_started_twice() throws Exception {
    BackgroundThread background = new BackgroundThread(starter);
    try {//from  w  w  w . j a v  a  2 s . co m
        background.start();
        boolean started = false;
        for (int i = 0; i < 100; i++) {
            // Waiting for server to be started.
            // A random and open port is used (see conf/sonar.properties)
            Thread.sleep(500L);
            if (starter.port() > 0) {
                try {
                    starter.start();
                    fail();
                } catch (IllegalStateException e) {
                    assertThat(e.getMessage()).isEqualTo("Server is already started");
                    started = true;
                    break;
                }
            }
        }
        assertThat(started).isTrue();

    } finally {
        starter.stop();
    }
}

From source file:org.sonar.batch.MavenProjectConverterTest.java

/**
 * See SONAR-2681//from   ww w.j  a  v a  2s.c  o m
 */
public void shouldThrowExceptionWhenUnableToDetermineProjectStructure() {
    MavenProject root = new MavenProject();
    root.setFile(new File("/foo/pom.xml"));
    root.getBuild().setDirectory("target");
    root.getModules().add("module/pom.xml");

    try {
        MavenProjectConverter.convert(Arrays.asList(root), root);
        fail();
    } catch (IllegalStateException e) {
        assertThat(e.getMessage(), containsString("Advanced Reactor Options"));
    }
}

From source file:org.resthub.rpc.AMQPHessianProxyTest.java

@Test
public void testSerializationError() throws Exception {
    FailingServiceEndpoint endpoint = new FailingServiceEndpoint();
    endpoint.setConnectionFactory(connectionFactory);
    endpoint.run();/*from   w w w.ja v  a2 s .c  o m*/

    AMQPHessianProxyFactory factory = new AMQPHessianProxyFactory();
    factory.setReadTimeout(5000);
    factory.setConnectionFactory(connectionFactory);
    FailingService service = factory.create(FailingService.class);

    try {
        service.getNotSerializable();
        fail("IllegalStateException expected");
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains("must implement java.io.Serializable"));
    } finally {
        endpoint.destroy();
    }
}

From source file:com.google.api.server.spi.auth.EspAuthenticatorTest.java

@Test
public void testNoService() {
    this.attribute.set(ATTRIBUTE_PREFIX + ".method_info", INFO);
    try {//from   www .  j  ava  2s  . co m
        espAuthenticator.authenticate(request);
        fail("Expected IllegalStateException.");
    } catch (IllegalStateException exception) {
        assertEquals("service is not set in the request", exception.getMessage());
    }
}

From source file:org.elasticsearch.client.SyncResponseListenerTests.java

public void testOnSuccess() throws Exception {
    RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
    Response mockResponse = mockResponse();
    syncResponseListener.onSuccess(mockResponse);
    Response response = syncResponseListener.get();
    assertSame(response, mockResponse);/*from  ww w. ja  v  a 2s .  c om*/

    try {
        syncResponseListener.onSuccess(mockResponse);
        fail("get should have failed");
    } catch (IllegalStateException e) {
        assertEquals(e.getMessage(), "response is already set");
    }
    response = syncResponseListener.get();
    assertSame(response, mockResponse);

    RuntimeException runtimeException = new RuntimeException("test");
    syncResponseListener.onFailure(runtimeException);
    try {
        syncResponseListener.get();
        fail("get should have failed");
    } catch (IllegalStateException e) {
        assertEquals("response and exception are unexpectedly set at the same time", e.getMessage());
        assertNotNull(e.getSuppressed());
        assertEquals(1, e.getSuppressed().length);
        assertSame(runtimeException, e.getSuppressed()[0]);
    }
}

From source file:com.google.api.server.spi.auth.EspAuthenticatorTest.java

@Test
public void testNoMethodInfo() {
    try {/* w w w  .  j a  v  a  2s  .  c om*/
        this.espAuthenticator.authenticate(request);
        fail("Expected IllegalStateException.");
    } catch (IllegalStateException exception) {
        assertEquals("method_info is not set in the request", exception.getMessage());
    }
}

From source file:ca.simplegames.micro.filters.FilterWrapper.java

@SuppressWarnings("unchecked")
public void call(MicroContext context) throws ControllerNotFoundException, ControllerException {
    if (context != null) {
        // check if there is a path defined for the filter and verify is matching the request
        if (path != null) {
            Context<String> input = (Context<String>) context.get(Globals.RACK_INPUT);
            String requestPath = input.get(JRack.PATH_INFO);
            if (StringUtils.isBlank(requestPath)) {
                requestPath = input.get(Rack.SCRIPT_NAME);
            }//from  www.  ja v  a  2s.com

            UriTemplateMatcher templateMatcher = match(requestPath, path);

            if (templateMatcher != null) {
                try {
                    MultivaluedMap<String, String> routeParams = templateMatcher.getVariables(true);
                    Map<String, String[]> params = (Map<String, String[]>) context.get(Globals.PARAMS);

                    if (CollectionUtils.isEmpty(params)) {
                        params = new HashMap<String, String[]>();
                        context.with(Globals.PARAMS, params);
                    }

                    for (Map.Entry<String, List<String>> param : routeParams.entrySet()) {
                        params.put(param.getKey(),
                                param.getValue().toArray(new String[param.getValue().size()]));
                    }

                    executeControllers(context);
                } catch (IllegalStateException e) {
                    context.getLog().error(e.getMessage()); //todo: improve the error message
                }
            }
        } else {
            executeControllers(context);
        }
    }
}

From source file:eu.eubrazilcc.lvl.core.ConcurrencyTest.java

@Test
public void test() {
    System.out.println("ConcurrencyTest.test()");
    try {//from   w w w .  j a  v  a 2s . co  m
        final String success = "OK";

        // test uninitialized task runner         
        try {
            TASK_RUNNER.submit(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    return success;
                }
            });
            fail("Should have thrown an IllegalStateException because task runner is uninitialized");
        } catch (IllegalStateException e) {
            assertThat(e.getMessage(), containsString("Task runner uninitialized"));
        }

        // test run task
        TASK_RUNNER.preload();
        final ListenableFuture<String> future = TASK_RUNNER.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                return success;
            }
        });
        assertThat("task future is not null", future, notNullValue());
        final String result = future.get(20, SECONDS);
        assertThat("task result is not null", result, notNullValue());
        assertThat("task result is not empty", isNotBlank(result));
        assertThat("task result coincides with expected", result, equalTo(success));

        // test uninitialized task scheduler
        try {
            TASK_SCHEDULER.scheduleAtFixedRate(new Runnable() {
                @Override
                public void run() {
                    System.out.println(" >> Scheluded job runs");
                }
            }, 0, 20, SECONDS);
            fail("Should have thrown an IllegalStateException because task runner is uninitialized");
        } catch (IllegalStateException e) {
            assertThat(e.getMessage(), containsString("Task scheduler uninitialized"));
        }

        // test schedule task
        TASK_SCHEDULER.preload();
        final ListenableScheduledFuture<?> future2 = TASK_SCHEDULER.scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println(" >> Scheluded job runs");
            }
        }, 0, 20, SECONDS);
        assertThat("scheduled task future is not null", future2, notNullValue());
        future2.addListener(new Runnable() {
            @Override
            public void run() {
                isCompleted = true;
            }
        }, directExecutor());
        Thread.sleep(2000);
        assertThat("scheduled task result coincides with expected", isCompleted, equalTo(isCompleted));
    } catch (Exception e) {
        e.printStackTrace(System.err);
        fail("ConcurrencyTest.test() failed: " + e.getMessage());
    } finally {
        System.out.println("ConcurrencyTest.test() has finished");
    }
}