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.finra.herd.service.helper.BusinessObjectDataHelperTest.java

@Test
public void getStorageUnitByStorageNameStorageUnitNoExists() {
    String testStorageName = "I_DO_NOT_EXIST";

    // Try to get a non-existing storage unit.
    try {/*from  w w w  .java2 s. c o  m*/
        businessObjectDataHelper.getStorageUnitByStorageName(new BusinessObjectData(INTEGER_VALUE,
                BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION,
                PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET,
                BusinessObjectDataStatusEntity.VALID, NO_STORAGE_UNITS, NO_ATTRIBUTES,
                NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN,
                NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY, NO_RETENTION_EXPIRATION_DATE), testStorageName);
        fail("Should throw a IllegalStateException when storage unit does not exist.");
    } catch (IllegalStateException e) {
        assertEquals(String.format("Business object data has no storage unit with storage name \"%s\".",
                testStorageName), e.getMessage());
    }
}

From source file:hello.jaxrs.GreetingsResource.java

@GET
@Produces(MediaType.TEXT_PLAIN)/*from w w  w.j  a  v a  2s.co  m*/
public Response showGreetings() {
    // read greetings
    Collection<String> greetings;
    try {
        greetings = getGreetingService().getGreetings();
    } catch (final IllegalStateException e) {
        // no service is available; lets report that properly
        return Response.status(Status.SERVICE_UNAVAILABLE).type(MediaType.TEXT_PLAIN_TYPE)
                .entity(e.getMessage()).build();
    } catch (final Exception e) {
        // this looks like an issue deeper in some underlying code; we should log this properly
        return Response.serverError().type(MediaType.TEXT_PLAIN_TYPE)
                .entity(ExceptionUtils.getFullStackTrace(e)).build();
    }

    return Response.ok(StringUtils.join(greetings, SystemUtils.LINE_SEPARATOR), MediaType.TEXT_PLAIN).build();
}

From source file:org.geoserver.restupload.ResumableUploadCatalogResource.java

/**
 * GET request with uploadId is used to get the status of upload
 * If the upload is incomplete, the GET return the RANGE header attribute:</br>
 * Range: 0-{uploded end byte index}./* w w  w  .  jav  a  2  s  .  c  o m*/
 */
@Override
public void handleGet() {
    String uploadId = RESTUtils.getAttribute(getRequest(), "uploadId");
    if (uploadId == null || uploadId.isEmpty()) {
        getResponse().setStatus(new Status(Status.CLIENT_ERROR_BAD_REQUEST, "Missing upload ID"));
        return;
    }

    try {
        if (!resumableUploadResourceManager.isUploadDone(uploadId)) {
            Long writedBytes = resumableUploadResourceManager.getWrittenBytes(uploadId);
            getResponse().setStatus(new Status(RESUME_INCOMPLETE.getCode()));
            Series<Parameter> headers = new Form();
            headers.add("Content-Length", "0");
            headers.add("Range", "0-" + (writedBytes - 1));
            getResponse().getAttributes().put("org.restlet.http.headers", headers);
        } else {
            Response response = getResponse();
            response.setStatus(Status.SUCCESS_OK);
        }
    } catch (IllegalStateException e) {
        getResponse().setStatus(new Status(Status.CLIENT_ERROR_NOT_FOUND, e.getMessage()));
        return;
    } catch (IOException e) {
        getResponse().setStatus(new Status(Status.SERVER_ERROR_INTERNAL, e.getMessage()));
        return;
    }
}

From source file:ltistarter.lti.LTITests.java

