List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getMessage
public static String getMessage(final Throwable th)
From source file:com.ebay.logstorm.server.services.impl.PipelineExecutionServiceImpl.java
@Override public PipelineEntity start(PipelineEntity pipeline) throws Exception { if (!PipelineExecutionStatus.isReadyToStart(pipeline.getStatus())) { throw new RuntimeException( pipeline.getName() + " is not ready to start (" + pipeline.getStatus() + ")"); }//from w ww .j a v a 2 s . c o m checkInitExecutionContext(pipeline); for (PipelineExecutionEntity executor : pipeline.getInstances()) { boolean readyToStart = PipelineExecutionStatus.isReadyToStart(executor.getStatus()); if (!readyToStart) { throw new PipelineExecutionException( pipeline + " is not ready to start, executor " + executor.getName() + " is still running"); } } pipeline.getInstances().stream().map((executor) -> ExecutionManager.getInstance().submit(() -> { try { executor.setStatus(PipelineExecutionStatus.STARTING); updateExecutionEntity(executor); pipeline.getCluster().getPlatformInstance().start(executor); executor.setStatus(PipelineExecutionStatus.RUNNING); updateExecutionEntity(executor); } catch (Throwable ex) { executor.setStatus(PipelineExecutionStatus.FAILED); executor.setDescription(ExceptionUtils.getMessage(ex)); updateExecutionEntity(executor); LOG.error(ex.getMessage(), ex); // throw new RuntimeException(ex); } })).forEach((future -> { try { future.get(); } catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } })); entityService.updatePipeline(pipeline); return pipeline; }
From source file:com.baasbox.dao.UserDao.java
public OUser getOUserByUsername(String username) { ODocument user = null;/*from ww w . j a va 2s. co m*/ try { user = getByUserName(username); if (user == null) return null; } catch (SqlInjectionException e) { BaasBoxLogger.debug(ExceptionUtils.getMessage(e)); throw new RuntimeException(e); } return new OUser((ODocument) user.field("user")); }
From source file:DocumentSerializationTest.java
@Test public void testCreateDocumentWithJustOneElementAsString() { running(getFakeApplication(), new Runnable() { public void run() { try { Result result = createDocumentWithJustOneElementAsString(getRouteAddress(collectionName)); assertRoute(result, "testCreateDocumentWithJustOneElementAsString CREATE", Status.BAD_REQUEST, ERROR_MESSAGE, true); } catch (Exception e) { assertFail(ExceptionUtils.getMessage(e)); }/*from w ww. j a v a 2 s. c o m*/ } }); }
From source file:com.baasbox.service.dbmanager.DbManagerService.java
public static void importDb(String appcode, ZipInputStream zis) throws FileFormatException, Exception { File newFile = null;/*from w w w . ja v a 2 s. c om*/ FileOutputStream fout = null; try { //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); if (ze == null) throw new FileFormatException("Looks like the uploaded file is not a valid export."); if (ze.isDirectory()) { ze = zis.getNextEntry(); } if (ze != null) { newFile = File.createTempFile("export", ".json"); fout = new FileOutputStream(newFile); IOUtils.copy(zis, fout, BBConfiguration.getImportExportBufferSize()); fout.close(); } else { throw new FileFormatException("Looks like the uploaded file is not a valid export."); } ZipEntry manifest = zis.getNextEntry(); if (manifest != null) { File manifestFile = File.createTempFile("manifest", ".txt"); fout = new FileOutputStream(manifestFile); for (int c = zis.read(); c != -1; c = zis.read()) { fout.write(c); } fout.close(); String manifestContent = FileUtils.readFileToString(manifestFile); manifestFile.delete(); Pattern p = Pattern.compile(BBInternalConstants.IMPORT_MANIFEST_VERSION_PATTERN); Matcher m = p.matcher(manifestContent); if (m.matches()) { String version = m.group(1); if (version.compareToIgnoreCase("0.6.0") < 0) { //we support imports from version 0.6.0 throw new FileFormatException(String.format( "Current baasbox version(%s) is not compatible with import file version(%s)", BBConfiguration.getApiVersion(), version)); } else { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Version : " + version + " is valid"); } } else { throw new FileFormatException("The manifest file does not contain a version number"); } } else { throw new FileFormatException("Looks like zip file does not contain a manifest file"); } if (newFile != null) { DbHelper.importData(appcode, newFile); zis.closeEntry(); zis.close(); } else { throw new FileFormatException("The import file is empty"); } } catch (FileFormatException e) { BaasBoxLogger.error(ExceptionUtils.getMessage(e)); throw e; } catch (Throwable e) { BaasBoxLogger.error(ExceptionUtils.getStackTrace(e)); throw new Exception("There was an error handling your zip import file.", e); } finally { try { if (zis != null) { zis.close(); } if (fout != null) { fout.close(); } } catch (IOException e) { // Nothing to do here } } }
From source file:com.baasbox.service.push.providers.GCMServer.java
public boolean send(String message, List<String> deviceid, JsonNode bodyJson) throws PushNotInitializedException, InvalidRequestException, UnknownHostException, IOException, PushTimeToLiveFormatException, PushCollapseKeyFormatException { PushLogger pushLogger = PushLogger.getInstance(); pushLogger.addMessage("............ GCM Push Message: -%s- to the device(s) %s", message, deviceid); try {/*from ww w . j a va 2s .c o m*/ if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("GCM Push message: " + message + " to the device " + deviceid); if (!isInit) { pushLogger.addMessage("............ GCMS is not initialized!"); return true; } JsonNode customDataNodes = bodyJson.get("custom"); Map<String, JsonNode> customData = new HashMap<String, JsonNode>(); if (!(customDataNodes == null)) { customData.put("custom", customDataNodes); } JsonNode collapse_KeyNode = bodyJson.findValue("collapse_key"); String collapse_key = null; if (!(collapse_KeyNode == null)) { if (!(collapse_KeyNode.isTextual())) throw new PushCollapseKeyFormatException("Collapse_key MUST be a String"); collapse_key = collapse_KeyNode.asText(); } else collapse_key = ""; JsonNode timeToLiveNode = bodyJson.findValue("time_to_live"); int time_to_live = 0; if (!(timeToLiveNode == null)) { if (!(timeToLiveNode.isNumber())) throw new PushTimeToLiveFormatException("Time_to_live MUST be a positive number or equal zero"); else if (timeToLiveNode.asInt() < 0) throw new PushTimeToLiveFormatException("Time_to_live MUST be a positive number or equal zero"); else if (timeToLiveNode.asInt() > MAX_TIME_TO_LIVE) { time_to_live = MAX_TIME_TO_LIVE; } else time_to_live = timeToLiveNode.asInt(); } else time_to_live = MAX_TIME_TO_LIVE; //IF NULL WE SET DEFAULT VALUE (4 WEEKS) if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("collapse_key: " + collapse_key.toString()); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("time_to_live: " + time_to_live); if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("Custom Data: " + customData.toString()); pushLogger.addMessage("............ messgae: %s", message); pushLogger.addMessage("............ collapse_key: %s", collapse_key); pushLogger.addMessage("............ time_to_live: %s", time_to_live); pushLogger.addMessage("............ custom: %s", customData); pushLogger.addMessage("............ device(s): %s", deviceid); Sender sender = new Sender(apikey); Message msg = new Message.Builder().addData("message", message).addData("custom", customData.toString()) .collapseKey(collapse_key.toString()).timeToLive(time_to_live).build(); MulticastResult result = sender.send(msg, deviceid, 1); pushLogger.addMessage("............ %d message(s) sent", result.getTotal()); pushLogger.addMessage("................. success: %s", result.getSuccess()); pushLogger.addMessage("................. failure: %s", result.getFailure()); for (Result r : result.getResults()) { pushLogger.addMessage("............ MessageId (null == error): %s", r.getMessageId()); pushLogger.addMessage("............... Error Code Name: %s", r.getErrorCodeName()); pushLogger.addMessage("............... Canonincal Registration Id: %s", r.getCanonicalRegistrationId()); } // icallbackPush.onError(ExceptionUtils.getMessage(e)); // icallbackPush.onSuccess(); return false; } catch (Exception e) { pushLogger.addMessage("Error sending push notification (GCM)..."); pushLogger.addMessage(ExceptionUtils.getMessage(e)); throw e; } }
From source file:com.baasbox.controllers.Social.java
/** * Login the user through socialnetwork specified * /*from ww w . j a v a2 s. c o m*/ * An oauth_token and oauth_secret provided by oauth steps * are mandatory * @param socialNetwork the social network name (facebook,google) * @return 200 status code with the X-BB-SESSION token for further calls */ @With({ AdminCredentialWrapFilter.class, ConnectToDBFilter.class }) public static Result loginWith(String socialNetwork) { String appcode = (String) ctx().args.get("appcode"); //after this call, db connection is lost! SocialLoginService sc = SocialLoginService.by(socialNetwork, appcode); Token t = extractOAuthTokensFromRequest(request()); if (t == null) { return badRequest( String.format("Both %s and %s should be specified as query parameters or in the json body", OAUTH_TOKEN, OAUTH_SECRET)); } UserInfo result = null; try { if (sc.validationRequest(t.getToken())) { result = sc.getUserInfo(t); } else { return badRequest("Provided token is not valid"); } } catch (BaasBoxSocialException e1) { return badRequest(e1.getError()); } catch (BaasBoxSocialTokenValidationException e2) { return badRequest("Unable to validate provided token"); } if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("UserInfo received: " + result.toString()); result.setFrom(socialNetwork); result.setToken(t.getToken()); //Setting token as secret for one-token only social networks result.setSecret( t.getSecret() != null && StringUtils.isNotEmpty(t.getSecret()) ? t.getSecret() : t.getToken()); UserDao userDao = UserDao.getInstance(); ODocument existingUser = null; try { existingUser = userDao.getBySocialUserId(result); } catch (SqlInjectionException sie) { return internalServerError(ExceptionUtils.getMessage(sie)); } if (existingUser != null) { String username = null; try { username = UserService.getUsernameByProfile(existingUser); if (username == null) { throw new InvalidModelException("username for profile is null"); } } catch (InvalidModelException e) { internalServerError("unable to login with " + socialNetwork + " : " + ExceptionUtils.getMessage(e)); } String password = UserService.generateFakeUserPassword(username, (Date) existingUser.field(UserDao.USER_SIGNUP_DATE)); ImmutableMap<SessionKeys, ? extends Object> sessionObject = SessionTokenProvider .getSessionTokenProvider().setSession(appcode, username, password); response().setHeader(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); ObjectNode on = Json.newObject(); if (existingUser != null) { on = (ObjectNode) Json.parse(User.prepareResponseToJson(existingUser)); } on.put(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); return ok(on); } else { if (BaasBoxLogger.isDebugEnabled()) BaasBoxLogger.debug("User does not exists with tokens...trying to create"); String username = UUID.randomUUID().toString(); Date signupDate = new Date(); try { String password = UserService.generateFakeUserPassword(username, signupDate); JsonNode privateData = null; if (result.getAdditionalData() != null && !result.getAdditionalData().isEmpty()) { privateData = Json.toJson(result.getAdditionalData()); } UserService.signUp(username, password, signupDate, null, privateData, null, null, true); ODocument profile = UserService.getUserProfilebyUsername(username); UserService.addSocialLoginTokens(profile, result); ImmutableMap<SessionKeys, ? extends Object> sessionObject = SessionTokenProvider .getSessionTokenProvider().setSession(appcode, username, password); response().setHeader(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); ObjectNode on = Json.newObject(); if (profile != null) { on = (ObjectNode) Json.parse(User.prepareResponseToJson(profile)); } on.put(SessionKeys.TOKEN.toString(), (String) sessionObject.get(SessionKeys.TOKEN)); return ok(on); } catch (Exception uaee) { return internalServerError(ExceptionUtils.getMessage(uaee)); } } }
From source file:com.baasbox.controllers.ScriptsAdmin.java
public static Result list() { if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method Start"); Result result;/*from www .java2 s .c o m*/ try { Context ctx = Http.Context.current.get(); QueryParams criteria = (QueryParams) ctx.args.get(IQueryParametersKeys.QUERY_PARAMETERS); List<ODocument> documents = ScriptingService.list(criteria); String json = JSONFormats.prepareResponseToJson(documents, JSONFormats.Formats.DOCUMENT); result = ok(json); } catch (SqlInjectionException e) { BaasBoxLogger.error("Sql injection: ", e); result = badRequest(ExceptionUtils.getMessage(e)); } catch (IOException e) { BaasBoxLogger.error("Error formatting response: ", e); result = internalServerError(ExceptionUtils.getMessage(e)); } if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method End"); return result; }
From source file:com.ebay.logstorm.server.services.impl.PipelineExecutionServiceImpl.java
@Override // @Transactional public PipelineEntity stop(PipelineEntity pipeline) { LOG.info("Stopping {} instances of {}", pipeline.getInstances().size(), pipeline.getName()); pipeline.getInstances().stream().map((instance) -> ExecutionManager.getInstance().submit(() -> { if (PipelineExecutionStatus.isReadyToStop(instance.getStatus())) { try { LOG.info("{} changed status from {} to {}", instance.getName(), instance.getStatus(), PipelineExecutionStatus.STOPPING); instance.setStatus(PipelineExecutionStatus.STOPPING); updateExecutionEntity(instance); pipeline.getCluster().getPlatformInstance().stop(instance); updateExecutionEntity(instance); } catch (Throwable e) { LOG.error(e.getMessage(), e); LOG.info("{} changed status from {} to {}", instance.getName(), instance.getStatus(), PipelineExecutionStatus.FAILED); instance.setStatus(PipelineExecutionStatus.FAILED); instance.setDescription(ExceptionUtils.getMessage(e)); updateExecutionEntity(instance); throw new RuntimeException(e); }//w w w. j av a2 s. c om } else { throw new RuntimeException(instance.getName() + " is not ready to stop"); } })).forEach(future -> { try { future.get(); } catch (InterruptedException | ExecutionException e) { LOG.error(e.getMessage(), e); throw new RuntimeException(e); } }); return pipeline; }
From source file:com.baasbox.controllers.ScriptsAdmin.java
public static Result drop(String name) { if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method Start"); Result res;// w w w. j a v a 2 s.com try { boolean deleted = ScriptingService.forceDelete(name); if (deleted) { res = ok(); } else { res = notFound("script: " + name + " not found"); } } catch (ScriptException e) { BaasBoxLogger.error("Error while deleting script: " + name, e); res = internalServerError(ExceptionUtils.getMessage(e)); } if (BaasBoxLogger.isTraceEnabled()) BaasBoxLogger.trace("Method End"); return res; }
From source file:com.twosigma.beaker.core.rest.FileIORest.java
@POST @Path("save") public void save(@FormParam("path") String path, @FormParam("content") String contentAsString) throws IOException { path = removePrefix(path);//from w w w . j a va 2 s . c o m try { utils.saveFile(path, contentAsString); } catch (AccessDeniedException ade) { throw new FileAccessDeniedException(ExceptionUtils.getMessage(ade)); } catch (Throwable t) { throw new FileSaveException(ExceptionUtils.getStackTrace(t)); } }