예제 #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
  private synchronized void refreshAppList(boolean auto) {
    try {
      updating = true;

      Set<String> imgSet = getImgs();

      List<Machine> machines = MachineUtils.getMachineList();

      appDao.deleteAutoUpdatedRecords();
      HashSet<String> set = new HashSet<String>();

      for (Machine machine : machines) {
        String data = thirdAppService.getAppData(machine.getCode(), "3.0");
        AppVO appVO = jsonMapper.fromJson(data, AppVO.class);

        if (appVO.getState().equals("0000")) {
          for (AppInfo appInfo : appVO.getZone()) {
            App app = new App();
            app.setActionUrl(jsonMapper.toJson(appInfo.getData()));
            app.setUrl1080(upload(appInfo.getIcon()));
            app.setClientType(machine.getCode());
            app.setTitle(jsonMapper.toJson(new String[] {appInfo.getName()}));
            app.setUpdateRefer("app:1");

            if (auto) {
              User user = new User();
              user.setId(1L);
              app.setUser(user);
            } else {
              app.setUser(UserUtils.getUser());
            }
            appDao.save(app);
            set.add(app.getUpdateRefer());
          }
        }
      }
      for (String ur : set) {
        templateService.evictTplByUpdateRefer(ur);
      }

    } catch (Exception e) {
      throw new RuntimeException(e);
    } finally {
      updating = false;
    }
  }
예제 #3
0
 @RequestMapping("queryc")
 public void queryCosmetics(Long id, HttpServletResponse request, HttpServletResponse response)
     throws IOException {
   PrintWriter out = response.getWriter();
   Cosmetics cos = mpts.getCos(id);
   String json = mapper.toJson(cos);
   out.write(json);
   out.close();
 }
예제 #4
0
 @RequestMapping("querytype")
 public void querytype(HttpServletResponse request, HttpServletResponse response)
     throws IOException {
   PrintWriter out = response.getWriter();
   List<CosmeticType> list = mpts.getAll();
   String json = mapper.toJson(list);
   out.write(json);
   out.close();
 }
예제 #5
0
 @RequestMapping("queryct")
 public void queryCosmeticsbytype(
     Long typeid, HttpServletResponse request, HttpServletResponse response) throws IOException {
   PrintWriter out = response.getWriter();
   List<Map<String, String>> list = mpts.queryCosmeticsbytype(typeid);
   String json = mapper.toJson(list);
   out.write(json);
   out.close();
 }
예제 #6
0
 @RequestMapping("queryzixun")
 public void queryzixun(Long type, HttpServletResponse request, HttpServletResponse response)
     throws IOException {
   PrintWriter out = response.getWriter();
   List<Map<String, String>> map = mpts.queryzixun(type);
   String json = mapper.toJson(map);
   out.write(json);
   out.close();
 }
예제 #7
0
 @RequestMapping("querydtall")
 public void querydtall(int user_id, HttpServletResponse request, HttpServletResponse response)
     throws IOException {
   PrintWriter out = response.getWriter();
   List<Map<String, String>> map = mpts.querydtall(user_id);
   String json = mapper.toJson(map);
   out.write(json);
   out.close();
 }
예제 #8
0
 @RequestMapping("querycpp")
 public void querycospp(String name, HttpServletResponse request, HttpServletResponse response)
     throws IOException {
   PrintWriter out = response.getWriter();
   System.out.println("121111111111111111111111111" + name);
   List<Map<String, String>> list = mpts.querycospp(name);
   String json = mapper.toJson(list);
   out.write(json);
   out.close();
 }
 /** 处理JSR311 Validation异常. */
 @ExceptionHandler(value = {ConstraintViolationException.class})
 public final ResponseEntity<?> handleException(
     ConstraintViolationException ex, WebRequest request) {
   Map<String, String> errors =
       BeanValidators.extractPropertyAndMessage(ex.getConstraintViolations());
   String body = jsonMapper.toJson(errors);
   HttpHeaders headers = new HttpHeaders();
   headers.setContentType(MediaType.parseMediaType(MediaTypes.TEXT_PLAIN_UTF_8));
   return handleExceptionInternal(ex, body, headers, HttpStatus.BAD_REQUEST, request);
 }
예제 #10
0
  @RequestMapping("login")
  public void login(User user, HttpServletResponse request, HttpServletResponse response)
      throws IOException {
    PrintWriter out = response.getWriter();
    User user1 = new User();
    user1 = mpts.getuser(user);
    if (user1 == null || user1.getUsername() == null) {

      out.write("-1");
    } else if (user1.getPassword().equals(user.getPassword())) {
      String json = mapper.toJson(user1);
      out.write(json);
    } else {
      out.write("-2");
    }
    out.close();
  }