Exemplo n.º 1
0
 public static MyResponse err(MyErrorCode errorCode) {
   MyResponse response = new MyResponse();
   response.setStatus(STATUS_ERROR);
   Error error = new Error();
   error.setErrorCode(errorCode.getErrorCode());
   error.setErrorInfo(errorCode.getErrorInfo());
   response.setError(error);
   return response;
 }
  @RequestMapping(method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
  MyResponse list() {
    List<CategoryPredefined> categoryPredifinedList = categoryPredefinedService.getAll();

    List<CategoryPredefinedDTO> categoryPredefinedDTOList =
        BeanMapper.mapList(categoryPredifinedList, CategoryPredefinedDTO.class);

    return MyResponse.ok(categoryPredefinedDTOList);
  }
Exemplo n.º 3
0
  public static MyResponse ok(Object content, boolean isEncryp) {

    MyResponse response = new MyResponse();
    if (isEncryp) {
      response.encryp = true;

      JsonMapper jsonMapper = new JsonMapper();
      String jsonContent = jsonMapper.toJson(content);

      try {
        // gzip压缩
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(out);
        gzip.write(jsonContent.getBytes());
        gzip.close();

        byte[] vi = Cryptos.generateIV();
        byte[] encryByte = Cryptos.aesEncrypt(out.toByteArray(), response.getCurrentToken(), vi);
        String encrypContent = Base64.encodeBase64String(encryByte);
        String viStr = Base64.encodeBase64String(vi);
        response.setContent(viStr + ":" + encrypContent);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

    } else {
      response.setContent(content);
    }

    response.setStatus(STATUS_OK);

    return response;
  }
Exemplo n.º 4
0
 public static MyResponse noContent() {
   MyResponse response = new MyResponse();
   response.setStatus(204); // 错误码204
   response.setContent(null);
   return response;
 }
Exemplo n.º 5
0
 public static MyResponse create() {
   MyResponse response = new MyResponse();
   response.setStatus(201);
   return response;
 }
Exemplo n.º 6
0
 public static MyResponse ok(Object content) {
   MyResponse response = new MyResponse();
   response.setContent(content);
   response.setStatus(STATUS_OK);
   return response;
 }