Example usage for org.apache.commons.lang3.exception ExceptionUtils getMessage

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getMessage

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getMessage.

Prototype

public static String getMessage(final Throwable th) 

Source Link

Document

Gets a short message summarising the exception.

Usage

From source file:com.baasbox.controllers.Social.java

/**
 * This method is a common callback for all oauth
 * providers.It isn't annotated with a Filter because
 * social networks callback requests couldn't pass the 
 * auth headers needed by baasbox.//w w w  .jav a 2  s. com
 * @param socialNetwork
 * @return
 */
public static Result callback(String socialNetwork) {
    try {
        SocialLoginService sc = SocialLoginService.by(socialNetwork, (String) ctx().args.get("appcode"));
        Token t = sc.requestAccessToken(request(), session());
        return ok("{\"" + OAUTH_TOKEN + "\":\"" + t.getToken() + "\",\"" + OAUTH_SECRET + "\":\""
                + t.getSecret() + "\"}");
    } catch (UnsupportedSocialNetworkException e) {
        return badRequest(ExceptionUtils.getMessage(e));
    } catch (java.lang.IllegalArgumentException e) {
        return badRequest(ExceptionUtils.getMessage(e));
    }
}

From source file:DocumentSerializationTest.java

@Test
public void createWithVersion() {
    running(getFakeApplication(), new Runnable() {
        public void run() {
            try {
                Result result = createDocumentWithVersion(getRouteAddress(collectionName));
                assertRoute(result, "createWithVersion CREATE", Status.BAD_REQUEST,
                        "UpdateOldVersionException: Are you trying to create a document with a @version field?",
                        true);//  w ww . java 2s.  c  o m
            } catch (Exception e) {
                assertFail(ExceptionUtils.getMessage(e));
            }
        }
    });
}

From source file:com.baasbox.commands.CollectionsResource.java

private static JsonNode createCollection(JsonNode command) throws CommandException {
    checkPreconditions(command, true);/*from w w  w. j  a v a2 s. co  m*/
    String coll = extractCollectionName(command);
    try {
        CollectionService.create(coll);
        return BooleanNode.getTrue();
    } catch (CollectionAlreadyExistsException e) {
        return BooleanNode.getFalse();
    } catch (InvalidCollectionException e) {
        throw new CommandExecutionException(command,
                "Invalid collection name: " + ExceptionUtils.getMessage(e));
    } catch (Throwable e) {
        throw new CommandExecutionException(command,
                "Error creating collection: " + ExceptionUtils.getMessage(e));
    }
}

From source file:com.hpe.caf.worker.testing.ProcessorDeliveryHandler.java

private String buildFailedMessage(TestItem testItem, Throwable throwable) {
    StringBuilder sb = new StringBuilder();
    sb.append("Test case failed.");
    TestCaseInfo info = testItem.getTestCaseInformation();
    if (info != null) {
        sb.append(" Test case id: " + info.getTestCaseId());
        sb.append("\nTest case description: " + info.getDescription());
        sb.append("\nTest case comments: " + info.getComments());
        sb.append("\nTest case associated tickets: " + info.getAssociatedTickets());
        sb.append("\n");
    }//w w w .j  a v a2 s.com
    sb.append("Message: " + ExceptionUtils.getMessage(throwable));
    sb.append("\n");
    sb.append("Root cause message: " + ExceptionUtils.getRootCauseMessage(throwable));

    sb.append("\nStack trace:\n");
    sb.append(ExceptionUtils.getStackTrace(throwable));
    return sb.toString();
}

From source file:com.baasbox.controllers.ScriptsAdmin.java

@BodyParser.Of(BodyParser.Json.class)
public static Result create() {
    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Start Method");
    Http.Request req = request();
    BaasBoxLogger.debug("Creating a new plugin. Received {}", req.toString());
    JsonNode body = req.body().asJson();
    Result result;/*  w  ww . java  2 s.  com*/
    try {
        validateBody(body);
        ScriptStatus res = ScriptingService.create(body);
        if (res.ok) {
            result = created(res.message);
        } else {
            // todo check return code
            result = ok(res.message);
        }
    } catch (ScriptAlreadyExistsException e) {
        result = badRequest(ExceptionUtils.getMessage(e));
    } catch (ScriptException e) {
        String message = ExceptionUtils.getMessage(e);

        result = badRequest(message == null ? "Script error" : message);
    }

    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("End Method");
    return result;
}

