mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Decoding postback GETs.
This commit is contained in:
parent
28e0d8cd42
commit
e31b4fead5
13 changed files with 63 additions and 17 deletions
|
@ -1,7 +1,10 @@
|
|||
package uk.ac.ic.wlgitbridge.application;
|
||||
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.util.MultiMap;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.WriteLatexAPI;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -13,9 +16,24 @@ import java.io.IOException;
|
|||
*/
|
||||
public class AttsResourceHandler extends ResourceHandler {
|
||||
|
||||
private final WriteLatexAPI writeLatexDataSource;
|
||||
|
||||
public AttsResourceHandler(WriteLatexAPI writeLatexDataSource) {
|
||||
this.writeLatexDataSource = writeLatexDataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
||||
System.out.println(baseRequest.getMethod() + " " + baseRequest.getUri());
|
||||
HttpURI uri = baseRequest.getUri();
|
||||
System.out.println(baseRequest.getMethod() + " " + uri);
|
||||
System.out.println(uri.getPath());
|
||||
MultiMap<String> multimap = new MultiMap<String>();
|
||||
uri.decodeQueryTo(multimap);
|
||||
System.out.println(multimap);
|
||||
|
||||
if (false) {
|
||||
throw new ServletException();
|
||||
}
|
||||
super.handle(target, baseRequest, request, response);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.google.gson.JsonObject;
|
|||
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.base.JSONSource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.UnexpectedPostbackException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.UnexpectedPostbackException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostExceptionBuilder;
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@ package uk.ac.ic.wlgitbridge.application;
|
|||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.UnexpectedPostbackException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.UnexpectedPostbackException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
|
|
@ -71,7 +71,7 @@ public class WLGitBridgeServer {
|
|||
HandlerCollection handlers = new HandlerCollection();
|
||||
WriteLatexAPI writeLatexDataSource = new WriteLatexAPI(new WLDataModel(rootGitDirectoryPath));
|
||||
handlers.setHandlers(new Handler[] {
|
||||
initResourceHandler(),
|
||||
initResourceHandler(writeLatexDataSource),
|
||||
new SnapshotPushPostbackHandler(writeLatexDataSource),
|
||||
initGitHandler(writeLatexDataSource)
|
||||
});
|
||||
|
@ -89,8 +89,8 @@ public class WLGitBridgeServer {
|
|||
return servletContextHandler;
|
||||
}
|
||||
|
||||
private Handler initResourceHandler() {
|
||||
ResourceHandler resourceHandler = new AttsResourceHandler();
|
||||
private Handler initResourceHandler(WriteLatexAPI writeLatexDataSource) {
|
||||
ResourceHandler resourceHandler = new AttsResourceHandler(writeLatexDataSource);
|
||||
resourceHandler.setResourceBase(new File(rootGitDirectoryPath, ".wlgb/atts").getAbsolutePath());
|
||||
return resourceHandler;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@ package uk.ac.ic.wlgitbridge.bridge;
|
|||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InvalidPostbackKeyException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.UnexpectedPostbackException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.UnexpectedPostbackException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
@ -22,6 +23,8 @@ public interface WriteLatexDataSource {
|
|||
public List<WritableRepositoryContents> getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException;
|
||||
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents, String hostname) throws SnapshotPostException, IOException, FailedConnectionException;
|
||||
|
||||
void checkPostbackKey(String projectName, String postbackKey) throws InvalidPostbackKeyException;
|
||||
|
||||
/* Called by postback thread. */
|
||||
public void postbackReceivedSuccessfully(String projectName, String postbackKey, int versionID) throws UnexpectedPostbackException;
|
||||
public void postbackReceivedWithException(String projectName, String postbackKey, SnapshotPostException exception) throws UnexpectedPostbackException;
|
||||
|
|
|
@ -7,10 +7,11 @@ import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
|||
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocRequest;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InvalidPostbackKeyException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.PostbackManager;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.SnapshotPushRequest;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.SnapshotPushRequestResult;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.UnexpectedPostbackException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.UnexpectedPostbackException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.OutOfDateException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.model.WLDataModel;
|
||||
|
@ -93,6 +94,11 @@ public class WriteLatexAPI implements WriteLatexDataSource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPostbackKey(String projectName, String postbackKey) throws InvalidPostbackKeyException {
|
||||
postbackManager.checkPostbackKey(projectName, postbackKey);
|
||||
}
|
||||
|
||||
/* Called by postback thread. */
|
||||
@Override
|
||||
public void postbackReceivedSuccessfully(String projectName, String postbackKey, int versionID) throws UnexpectedPostbackException {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.api.request.push;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InvalidPostbackKeyException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
|
||||
/**
|
||||
|
@ -49,4 +50,10 @@ public class PostbackContents {
|
|||
}
|
||||
}
|
||||
|
||||
public void checkPostbackKey(String postbackKey) throws InvalidPostbackKeyException {
|
||||
if (!postbackKey.equals(this.postbackKey)) {
|
||||
throw new InvalidPostbackKeyException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.api.request.push;
|
||||
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InvalidPostbackKeyException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.SnapshotPostException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.UnexpectedPostbackException;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.SecureRandom;
|
||||
|
@ -49,6 +51,10 @@ public class PostbackManager {
|
|||
return key;
|
||||
}
|
||||
|
||||
public void checkPostbackKey(String projectName, String postbackKey) throws InvalidPostbackKeyException {
|
||||
postbackContentsTable.get(projectName).checkPostbackKey(postbackKey);
|
||||
}
|
||||
|
||||
private String randomString() {
|
||||
return new BigInteger(130, random).toString(32);
|
||||
}
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.api.request.push;
|
||||
|
||||
/**
|
||||
* Created by Winston on 17/11/14.
|
||||
*/
|
||||
public class UnexpectedPostbackException extends Throwable {
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception;
|
||||
|
||||
/**
|
||||
* Created by Winston on 04/12/14.
|
||||
*/
|
||||
public class InvalidPostbackKeyException extends Exception {
|
||||
}
|
|
@ -2,7 +2,6 @@ package uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception;
|
|||
|
||||
import com.google.gson.JsonObject;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.UnexpectedPostbackException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 17/11/14.
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception;
|
||||
|
||||
/**
|
||||
* Created by Winston on 17/11/14.
|
||||
*/
|
||||
public class UnexpectedPostbackException extends Exception {
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package uk.ac.ic.wlgitbridge.writelatex.api.request.push;
|
||||
package uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception;
|
||||
|
||||
import org.junit.Test;
|
||||
|
Loading…
Reference in a new issue