예제 #1
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;
  }
예제 #2
0
 public static MyResponse noContent() {
   MyResponse response = new MyResponse();
   response.setStatus(204); // 错误码204
   response.setContent(null);
   return response;
 }
예제 #3
0
 public static MyResponse ok(Object content) {
   MyResponse response = new MyResponse();
   response.setContent(content);
   response.setStatus(STATUS_OK);
   return response;
 }