Example usage for org.apache.commons.lang NullArgumentException getMessage

List of usage examples for org.apache.commons.lang NullArgumentException getMessage

Introduction

In this page you can find the example usage for org.apache.commons.lang NullArgumentException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.usergrid.rest.management.organizations.OrganizationResource.java

@POST
@Path("export")
@Consumes(APPLICATION_JSON)/*w w w .  j  a  v  a2  s.c  o m*/
@RequireOrganizationAccess
public Response exportPostJson(@Context UriInfo ui, Map<String, Object> json,
        @QueryParam("callback") @DefaultValue("") String callback) throws OAuthSystemException {

    if (logger.isTraceEnabled()) {
        logger.trace("executePostJson");
    }

    Map<String, String> uuidRet = new HashMap<>();

    try {
        Object propertiesObj = json.get("properties");
        if (propertiesObj == null) {
            throw new NullArgumentException("Could not find 'properties'");
        }
        if (!(propertiesObj instanceof Map)) {
            throw new IllegalArgumentException("'properties' not a map");
        }

        @SuppressWarnings("unchecked")
        Map<String, Object> properties = (Map<String, Object>) propertiesObj;

        String storage_provider = (String) properties.get("storage_provider");
        if (storage_provider == null) {
            throw new NullArgumentException("Could not find field 'storage_provider'");
        }

        Object storageInfoObj = properties.get("storage_info");
        if (storageInfoObj == null) {
            throw new NullArgumentException("Could not find field 'storage_info'");
        }
        @SuppressWarnings("unchecked")
        Map<String, Object> storage_info = (Map<String, Object>) storageInfoObj;

        String bucketName = (String) storage_info.get("bucket_location");
        String accessId = (String) storage_info.get("s3_access_id");
        String secretKey = (String) storage_info.get("s3_key");

        if (bucketName == null) {
            throw new NullArgumentException("Could not find field 'bucketName'");
        }
        if (accessId == null) {
            throw new NullArgumentException("Could not find field 's3_access_id'");
        }
        if (secretKey == null) {

            throw new NullArgumentException("Could not find field 's3_key'");
        }

        json.put("organizationId", organization.getUuid());

        UUID jobUUID = exportService.schedule(json);
        uuidRet.put("Export Entity", jobUUID.toString());
    } catch (NullArgumentException e) {
        return Response.status(SC_BAD_REQUEST).type(JSONPUtils.jsonMediaType(callback))
                .entity(ServiceResource.wrapWithCallback(e.getMessage(), callback)).build();
    } catch (Exception e) {
        //TODO:throw descriptive error message and or include on in the response
        //TODO:fix below, it doesn't work if there is an exception. Make it look like the OauthResponse.
        return Response.status(SC_INTERNAL_SERVER_ERROR).type(JSONPUtils.jsonMediaType(callback))
                .entity(ServiceResource.wrapWithCallback(e.getMessage(), callback)).build();
    }
    return Response.status(SC_ACCEPTED).entity(uuidRet).build();
}

From source file:org.apache.zeppelin.interpreter.InterpreterFactoryTest.java

@Test
public void testExceptions() throws IOException {
    List<String> all = factory.getDefaultInterpreterSettingList();
    // add setting with null option & properties expected nullArgumentException.class
    try {//from  w ww.  j  av  a2 s  .c o m
        factory.add("a mock", "mock2", null, new Properties());
    } catch (NullArgumentException e) {
        assertEquals("Test null option", e.getMessage(), new NullArgumentException("option").getMessage());
    }
    try {
        factory.add("a mock", "mock2", new InterpreterOption(false), null);
    } catch (NullArgumentException e) {
        assertEquals("Test null properties", e.getMessage(),
                new NullArgumentException("properties").getMessage());
    }
}