@Test
@Transactional//from w  w  w . j a v  a  2  s.co  m
public void testLTIRequest() {
    assertNotNull(ltiDataService);
    assertNotNull(ltiKeyRepository);
    assertNotNull(ltiContextRepository);
    assertNotNull(ltiLinkRepository);
    assertNotNull(ltiUserRepository);
    assertNotNull(ltiMembershipRepository);
    MockHttpServletRequest request;
    LTIRequest ltiRequest;

    LtiKeyEntity key1 = ltiKeyRepository.save(new LtiKeyEntity("AZkey", "AZsecret"));
    LtiKeyEntity key2 = ltiKeyRepository.save(new LtiKeyEntity("key", "secret"));
    LtiKeyEntity key3 = ltiKeyRepository.save(new LtiKeyEntity("3key", "secret"));
    LtiKeyEntity key4 = ltiKeyRepository.save(new LtiKeyEntity("4key", "secret"));
    LtiKeyEntity key5 = ltiKeyRepository.save(new LtiKeyEntity("5key", "secret"));

    LtiUserEntity user1 = ltiUserRepository.save(new LtiUserEntity("azeckoski", null));
    LtiUserEntity user2 = ltiUserRepository.save(new LtiUserEntity("bzeckoski", null));
    LtiUserEntity user3 = ltiUserRepository.save(new LtiUserEntity("czeckoski", null));
    LtiUserEntity user4 = ltiUserRepository.save(new LtiUserEntity("dzeckoski", null));

    LtiContextEntity context1 = ltiContextRepository
            .save(new LtiContextEntity("AZcontext", key1, "AZCtitle", null));
    LtiContextEntity context2 = ltiContextRepository
            .save(new LtiContextEntity("3context", key3, "3Ctitle", null));
    LtiContextEntity context3 = ltiContextRepository
            .save(new LtiContextEntity("5context", key5, "5Ctitle", null));

    LtiLinkEntity link1 = ltiLinkRepository.save(new LtiLinkEntity("AZlink", context1, "linkTitle"));

    LtiMembershipEntity member1 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context1, user1, LtiMembershipEntity.ROLE_STUDENT));
    LtiMembershipEntity member2 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context1, user2, LtiMembershipEntity.ROLE_STUDENT));
    LtiMembershipEntity member3 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context1, user3, LtiMembershipEntity.ROLE_INTRUCTOR));
    LtiMembershipEntity member4 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context2, user1, LtiMembershipEntity.ROLE_STUDENT));
    LtiMembershipEntity member5 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context2, user3, LtiMembershipEntity.ROLE_INTRUCTOR));

    LtiServiceEntity service11 = ltiServiceRepository.save(new LtiServiceEntity("grading", key1, "format"));
    LtiServiceEntity service12 = ltiServiceRepository.save(new LtiServiceEntity("tracking", key1, "format"));

    request = new MockHttpServletRequest(); // NOT LTI request
    try {
        ltiRequest = new LTIRequest(request);
        fail("Should have died");
    } catch (IllegalStateException e) {
        assertNotNull(e.getMessage());
    }

    request = new MockHttpServletRequest(); // LTI request (minimal)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    ltiRequest = new LTIRequest(request);
    assertFalse(ltiRequest.isComplete());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNull(ltiRequest.getKey()); // not loaded yet
    boolean loaded = ltiDataService.loadLTIDataFromDB(ltiRequest); // load up the data
    assertTrue(loaded);
    assertNotNull(ltiRequest.getKey());
    assertEquals(key1, ltiRequest.getKey());

    request = new MockHttpServletRequest(); // LTI request (full)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, context1.getContextKey());
    request.setParameter(LTIRequest.LTI_LINK_ID, link1.getLinkKey());
    request.setParameter(LTIRequest.LTI_USER_ID, user1.getUserKey());
    ltiRequest = new LTIRequest(request, ltiDataService, false);
    assertTrue(ltiRequest.isLoaded());
    assertTrue(ltiRequest.isComplete());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertEquals(key1, ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNotNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getLtiUserId());
    assertNotNull(ltiRequest.getMembership());
    assertNull(ltiRequest.getService());
    assertNull(ltiRequest.getResult());

    request = new MockHttpServletRequest(); // LTI request (gaps)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, context1.getContextKey());
    request.setParameter(LTIRequest.LTI_LINK_ID, "invalid_link");
    request.setParameter(LTIRequest.LTI_USER_ID, user1.getUserKey());
    request.setParameter(LTIRequest.LTI_SOURCEDID, "invalid_sourcedid");
    request.setParameter(LTIRequest.LTI_SERVICE, service11.getServiceKey());
    ltiRequest = new LTIRequest(request, ltiDataService, false);
    assertTrue(ltiRequest.isLoaded());
    assertFalse(ltiRequest.isComplete()); // missing the link
    assertFalse(ltiRequest.isUpdated());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getLtiUserId());
    assertNotNull(ltiRequest.getMembership());
    assertNull(ltiRequest.getResult());
    assertNotNull(ltiRequest.getService());

    // testing updating existing data
    request = new MockHttpServletRequest(); // LTI request (gaps)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, context1.getContextKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_TITLE, "AZ context 1");
    request.setParameter(LTIRequest.LTI_LINK_ID, link1.getLinkKey());
    request.setParameter(LTIRequest.LTI_LINK_TITLE, "AZ link 1");
    request.setParameter(LTIRequest.LTI_USER_ID, user1.getUserKey());
    request.setParameter(LTIRequest.LTI_USER_NAME_FULL, "Aaron Zeckoski");
    request.setParameter(LTIRequest.LTI_USER_EMAIL, "azeckoski@fake.email.com");
    request.setParameter(LTIRequest.LTI_USER_ROLES, "Administrator,Instructor,Learner");
    request.setParameter(LTIRequest.LTI_SOURCEDID, "new_sourcedid_AZ");
    request.setParameter(LTIRequest.LTI_SERVICE, service11.getServiceKey());
    ltiRequest = new LTIRequest(request, ltiDataService, true);
    assertTrue(ltiRequest.isLoaded());
    assertTrue(ltiRequest.isComplete());
    assertTrue(ltiRequest.isUpdated());
    assertEquals(2, ltiRequest.getUserRoleNumber());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNotNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getUser());
    assertNotNull(ltiRequest.getMembership());
    assertNotNull(ltiRequest.getResult());
    assertNotNull(ltiRequest.getService());

    // testing inserting all new data (except key of course)
    request = new MockHttpServletRequest(); // LTI request (gaps)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key5.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, "context 5555");
    request.setParameter(LTIRequest.LTI_CONTEXT_TITLE, "AZ context 5555");
    request.setParameter(LTIRequest.LTI_LINK_ID, "link 5555");
    request.setParameter(LTIRequest.LTI_LINK_TITLE, "AZ link 5555");
    request.setParameter(LTIRequest.LTI_USER_ID, "rzeckoski");
    request.setParameter(LTIRequest.LTI_USER_NAME_FULL, "Rebecca Zeckoski");
    request.setParameter(LTIRequest.LTI_USER_EMAIL, "rzeckoski@fake.email.com");
    request.setParameter(LTIRequest.LTI_USER_ROLES,
            "Mentor/Advisor,Instructor/GuestInstructor,TeachingAssistant/TeachingAssistant");
    request.setParameter(LTIRequest.LTI_SOURCEDID, "RZ_new_sourcedid");
    request.setParameter(LTIRequest.LTI_SERVICE, "RZ_grading");
    ltiRequest = new LTIRequest(request, ltiDataService, true);
    assertTrue(ltiRequest.isLoaded());
    assertTrue(ltiRequest.isComplete());
    assertTrue(ltiRequest.isUpdated());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNotNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getUser());
    assertNotNull(ltiRequest.getMembership());
    assertNotNull(ltiRequest.getResult());
    assertNotNull(ltiRequest.getService());
}

