public String postFile(URLFetchService us, List<PostObj> postobjlist) throws Exception { int index; Gson gson; String linkID; List<String> linkList; HTTPRequest req; String param; gson = new Gson(); linkID = createUID(); linkList = new ArrayList<String>(); for (index = 0; index < postobjlist.size(); index++) { linkList.add(postobjlist.get(index).filelink); } param = URLEncoder.encode("postlist", "UTF-8") + "=" + URLEncoder.encode(gson.toJson(postobjlist), "UTF-8") + '&' + URLEncoder.encode("linkid", "UTF-8") + "=" + URLEncoder.encode(linkID, "UTF-8") + '&' + URLEncoder.encode("linklist", "UTF-8") + "=" + URLEncoder.encode(gson.toJson(linkList), "UTF-8"); req = new HTTPRequest( new URL("http://tnfshmoe.appspot.com/postdf89ksfxsyx9sfdex09usdjksd"), HTTPMethod.POST); req.setPayload(param.getBytes()); us.fetch(req); return linkID; }
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { int index; DatastoreService ds; MemcacheService ms; Cookie[] cookies; boolean insideFlag; String delpw; String paramOffset; String paramSize; int offset; int size; Key postObjGroupKey; Query q; List<Entity> postObjList; PostObj postObj; Gson gson; List<String> filelinkList; resp.setCharacterEncoding("UTF-8"); resp.setContentType("text/plain"); ds = DatastoreServiceFactory.getDatastoreService(); ms = MemcacheServiceFactory.getMemcacheService(); insideFlag = false; try { cookies = req.getCookies(); if (cookies.length > 0) { if (ms.contains(cookies[0].getValue()) == true) { insideFlag = true; } } } catch (Exception e) { insideFlag = false; } delpw = req.getParameter("delpw"); if (delpw != null) { if (delpw.equals("") == true) { delpw = null; } } paramOffset = req.getParameter("offset"); if (paramOffset != null) { offset = Integer.valueOf(paramOffset); } else { offset = 0; } paramSize = req.getParameter("size"); if (paramSize != null) { size = Integer.valueOf(paramSize); } else { size = 4096; } postObjGroupKey = KeyFactory.createKey("PostObjGroup", 1L); q = new Query("PostObj", postObjGroupKey); if (delpw != null) { q.addFilter("delpw", FilterOperator.EQUAL, delpw); q.addSort("delpw"); } q.addSort("posttime", SortDirection.DESCENDING); postObjList = ds.prepare(q).asList(FetchOptions.Builder.withOffset(offset).limit(size)); postObj = new PostObj(); filelinkList = new ArrayList<String>(); for (index = 0; index < postObjList.size(); index++) { postObj.getDB(postObjList.get(index)); if ((postObj.flag.equals("showgallery") == false && insideFlag == true) || (postObj.flag.equals("showgallery") == true && insideFlag == false) || delpw != null) { filelinkList.add(postObj.filelink); } } gson = new Gson(); resp.getWriter().print(gson.toJson(filelinkList)); }