Made a better postback key.

This commit is contained in:
Winston Li 2014-12-04 21:38:41 +00:00
parent 1561111a0b
commit 4dc093fcee
2 changed files with 15 additions and 3 deletions

View file

@ -26,9 +26,13 @@ public class SnapshotPushPostbackHandler extends AbstractHandler {
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (request.getMethod().equals("POST") && request.getPathInfo().endsWith("postback")) {
String contents = getContentsOfReader(request.getReader());
String projectName = request.getRequestURI().split("/")[1];
String[] parts = request.getRequestURI().split("/");
if (parts.length < 4) {
throw new ServletException();
}
String projectName = parts[1];
String postbackKey = parts[2];
System.out.println("Postback received for project: " + projectName);
String postbackKey = "postback";
SnapshotPushPostbackContents postbackContents = new SnapshotPushPostbackContents(writeLatexDataSource, projectName, postbackKey, contents);
try {
postbackContents.processPostback();

View file

@ -2,6 +2,8 @@ package uk.ac.ic.wlgitbridge.writelatex.api.request.push;
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.HashMap;
import java.util.Map;
@ -10,9 +12,11 @@ import java.util.Map;
*/
public class PostbackManager {
private final SecureRandom random;
private final Map<String, PostbackContents> postbackContentsTable;
public PostbackManager() {
random = new SecureRandom();
postbackContentsTable = new HashMap<String, PostbackContents>();
}
@ -39,10 +43,14 @@ public class PostbackManager {
}
public String makeKeyForProject(String projectName) {
String key = "postback";
String key = System.currentTimeMillis() + randomString();
PostbackContents contents = new PostbackContents(key);
postbackContentsTable.put(projectName, contents);
return key;
}
private String randomString() {
return new BigInteger(130, random).toString(32);
}
}