From source file:ltistarter.LTITests.java

@Test
@Transactional/*from   w  ww.j  a v a2s .c  o  m*/
public void testLTIRequest() {
    assertNotNull(allRepositories);
    assertNotNull(ltiKeyRepository);
    assertNotNull(ltiContextRepository);
    assertNotNull(ltiLinkRepository);
    assertNotNull(ltiUserRepository);
    assertNotNull(ltiMembershipRepository);
    MockHttpServletRequest request;
    LTIRequest ltiRequest;

    LtiKeyEntity key1 = ltiKeyRepository.save(new LtiKeyEntity("AZkey", "AZsecret"));
    LtiKeyEntity key2 = ltiKeyRepository.save(new LtiKeyEntity("key", "secret"));
    LtiKeyEntity key3 = ltiKeyRepository.save(new LtiKeyEntity("3key", "secret"));
    LtiKeyEntity key4 = ltiKeyRepository.save(new LtiKeyEntity("4key", "secret"));
    LtiKeyEntity key5 = ltiKeyRepository.save(new LtiKeyEntity("5key", "secret"));

    LtiUserEntity user1 = ltiUserRepository.save(new LtiUserEntity("azeckoski", null));
    LtiUserEntity user2 = ltiUserRepository.save(new LtiUserEntity("bzeckoski", null));
    LtiUserEntity user3 = ltiUserRepository.save(new LtiUserEntity("czeckoski", null));
    LtiUserEntity user4 = ltiUserRepository.save(new LtiUserEntity("dzeckoski", null));

    LtiContextEntity context1 = ltiContextRepository
            .save(new LtiContextEntity("AZcontext", key1, "AZCtitle", null));
    LtiContextEntity context2 = ltiContextRepository
            .save(new LtiContextEntity("3context", key3, "3Ctitle", null));
    LtiContextEntity context3 = ltiContextRepository
            .save(new LtiContextEntity("5context", key5, "5Ctitle", null));

    LtiLinkEntity link1 = ltiLinkRepository.save(new LtiLinkEntity("AZlink", context1, "linkTitle"));

    LtiMembershipEntity member1 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context1, user1, LtiMembershipEntity.ROLE_STUDENT));
    LtiMembershipEntity member2 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context1, user2, LtiMembershipEntity.ROLE_STUDENT));
    LtiMembershipEntity member3 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context1, user3, LtiMembershipEntity.ROLE_INTRUCTOR));
    LtiMembershipEntity member4 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context2, user1, LtiMembershipEntity.ROLE_STUDENT));
    LtiMembershipEntity member5 = ltiMembershipRepository
            .save(new LtiMembershipEntity(context2, user3, LtiMembershipEntity.ROLE_INTRUCTOR));

    LtiServiceEntity service11 = ltiServiceRepository.save(new LtiServiceEntity("grading", key1, "format"));
    LtiServiceEntity service12 = ltiServiceRepository.save(new LtiServiceEntity("tracking", key1, "format"));

    request = new MockHttpServletRequest(); // NOT LTI request
    try {
        ltiRequest = new LTIRequest(request);
        fail("Should have died");
    } catch (IllegalStateException e) {
        assertNotNull(e.getMessage());
    }

    request = new MockHttpServletRequest(); // LTI request (minimal)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    ltiRequest = new LTIRequest(request);
    assertFalse(ltiRequest.isComplete());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNull(ltiRequest.getKey()); // not loaded yet
    boolean loaded = ltiRequest.loadLTIDataFromDB(allRepositories); // load up the data
    assertTrue(loaded);
    assertNotNull(ltiRequest.getKey());
    assertEquals(key1, ltiRequest.getKey());

    request = new MockHttpServletRequest(); // LTI request (full)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, context1.getContextKey());
    request.setParameter(LTIRequest.LTI_LINK_ID, link1.getLinkKey());
    request.setParameter(LTIRequest.LTI_USER_ID, user1.getUserKey());
    ltiRequest = new LTIRequest(request, allRepositories, false);
    assertTrue(ltiRequest.isLoaded());
    assertTrue(ltiRequest.isComplete());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertEquals(key1, ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNotNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getLtiUserId());
    assertNotNull(ltiRequest.getMembership());
    assertNull(ltiRequest.getService());
    assertNull(ltiRequest.getResult());

    request = new MockHttpServletRequest(); // LTI request (gaps)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, context1.getContextKey());
    request.setParameter(LTIRequest.LTI_LINK_ID, "invalid_link");
    request.setParameter(LTIRequest.LTI_USER_ID, user1.getUserKey());
    request.setParameter(LTIRequest.LTI_SOURCEDID, "invalid_sourcedid");
    request.setParameter(LTIRequest.LTI_SERVICE, service11.getServiceKey());
    ltiRequest = new LTIRequest(request, allRepositories, false);
    assertTrue(ltiRequest.isLoaded());
    assertFalse(ltiRequest.isComplete()); // missing the link
    assertFalse(ltiRequest.isUpdated());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getLtiUserId());
    assertNotNull(ltiRequest.getMembership());
    assertNull(ltiRequest.getResult());
    assertNotNull(ltiRequest.getService());

    // testing updating existing data
    request = new MockHttpServletRequest(); // LTI request (gaps)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key1.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, context1.getContextKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_TITLE, "AZ context 1");
    request.setParameter(LTIRequest.LTI_LINK_ID, link1.getLinkKey());
    request.setParameter(LTIRequest.LTI_LINK_TITLE, "AZ link 1");
    request.setParameter(LTIRequest.LTI_USER_ID, user1.getUserKey());
    request.setParameter(LTIRequest.LTI_USER_NAME_FULL, "Aaron Zeckoski");
    request.setParameter(LTIRequest.LTI_USER_EMAIL, "azeckoski@fake.email.com");
    request.setParameter(LTIRequest.LTI_USER_ROLES, "Administrator,Instructor,Learner");
    request.setParameter(LTIRequest.LTI_SOURCEDID, "new_sourcedid_AZ");
    request.setParameter(LTIRequest.LTI_SERVICE, service11.getServiceKey());
    ltiRequest = new LTIRequest(request, allRepositories, true);
    assertTrue(ltiRequest.isLoaded());
    assertTrue(ltiRequest.isComplete());
    assertTrue(ltiRequest.isUpdated());
    assertEquals(2, ltiRequest.getUserRoleNumber());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNotNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getUser());
    assertNotNull(ltiRequest.getMembership());
    assertNotNull(ltiRequest.getResult());
    assertNotNull(ltiRequest.getService());

    // testing inserting all new data (except key of course)
    request = new MockHttpServletRequest(); // LTI request (gaps)
    request.setParameter(LTIRequest.LTI_VERSION, LTIRequest.LTI_VERSION_1P0);
    request.setParameter(LTIRequest.LTI_MESSAGE_TYPE, LTIRequest.LTI_MESSAGE_TYPE_BASIC);
    request.setParameter(LTIRequest.LTI_CONSUMER_KEY, key5.getKeyKey());
    request.setParameter(LTIRequest.LTI_CONTEXT_ID, "context 5555");
    request.setParameter(LTIRequest.LTI_CONTEXT_TITLE, "AZ context 5555");
    request.setParameter(LTIRequest.LTI_LINK_ID, "link 5555");
    request.setParameter(LTIRequest.LTI_LINK_TITLE, "AZ link 5555");
    request.setParameter(LTIRequest.LTI_USER_ID, "rzeckoski");
    request.setParameter(LTIRequest.LTI_USER_NAME_FULL, "Rebecca Zeckoski");
    request.setParameter(LTIRequest.LTI_USER_EMAIL, "rzeckoski@fake.email.com");
    request.setParameter(LTIRequest.LTI_USER_ROLES,
            "Mentor/Advisor,Instructor/GuestInstructor,TeachingAssistant/TeachingAssistant");
    request.setParameter(LTIRequest.LTI_SOURCEDID, "RZ_new_sourcedid");
    request.setParameter(LTIRequest.LTI_SERVICE, "RZ_grading");
    ltiRequest = new LTIRequest(request, allRepositories, true);
    assertTrue(ltiRequest.isLoaded());
    assertTrue(ltiRequest.isComplete());
    assertTrue(ltiRequest.isUpdated());
    assertNotNull(ltiRequest.getLtiVersion());
    assertNotNull(ltiRequest.getLtiMessageType());
    assertNotNull(ltiRequest.getLtiConsumerKey());
    assertNotNull(ltiRequest.getKey());
    assertNotNull(ltiRequest.getContext());
    assertNotNull(ltiRequest.getLink());
    assertNotNull(ltiRequest.getUser());
    assertNotNull(ltiRequest.getMembership());
    assertNotNull(ltiRequest.getResult());
    assertNotNull(ltiRequest.getService());
}

