diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/CorsConfig.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/CorsConfig.java index 14bb44af0..796e44f7b 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/CorsConfig.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/CorsConfig.java @@ -10,6 +10,7 @@ public class CorsConfig { // 当前跨域请求最大有效时长。这里默认30天 private long maxAge = 30 * 24 * 60 * 60; + private CorsConfiguration buildConfig() { CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址 diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java index 40a2d6e7e..a14078ef4 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/GlobalExceptionHandler.java @@ -1,8 +1,9 @@ package org.linlinjava.litemall.core.config; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.hibernate.validator.internal.engine.path.PathImpl; import org.linlinjava.litemall.core.util.ResponseUtil; -import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.web.bind.MissingServletRequestParameterException; @@ -17,41 +18,43 @@ import java.util.Set; @ControllerAdvice -@Order( value = Ordered.LOWEST_PRECEDENCE ) +@Order public class GlobalExceptionHandler { + private Log logger = LogFactory.getLog(GlobalExceptionHandler.class); + @ExceptionHandler(IllegalArgumentException.class) @ResponseBody public Object badArgumentHandler(IllegalArgumentException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return ResponseUtil.badArgumentValue(); } @ExceptionHandler(MethodArgumentTypeMismatchException.class) @ResponseBody public Object badArgumentHandler(MethodArgumentTypeMismatchException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return ResponseUtil.badArgumentValue(); } @ExceptionHandler(MissingServletRequestParameterException.class) @ResponseBody public Object badArgumentHandler(MissingServletRequestParameterException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return ResponseUtil.badArgumentValue(); } @ExceptionHandler(HttpMessageNotReadableException.class) @ResponseBody public Object badArgumentHandler(HttpMessageNotReadableException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return ResponseUtil.badArgumentValue(); } @ExceptionHandler(ValidationException.class) @ResponseBody public Object badArgumentHandler(ValidationException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); if (e instanceof ConstraintViolationException) { ConstraintViolationException exs = (ConstraintViolationException) e; Set> violations = exs.getConstraintViolations(); @@ -66,7 +69,7 @@ public Object badArgumentHandler(ValidationException e) { @ExceptionHandler(Exception.class) @ResponseBody public Object seriousHandler(Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return ResponseUtil.serious(); } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/JacksonConfig.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/JacksonConfig.java index 6f80efe0a..74000936d 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/config/JacksonConfig.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/config/JacksonConfig.java @@ -29,13 +29,18 @@ public Jackson2ObjectMapperBuilderCustomizer customJackson() { return new Jackson2ObjectMapperBuilderCustomizer() { @Override public void customize(Jackson2ObjectMapperBuilder builder) { - builder.serializerByType(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - builder.serializerByType(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); - builder.serializerByType(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); - - builder.deserializerByType(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); - builder.deserializerByType(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); - builder.deserializerByType(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); + builder.serializerByType(LocalDateTime.class, + new LocalDateTimeSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + builder.serializerByType(LocalDate.class, + new LocalDateSerializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + builder.serializerByType(LocalTime.class, + new LocalTimeSerializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); + builder.deserializerByType(LocalDateTime.class, + new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); + builder.deserializerByType(LocalDate.class, + new LocalDateDeserializer(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); + builder.deserializerByType(LocalTime.class, + new LocalTimeDeserializer(DateTimeFormatter.ofPattern("HH:mm:ss"))); builder.serializationInclusion(JsonInclude.Include.NON_NULL); builder.failOnUnknownProperties(false); builder.featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java index d7278f371..6cf0bae41 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/express/ExpressService.java @@ -1,6 +1,8 @@ package org.linlinjava.litemall.core.express; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.linlinjava.litemall.core.express.config.ExpressProperties; import org.linlinjava.litemall.core.express.dao.ExpressInfo; import org.linlinjava.litemall.core.util.HttpUtil; @@ -13,10 +15,12 @@ /** * 物流查询服务 - * + *

* 快递鸟即时查询API http://www.kdniao.com/api-track */ public class ExpressService { + + private final Log logger = LogFactory.getLog(ExpressService.class); //请求url private String ReqURL = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx"; @@ -59,7 +63,7 @@ public ExpressInfo getExpressInfo(String expCode, String expNo) { ei.setShipperName(getVendorName(expCode)); return ei; } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; @@ -103,7 +107,7 @@ private String MD5(String str, String charset) throws Exception { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes(charset)); byte[] result = md.digest(); - StringBuffer sb = new StringBuffer(32); + StringBuilder sb = new StringBuilder(32); for (int i = 0; i < result.length; i++) { int val = result[i] & 0xff; if (val <= 0xf) { @@ -126,12 +130,12 @@ private String encrypt(String content, String keyValue, String charset) { if (keyValue != null) { content = content + keyValue; } - byte[] src = new byte[0]; + byte[] src; try { src = MD5(content, charset).getBytes(charset); return Base64Utils.encodeToString(src); } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java index 7d15154c8..a704cb194 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/TencentSmsSender.java @@ -35,7 +35,7 @@ public SmsResult send(String phone, String content) { smsResult.setResult(result); return smsResult; } catch (HTTPException | IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; @@ -52,7 +52,7 @@ public SmsResult sendWithTemplate(String phone, int templateId, String[] params) smsResult.setResult(result); return smsResult; } catch (HTTPException | IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java index 448e0d2a3..88c33c9db 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/notify/WxTemplateSender.java @@ -47,7 +47,8 @@ public void sendWechatMsg(String touser, String templatId, String[] parms, Strin sendMsg(touser, templatId, parms, page, "", ""); } - private void sendMsg(String touser, String templatId, String[] parms, String page, String color, String emphasisKeyword) { + private void sendMsg(String touser, String templatId, String[] parms, String page, String color, + String emphasisKeyword) { LitemallUserFormid userFormid = formIdService.queryByOpenId(touser); if (userFormid == null) return; @@ -68,7 +69,7 @@ private void sendMsg(String touser, String templatId, String[] parms, String pag logger.warn("更新数据已失效"); } } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java index 49ac8cb74..ead254c0d 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/qcode/QCodeService.java @@ -2,6 +2,8 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import me.chanjar.weixin.common.error.WxErrorException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.linlinjava.litemall.core.storage.StorageService; import org.linlinjava.litemall.core.system.SystemConfig; import org.linlinjava.litemall.db.domain.LitemallGroupon; @@ -18,6 +20,7 @@ @Service public class QCodeService { + private final Log logger = LogFactory.getLog(QCodeService.class); @Autowired WxMaService wxMaService; @@ -28,21 +31,23 @@ public class QCodeService { public String createGrouponShareImage(String goodName, String goodPicUrl, LitemallGroupon groupon) { try { //创建该商品的二维码 - File file = wxMaService.getQrcodeService().createWxaCodeUnlimit("groupon," + groupon.getId(), "pages/index/index"); + File file = wxMaService.getQrcodeService().createWxaCodeUnlimit("groupon," + groupon.getId(), "pages" + + "/index/index"); FileInputStream inputStream = new FileInputStream(file); //将商品图片,商品名字,商城名字画到模版图中 byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); //存储分享图 - LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(groupon.getId().toString())); + LitemallStorage storageInfo = storageService.store(inputStream2, imageData.length, "image/jpeg", + getKeyName(groupon.getId().toString())); return storageInfo.getUrl(); } catch (WxErrorException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } catch (FileNotFoundException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return ""; @@ -68,15 +73,16 @@ public String createGoodShareImage(String goodId, String goodPicUrl, String good byte[] imageData = drawPicture(inputStream, goodPicUrl, goodName); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(imageData); //存储分享图 - LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg", getKeyName(goodId)); + LitemallStorage litemallStorage = storageService.store(inputStream2, imageData.length, "image/jpeg", + getKeyName(goodId)); return litemallStorage.getUrl(); } catch (WxErrorException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } catch (FileNotFoundException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return ""; @@ -126,7 +132,7 @@ private byte[] drawPicture(InputStream qrCodeImg, String goodPicUrl, String good drawTextInImg(baseImage, goodName, 65, 867); //写上商城名称 -// drawTextInImgCenter(baseImage, shopName, 98); + // drawTextInImgCenter(baseImage, shopName, 98); //转jpg @@ -173,7 +179,8 @@ private void drawTextInImg(BufferedImage baseImage, String textToWrite, int x, i g2D.dispose(); } - private void drawImgInImg(BufferedImage baseImage, BufferedImage imageToWrite, int x, int y, int width, int heigth) { + private void drawImgInImg(BufferedImage baseImage, BufferedImage imageToWrite, int x, int y, int width, + int heigth) { Graphics2D g2D = (Graphics2D) baseImage.getGraphics(); g2D.drawImage(imageToWrite, x, y, width, heigth, null); g2D.dispose(); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java index 7a3d87efc..30d84b00e 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/AliyunStorage.java @@ -4,6 +4,8 @@ import com.aliyun.oss.model.ObjectMetadata; import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectResult; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; @@ -20,6 +22,8 @@ */ public class AliyunStorage implements Storage { + private final Log logger = LogFactory.getLog(AliyunStorage.class); + private String endpoint; private String accessKeyId; private String accessKeySecret; @@ -84,7 +88,7 @@ public void store(InputStream inputStream, long contentLength, String contentTyp PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata); PutObjectResult putObjectResult = getOSSClient().putObject(putObjectRequest); } catch (Exception ex) { - ex.printStackTrace(); + logger.error(ex.getMessage(), ex); } } @@ -110,7 +114,7 @@ public Resource loadAsResource(String keyName) { return null; } } catch (MalformedURLException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return null; } } @@ -120,7 +124,7 @@ public void delete(String keyName) { try { getOSSClient().deleteObject(bucketName, keyName); } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java index a4fc7f693..3c182b570 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/LocalStorage.java @@ -1,6 +1,8 @@ package org.linlinjava.litemall.core.storage; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; @@ -18,6 +20,9 @@ */ public class LocalStorage implements Storage { + + private final Log logger = LogFactory.getLog(LocalStorage.class); + private String storagePath; private String address; @@ -34,7 +39,7 @@ public void setStoragePath(String storagePath) { try { Files.createDirectories(rootLocation); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } } @@ -83,7 +88,7 @@ public Resource loadAsResource(String filename) { return null; } } catch (MalformedURLException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); return null; } } @@ -94,13 +99,13 @@ public void delete(String filename) { try { Files.delete(file); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } } @Override public String generateUrl(String keyName) { - String url = address + keyName; - return url; + + return address + keyName; } } \ No newline at end of file diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java index cf307cbae..03827ec39 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/QiniuStorage.java @@ -1,11 +1,12 @@ package org.linlinjava.litemall.core.storage; import com.qiniu.common.QiniuException; -import com.qiniu.http.Response; import com.qiniu.storage.BucketManager; import com.qiniu.storage.Configuration; import com.qiniu.storage.UploadManager; import com.qiniu.util.Auth; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; @@ -17,6 +18,8 @@ public class QiniuStorage implements Storage { + private final Log logger = LogFactory.getLog(QiniuStorage.class); + private String endpoint; private String accessKey; private String secretKey; @@ -71,9 +74,9 @@ public void store(InputStream inputStream, long contentLength, String contentTyp try { String upToken = auth.uploadToken(bucketName); - Response response = uploadManager.put(inputStream, keyName, upToken, null, contentType); + uploadManager.put(inputStream, keyName, upToken, null, contentType); } catch (QiniuException ex) { - ex.printStackTrace(); + logger.error(ex.getMessage(), ex); } } @@ -94,13 +97,11 @@ public Resource loadAsResource(String keyName) { Resource resource = new UrlResource(url); if (resource.exists() || resource.isReadable()) { return resource; - } else { - return null; } } catch (MalformedURLException e) { - e.printStackTrace(); - return null; + logger.error(e.getMessage(), e); } + return null; } @Override @@ -111,11 +112,10 @@ public void delete(String keyName) { } bucketManager = new BucketManager(auth, new Configuration()); } - try { bucketManager.delete(bucketName, keyName); } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java index b4e3e300f..c5f9b0231 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/storage/TencentStorage.java @@ -6,8 +6,9 @@ import com.qcloud.cos.auth.COSCredentials; import com.qcloud.cos.model.ObjectMetadata; import com.qcloud.cos.model.PutObjectRequest; -import com.qcloud.cos.model.PutObjectResult; import com.qcloud.cos.region.Region; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; @@ -22,6 +23,8 @@ */ public class TencentStorage implements Storage { + private final Log logger = LogFactory.getLog(TencentStorage.class); + private String secretId; private String secretKey; private String region; @@ -84,11 +87,12 @@ public void store(InputStream inputStream, long contentLength, String contentTyp ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(contentLength); objectMetadata.setContentType(contentType); - // 对象键(Key)是对象在存储桶中的唯一标识。例如,在对象的访问域名 `bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg` 中,对象键为 doc1/pic1.jpg, 详情参考 [对象键](https://cloud.tencent.com/document/product/436/13324) + // 对象键(Key)是对象在存储桶中的唯一标识。例如,在对象的访问域名 `bucket1-1250000000.cos.ap-guangzhou.myqcloud.com/doc1/pic1.jpg` + // 中,对象键为 doc1/pic1.jpg, 详情参考 [对象键](https://cloud.tencent.com/document/product/436/13324) PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, keyName, inputStream, objectMetadata); - PutObjectResult putObjectResult = getCOSClient().putObject(putObjectRequest); + getCOSClient().putObject(putObjectRequest); } catch (Exception ex) { - ex.printStackTrace(); + logger.error(ex.getMessage(), ex); } } @@ -109,13 +113,11 @@ public Resource loadAsResource(String keyName) { Resource resource = new UrlResource(url); if (resource.exists() || resource.isReadable()) { return resource; - } else { - return null; } } catch (MalformedURLException e) { - e.printStackTrace(); - return null; + logger.error(e.getMessage(), e); } + return null; } @Override @@ -123,7 +125,7 @@ public void delete(String keyName) { try { getCOSClient().deleteObject(bucketName, keyName); } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/system/SystemInistService.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/system/SystemInistService.java index e68c50048..9796a52c0 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/system/SystemInistService.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/system/SystemInistService.java @@ -31,6 +31,7 @@ private void inist() { private final static Map DEFAULT_CONFIGS = new HashMap<>(); + static { // 小程序相关配置默认值 DEFAULT_CONFIGS.put(SystemConfig.LITEMALL_WX_INDEX_NEW, "6"); @@ -63,7 +64,7 @@ private void initConfigs() { // 2. 分析DEFAULT_CONFIGS for (Map.Entry entry : DEFAULT_CONFIGS.entrySet()) { - if(configs.containsKey(entry.getKey())){ + if (configs.containsKey(entry.getKey())) { continue; } @@ -109,7 +110,9 @@ private Map getSystemInfo() { infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 3, "系统设置"); infos.put("自动创建朋友圈分享图", Boolean.toString(SystemConfig.isAutoCreateShareImage())); infos.put("商场名称", SystemConfig.getMallName()); - infos.put("首页显示记录数:NEW,HOT,BRAND,TOPIC,CatlogList,CatlogMore", SystemConfig.getNewLimit() + "," + SystemConfig.getHotLimit() + "," + SystemConfig.getBrandLimit() + "," + SystemConfig.getTopicLimit() + "," + SystemConfig.getCatlogListLimit() + "," + SystemConfig.getCatlogMoreLimit()); + infos.put("首页显示记录数:NEW,HOT,BRAND,TOPIC,CatlogList,CatlogMore", + SystemConfig.getNewLimit() + "," + SystemConfig.getHotLimit() + "," + SystemConfig.getBrandLimit() + + "," + SystemConfig.getTopicLimit() + "," + SystemConfig.getCatlogListLimit() + "," + SystemConfig.getCatlogMoreLimit()); return infos; } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/HttpUtil.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/HttpUtil.java index f80736886..60713df1e 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/HttpUtil.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/HttpUtil.java @@ -1,5 +1,8 @@ package org.linlinjava.litemall.core.util; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -14,6 +17,9 @@ * @return 远程资源的响应结果 */ public class HttpUtil { + + private static final Log logger = LogFactory.getLog(HttpUtil.class); + /** * 向指定 URL 发送POST方法的请求 * @@ -53,9 +59,9 @@ public static String sendPost(String url, Map params) { param.append(entry.getKey()); param.append("="); param.append(entry.getValue()); - //System.out.println(entry.getKey()+":"+entry.getValue()); + } - //System.out.println("param:"+param.toString()); + out.write(param.toString()); } // flush输出流的缓冲 @@ -68,7 +74,7 @@ public static String sendPost(String url, Map params) { result.append(line); } } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } //使用finally块来关闭输出流、输入流 finally { @@ -80,7 +86,7 @@ public static String sendPost(String url, Map params) { in.close(); } } catch (IOException ex) { - ex.printStackTrace(); + logger.error(ex.getMessage(), ex); } } return result.toString(); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/IpUtil.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/IpUtil.java index 2618bbd85..f753428e7 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/IpUtil.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/IpUtil.java @@ -1,5 +1,8 @@ package org.linlinjava.litemall.core.util; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import javax.servlet.http.HttpServletRequest; import java.net.InetAddress; import java.net.UnknownHostException; @@ -9,8 +12,10 @@ */ public class IpUtil { + private static final Log logger = LogFactory.getLog(IpUtil.class); + public static String getIpAddr(HttpServletRequest request) { - String ipAddress = null; + String ipAddress; try { ipAddress = request.getHeader("x-forwarded-for"); if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { @@ -27,7 +32,7 @@ public static String getIpAddr(HttpServletRequest request) { try { inet = InetAddress.getLocalHost(); } catch (UnknownHostException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } ipAddress = inet.getHostAddress(); } @@ -42,7 +47,6 @@ public static String getIpAddr(HttpServletRequest request) { } catch (Exception e) { ipAddress = ""; } - // ipAddress = this.getRequest().getRemoteAddr(); return ipAddress; } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java index d81d40e10..22676ace9 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/JacksonUtil.java @@ -3,22 +3,27 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import java.io.IOException; import java.util.List; import java.util.Map; public class JacksonUtil { + + private static final Log logger = LogFactory.getLog(JacksonUtil.class); + public static String parseString(String body, String field) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); JsonNode leaf = node.get(field); if (leaf != null) return leaf.asText(); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } @@ -26,7 +31,7 @@ public static String parseString(String body, String field) { public static List parseStringList(String body, String field) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); JsonNode leaf = node.get(field); @@ -35,28 +40,28 @@ public static List parseStringList(String body, String field) { return mapper.convertValue(leaf, new TypeReference>() { }); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } public static Integer parseInteger(String body, String field) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); JsonNode leaf = node.get(field); if (leaf != null) return leaf.asInt(); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } public static List parseIntegerList(String body, String field) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); JsonNode leaf = node.get(field); @@ -65,7 +70,7 @@ public static List parseIntegerList(String body, String field) { return mapper.convertValue(leaf, new TypeReference>() { }); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } @@ -73,21 +78,21 @@ public static List parseIntegerList(String body, String field) { public static Boolean parseBoolean(String body, String field) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); JsonNode leaf = node.get(field); if (leaf != null) return leaf.asBoolean(); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } public static Short parseShort(String body, String field) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); JsonNode leaf = node.get(field); @@ -96,14 +101,14 @@ public static Short parseShort(String body, String field) { return value.shortValue(); } } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } public static Byte parseByte(String body, String field) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); JsonNode leaf = node.get(field); @@ -112,20 +117,20 @@ public static Byte parseByte(String body, String field) { return value.byteValue(); } } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } public static T parseObject(String body, String field, Class clazz) { ObjectMapper mapper = new ObjectMapper(); - JsonNode node = null; + JsonNode node; try { node = mapper.readTree(body); node = node.get(field); return mapper.treeToValue(node, clazz); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } @@ -136,10 +141,10 @@ public static Object toNode(String json) { } ObjectMapper mapper = new ObjectMapper(); try { - JsonNode jsonNode = mapper.readTree(json); - return jsonNode; + + return mapper.readTree(json); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; @@ -148,9 +153,10 @@ public static Object toNode(String json) { public static Map toMap(String data) { ObjectMapper objectMapper = new ObjectMapper(); try { - return objectMapper.readValue(data, new TypeReference>(){}); + return objectMapper.readValue(data, new TypeReference>() { + }); } catch (IOException e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } return null; } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java index 3fbbf07ee..97b99111b 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/RegexUtil.java @@ -9,7 +9,8 @@ /** * RegexUtil类的代码是来自[AndroidUtilCode](https://github.com/Blankj/AndroidUtilCode)的RegexUtils类和RegexConstants类 * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/util/RegexUtils.java - * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/constant/RegexConstants.java + * https://github.com/Blankj/AndroidUtilCode/blob/master/utilcode/src/main/java/com/blankj/utilcode/constant + * /RegexConstants.java */ public class RegexUtil { @@ -19,13 +20,15 @@ public class RegexUtil { public static final String REGEX_MOBILE_SIMPLE = "^[1]\\d{10}$"; /** * Regex of exact mobile. - *

china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184, 187, 188, 198

+ *

china mobile: 134(0-8), 135, 136, 137, 138, 139, 147, 150, 151, 152, 157, 158, 159, 178, 182, 183, 184, + * 187, 188, 198

*

china unicom: 130, 131, 132, 145, 155, 156, 166, 171, 175, 176, 185, 186

*

china telecom: 133, 153, 173, 177, 180, 181, 189, 199

*

global star: 1349

*

virtual operator: 170

*/ - public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|(18[0-9])|(19[8,9]))\\d{8}$"; + public static final String REGEX_MOBILE_EXACT = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(16[6])|(17[0,1,3,5-8])|" + + "(18[0-9])|(19[8,9]))\\d{8}$"; /** * Regex of telephone number. */ @@ -37,7 +40,8 @@ public class RegexUtil { /** * Regex of id card number which length is 18. */ - public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9Xx])$"; + public static final String REGEX_ID_CARD18 = "^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}" + + "([0-9Xx])$"; /** * Regex of email. */ @@ -60,7 +64,9 @@ public class RegexUtil { /** * Regex of date which pattern is "yyyy-MM-dd". */ - public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$"; + public static final String REGEX_DATE = "^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|" + + "(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|" + + "(?:0[48]|[2468][048]|[13579][26])00)-02-29)$"; /** * Regex of ip address. */ @@ -255,7 +261,8 @@ public static boolean isMatch(final String regex, final CharSequence input) { * @return the list of input matches the regex */ public static List getMatches(final String regex, final CharSequence input) { - if (input == null) return Collections.emptyList(); + if (input == null) + return Collections.emptyList(); List matches = new ArrayList<>(); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(input); @@ -273,7 +280,8 @@ public static List getMatches(final String regex, final CharSequence inp * @return the array of strings computed by splitting input around matches of regex */ public static String[] getSplits(final String input, final String regex) { - if (input == null) return new String[0]; + if (input == null) + return new String[0]; return input.split(regex); } @@ -291,7 +299,8 @@ public static String[] getSplits(final String input, final String regex) { public static String getReplaceFirst(final String input, final String regex, final String replacement) { - if (input == null) return ""; + if (input == null) + return ""; return Pattern.compile(regex).matcher(input).replaceFirst(replacement); } @@ -309,7 +318,8 @@ public static String getReplaceFirst(final String input, public static String getReplaceAll(final String input, final String regex, final String replacement) { - if (input == null) return ""; + if (input == null) + return ""; return Pattern.compile(regex).matcher(input).replaceAll(replacement); } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/ResponseUtil.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/ResponseUtil.java index ef700965b..53d3255c6 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/ResponseUtil.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/ResponseUtil.java @@ -65,8 +65,7 @@ public static Object okList(List list) { data.put("page", page.getPageNum()); data.put("limit", page.getPageSize()); data.put("pages", page.getPages()); - } - else{ + } else { data.put("total", list.size()); data.put("page", 1); data.put("limit", list.size()); @@ -86,8 +85,7 @@ public static Object okList(List list, List pagedList) { data.put("page", page.getPageNum()); data.put("limit", page.getPageSize()); data.put("pages", page.getPages()); - } - else{ + } else { data.put("total", pagedList.size()); data.put("page", 1); data.put("limit", pagedList.size()); diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/SystemInfoPrinter.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/SystemInfoPrinter.java index dac7d57d9..51a02f642 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/util/SystemInfoPrinter.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/util/SystemInfoPrinter.java @@ -1,8 +1,13 @@ package org.linlinjava.litemall.core.util; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import java.util.Map; public class SystemInfoPrinter { + + private static final Log logger = LogFactory.getLog(SystemInfoPrinter.class); public static final String CREATE_PART_COPPER = "XOXOXOXOX"; private static int maxSize = 0; @@ -34,24 +39,24 @@ private static void setMaxSize(Map infos) { } private static void printHeader(String title) { - System.out.println(getLineCopper()); - System.out.println(""); - System.out.println(" " + title); - System.out.println(""); + logger.info(getLineCopper()); + logger.info(""); + logger.info(" " + title); + logger.info(""); } private static void printEnd() { - System.out.println(" "); - System.out.println(getLineCopper()); + logger.info(" "); + logger.info(getLineCopper()); } private static String getLineCopper() { - String copper = ""; + StringBuilder sb = new StringBuilder(); for (int i = 0; i < maxSize; i++) { - copper += "="; + sb.append("="); } - return copper; + return sb.toString(); } private static void printLine(String head, String line) { @@ -59,11 +64,11 @@ private static void printLine(String head, String line) { return; if (head.startsWith(CREATE_PART_COPPER)) { - System.out.println(""); - System.out.println(" [[ " + line + " ]]"); - System.out.println(""); + logger.info(""); + logger.info(" [[ " + line + " ]]"); + logger.info(""); } else { - System.out.println(" " + head + " -> " + line); + logger.info(" " + head + " -> " + line); } } } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java index 7511c0a2f..b163a117b 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/OrderValidator.java @@ -1,8 +1,9 @@ package org.linlinjava.litemall.core.validator; +import com.google.common.collect.Lists; + import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -import java.util.ArrayList; import java.util.List; public class OrderValidator implements ConstraintValidator { @@ -10,7 +11,7 @@ public class OrderValidator implements ConstraintValidator { @Override public void initialize(Order order) { - valueList = new ArrayList(); + valueList = Lists.newArrayList(); for (String val : order.accepts()) { valueList.add(val.toUpperCase()); } diff --git a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java index 4d8bf7e2f..eca179bba 100644 --- a/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java +++ b/litemall-core/src/main/java/org/linlinjava/litemall/core/validator/SortValidator.java @@ -1,8 +1,9 @@ package org.linlinjava.litemall.core.validator; +import com.google.common.collect.Lists; + import javax.validation.ConstraintValidator; import javax.validation.ConstraintValidatorContext; -import java.util.ArrayList; import java.util.List; public class SortValidator implements ConstraintValidator { @@ -10,7 +11,7 @@ public class SortValidator implements ConstraintValidator { @Override public void initialize(Sort sort) { - valueList = new ArrayList(); + valueList = Lists.newArrayList(); for (String val : sort.accepts()) { valueList.add(val.toUpperCase()); } diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java index 6623e039a..18983c9e6 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/AliyunStorageTest.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; import org.linlinjava.litemall.core.storage.AliyunStorage; @@ -17,6 +19,8 @@ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class AliyunStorageTest { + + private final Log logger = LogFactory.getLog(AliyunStorageTest.class); @Autowired private AliyunStorage aliyunStorage; @@ -27,11 +31,9 @@ public void test() throws IOException { aliyunStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); Resource resource = aliyunStorage.loadAsResource("litemall.png"); String url = aliyunStorage.generateUrl("litemall.png"); - System.out.println("test file " + test); - System.out.println("store file " + resource.getURI()); - System.out.println("generate url " + url); - -// tencentOsService.delete("litemall.png"); + logger.info("test file " + test); + logger.info("store file " + resource.getURI()); + logger.info("generate url " + url); } } \ No newline at end of file diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTask.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTask.java index a2a79fda4..b6e0d98ee 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTask.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/AsyncTask.java @@ -1,18 +1,22 @@ package org.linlinjava.litemall.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @Service public class AsyncTask { + private final Log logger = LogFactory.getLog(AsyncTask.class); + @Async public void asyncMethod() { - System.out.println("Execute method asynchronously. " + logger.info("Execute method asynchronously. " + Thread.currentThread().getName()); } public void nonasyncMethod() { - System.out.println("Execute method nonasynchronously. " + logger.info("Execute method nonasynchronously. " + Thread.currentThread().getName()); } } diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/CoreConfigTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/CoreConfigTest.java index 2d0606bce..d494451b1 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/CoreConfigTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/CoreConfigTest.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -12,12 +14,13 @@ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class CoreConfigTest { + private final Log logger = LogFactory.getLog(CoreConfigTest.class); @Autowired Environment environment; @Test public void test() { // 测试获取application-core.yml配置信息 - System.out.println(environment.getProperty("litemall.express.appId")); + logger.info(environment.getProperty("litemall.express.appId")); } } diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/ExpressTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/ExpressTest.java index 4bb0d40df..85d036ff9 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/ExpressTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/ExpressTest.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; import org.linlinjava.litemall.core.express.ExpressService; @@ -13,6 +15,8 @@ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) public class ExpressTest { + + private final Log logger = LogFactory.getLog(ExpressTest.class); @Autowired private ExpressService expressService; @@ -22,8 +26,8 @@ public void test() { try { ei = expressService.getExpressInfo("YTO", "800669400640887922"); } catch (Exception e) { - e.printStackTrace(); + logger.error(e.getMessage(), e); } - System.out.print(ei); + logger.info(ei); } } diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java index 3d89bcf6e..79297509f 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/LocalStorageTest.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; import org.linlinjava.litemall.core.storage.LocalStorage; @@ -17,6 +19,8 @@ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class LocalStorageTest { + + private final Log logger = LogFactory.getLog(LocalStorageTest.class); @Autowired private LocalStorage localStorage; @@ -27,12 +31,9 @@ public void test() throws IOException { localStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); Resource resource = localStorage.loadAsResource("litemall.png"); String url = localStorage.generateUrl("litemall.png"); - System.out.println("test file " + test); - System.out.println("store file " + resource.getURI()); - System.out.println("generate url " + url); - -// localStorage.delete("litemall.png"); - + logger.info("test file " + test); + logger.info("store file " + resource.getURI()); + logger.info("generate url " + url); } } \ No newline at end of file diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/QiniuStorageTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/QiniuStorageTest.java index 8f81bafed..dab9a6ba2 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/QiniuStorageTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/QiniuStorageTest.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; import org.linlinjava.litemall.core.storage.QiniuStorage; @@ -17,6 +19,8 @@ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class QiniuStorageTest { + + private final Log logger = LogFactory.getLog(QiniuStorageTest.class); @Autowired private QiniuStorage qiniuStorage; @@ -27,10 +31,9 @@ public void test() throws IOException { qiniuStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); Resource resource = qiniuStorage.loadAsResource("litemall.png"); String url = qiniuStorage.generateUrl("litemall.png"); - System.out.println("test file " + test); - System.out.println("store file " + resource.getURI()); - System.out.println("generate url " + url); -// qiniuStorage.delete("litemall.png"); + logger.info("test file " + test); + logger.info("store file " + resource.getURI()); + logger.info("generate url " + url); } } \ No newline at end of file diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/TencentStorageTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/TencentStorageTest.java index 28b67b13c..459ecec61 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/TencentStorageTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/TencentStorageTest.java @@ -1,5 +1,7 @@ package org.linlinjava.litemall.core; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; import org.linlinjava.litemall.core.storage.TencentStorage; @@ -17,6 +19,8 @@ @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest public class TencentStorageTest { + + private Log logger = LogFactory.getLog(TencentStorageTest.class); @Autowired private TencentStorage tencentStorage; @@ -27,11 +31,9 @@ public void test() throws IOException { tencentStorage.store(new FileInputStream(test), testFile.length(), "image/png", "litemall.png"); Resource resource = tencentStorage.loadAsResource("litemall.png"); String url = tencentStorage.generateUrl("litemall.png"); - System.out.println("test file " + test); - System.out.println("store file " + resource.getURI()); - System.out.println("generate url " + url); - -// tencentStorage.delete("litemall.png"); + logger.info("test file " + test); + logger.info("store file " + resource.getURI()); + logger.info("generate url " + url); } } \ No newline at end of file diff --git a/litemall-core/src/test/java/org/linlinjava/litemall/core/util/bcrypt/BCryptTest.java b/litemall-core/src/test/java/org/linlinjava/litemall/core/util/bcrypt/BCryptTest.java index 311e3b564..1a98481b6 100644 --- a/litemall-core/src/test/java/org/linlinjava/litemall/core/util/bcrypt/BCryptTest.java +++ b/litemall-core/src/test/java/org/linlinjava/litemall/core/util/bcrypt/BCryptTest.java @@ -4,9 +4,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.junit.rules.Timeout; import org.junit.runner.RunWith; -import org.linlinjava.litemall.core.util.bcrypt.BCrypt; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @@ -16,106 +14,107 @@ @RunWith(PowerMockRunner.class) public class BCryptTest { - @Rule public final ExpectedException thrown = ExpectedException.none(); - - @Test - public void testHashpwSaltIsNull() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", null); - } - - @Test - public void testHashpwSaltTooShort() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "foo"); - } - - @Test - public void testHashpwInvalidSaltVersion() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "+2a$10$....................."); - } - - @Test - public void testHashpwInvalidSaltVersion2() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "$1a$10$....................."); - } - - @Test - public void testHashpwInvalidSaltRevision() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "$2+$10$....................."); - } - - @Test - public void testHashpwInvalidSaltRevision2() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "$2a+10$....................."); - } - - @Test - public void testHashpwSaltTooShort2() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "$2a$10+....................."); - } - - @Test - public void testHashpwMissingSaltRounds() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "$2$a10$....................."); - } - - @Test - public void testHashpwTooLittleRounds() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "$2a$03$......................"); - } - - @Test - public void testHashpwTooManyRounds() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.hashpw("foo", "$2a$32$......................"); - } - - @Test - public void testHashpw() { - Assert.assertEquals( - "$2a$10$......................0li5vIK0lccG/IXHAOP2wBncDW/oa2u", - BCrypt.hashpw("foo", "$2a$10$......................")); - - Assert.assertEquals( - "$2$09$......................GlnmyWmDnFB.MnSSUnFsiPvHsC2KPBm", - BCrypt.hashpw("foo", "$2$09$......................")); - } - - @PrepareForTest({BCrypt.class, SecureRandom.class}) - @Test - public void testGensalt() throws Exception { - PowerMockito.whenNew(SecureRandom.class).withNoArguments() - .thenReturn(PowerMockito.mock(SecureRandom.class)); - Assert.assertEquals("$2a$10$......................", BCrypt.gensalt()); - Assert.assertEquals("$2a$09$......................", BCrypt.gensalt(9)); - } - - @Test - public void testGensaltTooLittleRounds() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.gensalt(3); - } - - @Test - public void testGensaltTooManyRounds() throws IllegalArgumentException { - thrown.expect(IllegalArgumentException.class); - BCrypt.gensalt(32); - } - - @Test - public void testCheckpw() { - Assert.assertFalse(BCrypt.checkpw("foo", "$2a$10$......................")); - - final String hashed = BCrypt.hashpw("foo", BCrypt.gensalt()); - Assert.assertTrue(BCrypt.checkpw("foo", hashed)); - Assert.assertFalse(BCrypt.checkpw("bar", hashed)); - } + @Rule + public final ExpectedException thrown = ExpectedException.none(); + + @Test + public void testHashpwSaltIsNull() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", null); + } + + @Test + public void testHashpwSaltTooShort() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "foo"); + } + + @Test + public void testHashpwInvalidSaltVersion() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "+2a$10$....................."); + } + + @Test + public void testHashpwInvalidSaltVersion2() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "$1a$10$....................."); + } + + @Test + public void testHashpwInvalidSaltRevision() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "$2+$10$....................."); + } + + @Test + public void testHashpwInvalidSaltRevision2() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "$2a+10$....................."); + } + + @Test + public void testHashpwSaltTooShort2() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "$2a$10+....................."); + } + + @Test + public void testHashpwMissingSaltRounds() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "$2$a10$....................."); + } + + @Test + public void testHashpwTooLittleRounds() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "$2a$03$......................"); + } + + @Test + public void testHashpwTooManyRounds() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.hashpw("foo", "$2a$32$......................"); + } + + @Test + public void testHashpw() { + Assert.assertEquals( + "$2a$10$......................0li5vIK0lccG/IXHAOP2wBncDW/oa2u", + BCrypt.hashpw("foo", "$2a$10$......................")); + + Assert.assertEquals( + "$2$09$......................GlnmyWmDnFB.MnSSUnFsiPvHsC2KPBm", + BCrypt.hashpw("foo", "$2$09$......................")); + } + + @PrepareForTest({BCrypt.class, SecureRandom.class}) + @Test + public void testGensalt() throws Exception { + PowerMockito.whenNew(SecureRandom.class).withNoArguments() + .thenReturn(PowerMockito.mock(SecureRandom.class)); + Assert.assertEquals("$2a$10$......................", BCrypt.gensalt()); + Assert.assertEquals("$2a$09$......................", BCrypt.gensalt(9)); + } + + @Test + public void testGensaltTooLittleRounds() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.gensalt(3); + } + + @Test + public void testGensaltTooManyRounds() throws IllegalArgumentException { + thrown.expect(IllegalArgumentException.class); + BCrypt.gensalt(32); + } + + @Test + public void testCheckpw() { + Assert.assertFalse(BCrypt.checkpw("foo", "$2a$10$......................")); + + final String hashed = BCrypt.hashpw("foo", BCrypt.gensalt()); + Assert.assertTrue(BCrypt.checkpw("foo", hashed)); + Assert.assertFalse(BCrypt.checkpw("bar", hashed)); + } }