@Action( value = "uploadHistory", results = {@Result(name = SUCCESS, location = "/upload/apkUpload.jsp")}) public String uploadHistory() { result.put("apkUploads", apkUploadService.findAll()); return SUCCESS; }
@Action( value = "apkUpload", results = {@Result(name = SUCCESS, type = "redirectAction", location = "uploadHistory")}) public String apkUpload() { if (apk == null || StringUtils.isEmpty(apkFileName)) { return ERROR; } if (!apkFileName.endsWith(".apk")) { return ERROR; } if (!doNotModifyFileName) { String noSuffixFileName = apkFileName.substring(0, apkFileName.length() - 4); noSuffixFileName = noSuffixFileName.replaceAll("[^a-zA-z0-9_.]", "_"); apkFileName = noSuffixFileName + "_" + sdf.format(new Date()) + ".apk"; } byte[] bytes = null; try { bytes = FileUtils.readFileToByteArray(apk); } catch (IOException e2) { e2.printStackTrace(); } if (bytes == null) { return ERROR; } byte[] apkNameBytes = apkFileName.getBytes(); String apkSizeName = apkFileName + "_size"; String apkSize = bytes.length + ""; String config = null; String redisConfig = null; JSONArray redisArr = null; JSONArray arr = null; try { config = FileUtility.readFileToString( new File( this.getClass().getResource("/config/config_apk_upload.properties").getFile()), "UTF-8"); redisConfig = FileUtility.readFileToString( new File( this.getClass() .getResource("/config/config_apk_upload_redis.properties") .getFile()), "UTF-8"); redisArr = JSONArray.fromObject(redisConfig); arr = JSONArray.fromObject(config); } catch (IOException e) { e.printStackTrace(); } if (redisArr != null) { for (int i = 0; i < redisArr.size(); i++) { JSONObject json = redisArr.getJSONObject(i); String host = json.getString("host"); int port = json.getInt("port"); RedisFactory redisFactory = new RedisFactory(host, port); Jedis jedis = redisFactory.getJedis(); try { jedis.set(apkNameBytes, bytes); jedis.set(apkSizeName, apkSize); } catch (Exception e1) { e1.printStackTrace(); } finally { RedisUtil.returnResource(jedis); } } } if (arr != null) { List<FilePart> files = new ArrayList<FilePart>(); try { files.add(new FilePart("file", apk)); } catch (FileNotFoundException e) { e.printStackTrace(); } for (int i = 0; i < arr.size(); i++) { JSONObject json = arr.getJSONObject(i); String url = json.getString("url"); String folder = json.getString("folder"); Map<String, String> params = new HashMap<String, String>(); params.put("fileName", apkFileName); params.put("folder", folder); String msg = HttpUtility.upload(url, params, files); json.put("result", msg); } } ApkUploadBean bean = new ApkUploadBean(); bean.setMsg(arr == null ? null : arr.toString()); bean.setCreateDate(new Date()); if ("ori".equals(urlType)) { String oriDownloadUrlPrefix = Config.getInstance().getString("toolbox.oriDownloadUrlPrefix"); bean.setFileName(oriDownloadUrlPrefix + apkFileName); } else { bean.setFileName(apkFileName); } bean.setUser(""); apkUploadService.save(bean); return SUCCESS; }