From source file:com.microsoft.tfs.util.shutdown.ShutdownManager.java

/**
 * Instructs all registered listeners to shutdown.
 * <p>/*  w ww  .  j av a  2 s . c o m*/
 * Using the shutdown manager for the first time causes it to establish a
 * link with the Java virtual machine that ensures it will be invoked during
 * JVM shutdown. However, when an application exits normally, the shutdown
 * hooks may not be called. Applications that use {@link ShutdownManager}
 * should call {@link #shutdown()} directly as part of their application
 * exit procedure to ensure all listeners are invoked before the JVM exits.
 */
public synchronized void shutdown() {
    log.debug("shutdown"); //$NON-NLS-1$

    /*
     * This method is synchronized on this class instance so shutdown event
     * listeners can unregister themselves from the shutdown manager and
     * guarantee they won't be called again.
     */

    try {
        ((ShutdownEventListener) earlyListeners.getListener()).onShutdown();
    } catch (final IllegalStateException e) {
        /*
         * Suppress the error in case the build has been already unloaded
         * some bundles
         */
        log.warn(e.getMessage());
    }

    try {
        ((ShutdownEventListener) middleListeners.getListener()).onShutdown();
    } catch (final IllegalStateException e) {
        /*
         * Suppress the error in case the build has been already unloaded
         * some bundles
         */
        log.warn(e.getMessage());
    }

    try {
        ((ShutdownEventListener) lateListeners.getListener()).onShutdown();
    } catch (final IllegalStateException e) {
        /*
         * Suppress the error in case the build has been already unloaded
         * some bundles
         */
        log.warn(e.getMessage());
    }
}

From source file:com.globo.galeb.server.ServerResponse.java

/**
 * Show error and finish connection (and close, if necessary).
 *
 * @param event the event/exception/* w  ww  .  j a  v  a 2 s .c  o m*/
 */
public void showErrorAndClose(final Throwable event) {

    int statusCode = exceptionToHttpCode(event);
    setStatusCode(statusCode);

    String headerHost = getHeaderHost();

    String logMessage = String.format("FAIL with HttpStatus %d%s: %s", statusCode,
            !"".equals(headerHost) ? String.format(" (virtualhost: %s)", headerHost) : "",
            HttpCode.getMessage(statusCode, false));

    defineLoggerIfNecessary();
    if (statusCode >= HttpCode.INTERNAL_SERVER_ERROR) {
        log.error(logMessage);
        log.debug(getStackTrace(event));
    } else {
        log.warn(logMessage);
    }

    endResponse();

    try {
        closeResponse();
    } catch (IllegalStateException e) {
        // Response has already been finish?
        log.debug(e.getMessage());
    } catch (RuntimeException e2) {
        log.error(String.format("FAIL: statusCode %d, Error > %s", resp.getStatusCode(), e2.getMessage()));
    }
}

From source file:com.ebay.pulsar.analytics.cache.MemcachedCache.java

@Override
public void put(NamedKey key, byte[] value, int expiration) {
    try {/*from w ww.  j a v a2s.  c  o m*/
        putBytes.addAndGet(value.length);
        putCount.incrementAndGet();
        client.set(computeKeyHash(memcachedPrefix, key), expiration, serializeValue(key, value));
    } catch (IllegalStateException e) {
        // operation did not get queued in time (queue is full)
        errorCount.incrementAndGet();
        logger.warn("Unable to queue cache operation: " + e.getMessage());
    }
}

From source file:org.datacleaner.panels.DatabaseDriversPanel.java

private ActionListener createDownloadActionListener(final DatabaseDriverDescriptor dd) {
    final FileDownloadListener downloadListener = new FileDownloadListener() {
        @Override//ww  w .j av  a  2 s  .  c  o  m
        public void onFilesDownloaded(FileObject[] files) {
            final String driverClassName = dd.getDriverClassName();

            logger.info("Registering and loading driver '{}' in files '{}'", driverClassName, files);

            final UserDatabaseDriver userDatabaseDriver = new UserDatabaseDriver(files, driverClassName);
            _userPreferences.getDatabaseDrivers().add(userDatabaseDriver);

            try {
                userDatabaseDriver.loadDriver();
            } catch (IllegalStateException e) {
                WidgetUtils.showErrorMessage("Error while loading driver", "Error message: " + e.getMessage(),
                        e);
            }
            updateDriverList();
        }
    };

    final WebServiceHttpClient httpClient = new SimpleWebServiceHttpClient(_httpClient);
    return new DownloadFilesActionListener(dd.getDownloadUrls(), downloadListener, _windowContext, httpClient,
            _userPreferences);
}

From source file:com.github.alexfalappa.nbspringboot.codegen.InjectSpringBootGenerator.java

private void addDeps(String bootVersion, final Set<String> selectedDeps) throws Exception {
    logger.log(Level.INFO, "Adding Spring Boot dependencies: {0}", selectedDeps.toString());
    JsonNode depsMeta = InitializrService.getInstance().getDependencies(bootVersion);
    Iterator<Map.Entry<String, JsonNode>> it = depsMeta.path("dependencies").fields();
    int newPos = component.getCaretPosition();
    try {/* w w w  . j a va 2  s .  c  o  m*/
        if (model.startTransaction()) {
            DependencyContainer container = model.getProject();
            // iterate on "dependencies" JSON object (fields are dependency ids)
            while (it.hasNext()) {
                Map.Entry<String, JsonNode> entry = it.next();
                if (selectedDeps.contains(entry.getKey())) {
                    JsonNode depInfo = entry.getValue();
                    String groupId = depInfo.path("groupId").asText();
                    String artifactId = depInfo.path("artifactId").asText();
                    String scope = depInfo.path("scope").asText();
                    Dependency dep = container.findDependencyById(groupId, artifactId, null);
                    if (dep == null) {
                        dep = model.getFactory().createDependency();
                        dep.setGroupId(groupId);
                        dep.setArtifactId(artifactId);
                        // set scope only if not 'compile'
                        if (!scope.equals("compile")) {
                            if (scope.equals("compileOnly")) {
                                dep.setOptional(Boolean.TRUE);
                            } else {
                                // scope is 'runtime' or 'test'
                                dep.setScope(scope);
                            }
                        }
                        // manage optional version
                        if (depInfo.hasNonNull("version")) {
                            dep.setVersion(depInfo.get("version").asText());
                        }
                        // manage optional need of extra repository
                        if (depInfo.hasNonNull("repository")) {
                            addRepository(depsMeta, depInfo.get("repository").asText());
                            addPluginRepository(depsMeta, depInfo.get("repository").asText());
                        }
                        // manage optional need of BOM inclusion
                        if (depInfo.hasNonNull("bom")) {
                            addBom(depsMeta, depInfo.get("bom").asText());
                        }
                        container.addDependency(dep);
                        newPos = model.getAccess().findPosition(dep.getPeer());
                    }
                }
            }
        }
    } finally {
        try {
            model.endTransaction();
        } catch (IllegalStateException ex) {
            StatusDisplayer.getDefault().setStatusText("Cannot write to the model: " + ex.getMessage(),
                    StatusDisplayer.IMPORTANCE_ERROR_HIGHLIGHT);
        }
    }
    component.setCaretPosition(newPos);
}