/** * Mark the specified action as completed * * @param transactionId the unique transaction id for this action * @param scheduledActionUuid the unique name of an action */ private void markAsCompleted(String transactionId, String scheduledActionUuid) { try { Ebean.beginTransaction(); SchedulerState schedulerState = SchedulerState.getRunningSchedulerStateFromTransactionId(transactionId); if (schedulerState == null) { log.error( String.format( "Strange ... No running scheduled action for %s with transaction id %s while one was running and mark as completed is requested", scheduledActionUuid, transactionId)); } else { schedulerState.isRunning = false; schedulerState.save(); if (log.isDebugEnabled()) { log.debug( String.format( "Scheduled action for %s with transaction id %s completed", scheduledActionUuid, transactionId)); } } Ebean.commitTransaction(); } catch (Exception e) { log.error("Failed to mark as complete", e); rollbackTransactionSilent(); } finally { endTransactionSilent(); } }
/** * Block the execution thread during a moment * * @param duration a duration in ms */ public static void wait(int duration) { try { Thread.sleep(duration); } catch (InterruptedException e) { log.error("Error while stopping the current thread", e); } }
/** * Create a new SysAdminUtilsImpl * * @param lifecycle the play application lifecycle listener * @param configuration the play application configuration * @param databaseDependencyService the service which secure the availability of the database * @param actorSystem the Akka actor system */ @Inject public SysAdminUtilsImpl( ApplicationLifecycle lifecycle, Configuration configuration, IDatabaseDependencyService databaseDependencyService, ActorSystem actorSystem) { log.info("SERVICE>>> SysAdminUtilsImpl starting..."); this.actorSystem = actorSystem; this.configuration = configuration; initAutomatedSystemStatus(); lifecycle.addStopHook( () -> { log.info("SERVICE>>> SysAdminUtilsImpl stopping..."); if (automaticSystemStatus != null) { try { getAutomaticSystemStatus().cancel(); } catch (Exception e) { log.error("Unable to stop the automatic system status", e); } } log.info("SERVICE>>> SysAdminUtilsImpl stopped"); return Promise.pure(null); }); log.info("SERVICE>>> SysAdminUtilsImpl started"); }
public static Result upload() { try { Http.MultipartFormData body = request().body().asMultipartFormData(); Http.MultipartFormData.FilePart picture = body.getFile("picture"); if (picture != null) { String fileName = picture.getFilename(); logger.info("Uploading file name: {}", fileName); File pictureFile = picture.getFile(); pictureFile.getTotalSpace(); logger.info("Total space: {}", pictureFile); File folder = pictureFile.getParentFile(); File renamedFile = new File(folder, fileName); File result = ExifImageUtils.rotateFromOrientationData(pictureFile, renamedFile); // final String absolutePath = pictureFile.getAbsolutePath(); // final String escapedPath = UrlEscapers.urlPathSegmentEscaper().escape(absolutePath); // return ok(views.html.main.render(escapedPath)); return ok(views.html.main.render(result.getAbsolutePath())); } return ok("asdf"); } catch (Exception e) { logger.error("Error uploading", e); return internalServerError(e.getMessage()); } }
public static void resize(File file, int width, int height) throws FileOperationException { BufferedImage image; try { image = ImageIO.read(file); image = Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, Scalr.Mode.FIT_EXACT, width, height); saveToJPG(image, file); image.flush(); } catch (IOException | IllegalArgumentException e) { logger.error(e.getMessage(), e); throw new FileOperationException("Resizing failed"); } }
public static void crop(File file, int x, int y, int width, int height) throws FileOperationException { BufferedImage image; try { image = ImageIO.read(file); image = Scalr.crop(image, x, y, width, height); saveToJPG(image, file); image.flush(); } catch (IOException | IllegalArgumentException e) { logger.error(e.getMessage(), e); throw new FileOperationException("Cropping failed"); } }
@Override protected String infoNotify(Map<String, String> requestParams) { String respCode = requestParams.get("respCode"); if (StringUtil.isNotBlank(respCode) && respCode.equals("00")) { String outTradeNo = new String(requestParams.get("orderId").replaceFirst("^0*", "")); // 获取交易金额 txnAmt String totalFee = String.valueOf(Double.valueOf(requestParams.get("txnAmt")) / 100); // 获取付款时间 String payedMill = requestParams.get("txnTime"); // 获取流水号 String tradeNo = requestParams.get("queryId"); String tradeStatus = "SUCCESS"; Date payedAt = DateUtil.timeMillToDate(payedMill); Integer id = resultOfPayment(outTradeNo, tradeNo, tradeStatus, totalFee, payedAt); logger.info(id + "验证签名结果[成功]."); } else { logger.error("银联支付返回,失败" + "\n以下是回掉信息" + requestParams.toString()); } return notifySuccess(); }
/** * Mark the specified action as completed * * @param transactionId the unique transaction id for this action * @param scheduledActionUuid the unique name of an action */ private void markAsStarted(String transactionId, String scheduledActionUuid) { try { Ebean.beginTransaction(); SchedulerState schedulerState = new SchedulerState(); schedulerState.actionUuid = scheduledActionUuid; schedulerState.transactionId = transactionId; schedulerState.isRunning = true; schedulerState.save(); if (log.isDebugEnabled()) { log.debug( String.format( "Scheduled action for %s with transaction id %s started", scheduledActionUuid, transactionId)); } Ebean.commitTransaction(); } catch (Exception e) { log.error("Failed to mark as started", e); rollbackTransactionSilent(); } finally { endTransactionSilent(); } }