From source file:cc.sion.core.utils.Exceptions.java

/**
 *  ??: ?./*from ww w  .  j a  v  a 2s  .  c  om*/
 *
 * Throwable.toString()??
 *
 * @see ExceptionUtils#getMessage(Throwable)
 */
public static String toStringWithShortName(@Nullable Throwable t) {
    return ExceptionUtils.getMessage(t);
}

From source file:com.baasbox.commands.PushResource.java

private JsonNode sendMessage(JsonNode command, JsonCallback callback) throws CommandException {
    JsonNode params = command.get(ScriptCommand.PARAMS);
    if (params == null || !params.isObject()) {
        throw new CommandParsingException(command, "missing parameters");
    }//from   w w w .  ja va2 s . c o m

    JsonNode body = params.get("body");
    if (body == null || !body.isObject()) {
        throw new CommandParsingException(command, "missing body object parameter");
    }
    JsonNode messageNode = body.get("message");
    if (messageNode == null || !messageNode.isTextual()) {
        throw new CommandParsingException(command, "missing message text parameter");
    }
    String message = messageNode.asText();

    List<String> users = new ArrayList<>();
    JsonNode usersNode = params.get("to");
    if (usersNode == null || !usersNode.isArray()) {
        throw new CommandParsingException(command, "missing required to parameter");
    }
    ArrayNode usrAry = (ArrayNode) usersNode;
    usrAry.forEach(j -> {
        if (j == null || !j.isTextual())
            return;
        users.add(j.asText());
    });

    JsonNode profilesNode = params.get("profiles");
    List<Integer> profiles;
    if (profilesNode == null) {
        profiles = Collections.singletonList(1);
    } else if (profilesNode.isArray()) {
        ArrayNode pAry = (ArrayNode) profilesNode;
        profiles = new ArrayList<>();
        pAry.forEach((j) -> {
            if (j == null || !j.isIntegralNumber())
                return;
            profiles.add(j.asInt());
        });
    } else {
        throw new CommandParsingException(command, "wrong profiles parameter");
    }

    boolean[] errors = new boolean[users.size()];
    PushService ps = new PushService();

    try {
        ps.send(message, users, profiles, body, errors);
        Json.ObjectMapperExt mapper = Json.mapper();
        boolean someOk = false;
        boolean someFail = false;
        for (boolean error : errors) {
            if (error)
                someFail = true;
            else
                someOk = true;
        }
        if (someFail && someOk) {
            return IntNode.valueOf(1);
        } else if (someFail) {
            return IntNode.valueOf(2);
        } else {
            return IntNode.valueOf(0);
        }
    } catch (Exception e) {
        throw new CommandExecutionException(command, ExceptionUtils.getMessage(e), e);
    }
}

From source file:com.baasbox.controllers.Push.java

public static Result send(String username) throws Exception {
    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method Start");
    Http.RequestBody body = request().body();
    JsonNode bodyJson = body.asJson(); //{"message":"Text"}
    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("send bodyJson: " + bodyJson);
    if (bodyJson == null)
        return status(CustomHttpCode.JSON_PAYLOAD_NULL.getBbCode(),
                CustomHttpCode.JSON_PAYLOAD_NULL.getDescription());
    JsonNode messageNode = bodyJson.findValue("message");
    if (messageNode == null)
        return status(CustomHttpCode.PUSH_MESSAGE_INVALID.getBbCode(),
                CustomHttpCode.PUSH_MESSAGE_INVALID.getDescription());
    if (!messageNode.isTextual())
        return status(CustomHttpCode.PUSH_MESSAGE_INVALID.getBbCode(),
                CustomHttpCode.PUSH_MESSAGE_INVALID.getDescription());

    String message = messageNode.asText();

    List<String> usernames = new ArrayList<String>();
    usernames.add(username);/* w  ww.  ja  v  a2 s  . c o  m*/

    JsonNode pushProfilesNodes = bodyJson.get("profiles");

    List<Integer> pushProfiles = new ArrayList<Integer>();
    if (!(pushProfilesNodes == null)) {
        if (!(pushProfilesNodes.isArray()))
            return status(CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getBbCode(),
                    CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getDescription());
        for (JsonNode pushProfileNode : pushProfilesNodes) {
            pushProfiles.add(pushProfileNode.asInt());
        }
    } else {
        pushProfiles.add(1);
    }
    boolean[] withError = new boolean[6];
    PushService ps = new PushService();
    try {
        if (ps.validate(pushProfiles))
            withError = ps.send(message, usernames, pushProfiles, bodyJson, withError);
    } catch (UserNotFoundException e) {
        BaasBoxLogger.error("Username not found " + username, e);
        return notFound("Username not found");
    } catch (SqlInjectionException e) {
        return badRequest("the supplied name appears invalid (Sql Injection Attack detected)");
    } catch (PushNotInitializedException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_CONFIG_INVALID.getBbCode(),
                CustomHttpCode.PUSH_CONFIG_INVALID.getDescription());
    } catch (PushProfileDisabledException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_PROFILE_DISABLED.getBbCode(),
                CustomHttpCode.PUSH_PROFILE_DISABLED.getDescription());
    } catch (PushProfileInvalidException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_PROFILE_FORMAT_INVALID.getDescription());
    } catch (UnknownHostException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_HOST_UNREACHABLE.getBbCode(),
                CustomHttpCode.PUSH_HOST_UNREACHABLE.getDescription());
    } catch (InvalidRequestException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_INVALID_REQUEST.getBbCode(),
                CustomHttpCode.PUSH_INVALID_REQUEST.getDescription());
    } catch (PushSoundKeyFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_SOUND_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_SOUND_FORMAT_INVALID.getDescription());
    } catch (PushBadgeFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_BADGE_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_BADGE_FORMAT_INVALID.getDescription());
    } catch (PushActionLocalizedKeyFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_ACTION_LOCALIZED_KEY_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_ACTION_LOCALIZED_KEY_FORMAT_INVALID.getDescription());
    } catch (PushLocalizedKeyFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_LOCALIZED_KEY_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_LOCALIZED_ARGUMENTS_FORMAT_INVALID.getDescription());
    } catch (PushLocalizedArgumentsFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_LOCALIZED_ARGUMENTS_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_LOCALIZED_ARGUMENTS_FORMAT_INVALID.getDescription());
    } catch (PushCollapseKeyFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_COLLAPSE_KEY_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_COLLAPSE_KEY_FORMAT_INVALID.getDescription());
    } catch (PushTimeToLiveFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_TIME_TO_LIVE_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_TIME_TO_LIVE_FORMAT_INVALID.getDescription());
    } catch (PushContentAvailableFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_CONTENT_AVAILABLE_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_CONTENT_AVAILABLE_FORMAT_INVALID.getDescription());
    } catch (PushCategoryFormatException e) {
        BaasBoxLogger.error(ExceptionUtils.getMessage(e));
        return status(CustomHttpCode.PUSH_CATEGORY_FORMAT_INVALID.getBbCode(),
                CustomHttpCode.PUSH_CATEGORY_FORMAT_INVALID.getDescription());
    }
    if (BaasBoxLogger.isTraceEnabled())
        BaasBoxLogger.trace("Method End");
    for (int i = 0; i < withError.length; i++) {
        if (withError[i] == true)
            return status(CustomHttpCode.PUSH_SENT_WITH_ERROR.getBbCode(),
                    CustomHttpCode.PUSH_SENT_WITH_ERROR.getDescription());
    }
    return ok();
}

From source file:DocumentSerializationTest.java

@Test
public void testCreateDocumentWithJustCollection() {
    running(getFakeApplication(), new Runnable() {
        public void run() {
            try {
                Result result = createDocumentWithJustCollection(getRouteAddress(collectionName));
                assertRoute(result, "testCreateDocumentWithJustCollection CREATE", Status.BAD_REQUEST,
                        ERROR_MESSAGE, true);
            } catch (Exception e) {
                assertFail(ExceptionUtils.getMessage(e));
            }//  w  w  w.j  av a  2  s. c o  m
        }
    });
}

From source file:DocumentSerializationTest.java

@Test
public void testCreateDocumentWithJustOneElement() {
    running(getFakeApplication(), new Runnable() {
        public void run() {
            try {
                Result result = createDocumentWithJustOneElement(getRouteAddress(collectionName));
                assertRoute(result, "testCreateDocumentWithJustOneElement CREATE", Status.BAD_REQUEST,
                        ERROR_MESSAGE, true);
            } catch (Exception e) {
                assertFail(ExceptionUtils.getMessage(e));
            }/*from  ww w  . ja va  2s . co m*/
        }
    });
}