Added better logging with timestamps and removed verbose http responses.

This commit is contained in:
Winston Li 2015-01-10 11:27:57 +00:00
parent ae3808e5ad
commit ca936d6630
27 changed files with 116 additions and 82 deletions

View file

@ -4,6 +4,7 @@ import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.server.handler.ResourceHandler;
import org.eclipse.jetty.util.MultiMap; import org.eclipse.jetty.util.MultiMap;
import uk.ac.ic.wlgitbridge.util.Util;
import uk.ac.ic.wlgitbridge.writelatex.WriteLatexAPI; import uk.ac.ic.wlgitbridge.writelatex.WriteLatexAPI;
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InvalidPostbackKeyException; import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InvalidPostbackKeyException;
@ -28,7 +29,7 @@ public class AttsResourceHandler extends ResourceHandler {
String method = baseRequest.getMethod(); String method = baseRequest.getMethod();
if (method.equals("GET")) { if (method.equals("GET")) {
HttpURI uri = baseRequest.getUri(); HttpURI uri = baseRequest.getUri();
System.out.println(method + " " + uri); Util.sout(method + " " + uri);
MultiMap<String> multimap = new MultiMap<String>(); MultiMap<String> multimap = new MultiMap<String>();
uri.decodeQueryTo(multimap); uri.decodeQueryTo(multimap);
String[] pathSections = uri.getPath().split("/"); String[] pathSections = uri.getPath().split("/");

View file

@ -35,7 +35,6 @@ public class SnapshotPushPostbackContents implements JSONSource {
@Override @Override
public void fromJSON(JsonElement json) { public void fromJSON(JsonElement json) {
System.out.println(json);
JsonObject responseObject = json.getAsJsonObject(); JsonObject responseObject = json.getAsJsonObject();
String code = responseObject.get("code").getAsString(); String code = responseObject.get("code").getAsString();
setResult(responseObject, code); setResult(responseObject, code);

View file

@ -33,12 +33,11 @@ public class SnapshotPushPostbackHandler extends AbstractHandler {
String contents = Util.getContentsOfReader(request.getReader()); String contents = Util.getContentsOfReader(request.getReader());
String[] parts = request.getRequestURI().split("/"); String[] parts = request.getRequestURI().split("/");
if (parts.length < 4) { if (parts.length < 4) {
System.out.println("Invalid postback url");
throw new ServletException(); throw new ServletException();
} }
String projectName = parts[1]; String projectName = parts[1];
String postbackKey = parts[2]; String postbackKey = parts[2];
System.out.println("Postback received for project: " + projectName); Util.sout(baseRequest.getMethod() + " " + baseRequest.getUri());
SnapshotPushPostbackContents postbackContents = new SnapshotPushPostbackContents(writeLatexDataSource, projectName, postbackKey, contents); SnapshotPushPostbackContents postbackContents = new SnapshotPushPostbackContents(writeLatexDataSource, projectName, postbackKey, contents);
JsonObject body = new JsonObject(); JsonObject body = new JsonObject();
@ -57,13 +56,13 @@ public class SnapshotPushPostbackHandler extends AbstractHandler {
baseRequest.setHandled(true); baseRequest.setHandled(true);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Util.printStackTrace(e);
throw e; throw e;
} catch (ServletException e) { } catch (ServletException e) {
e.printStackTrace(); Util.printStackTrace(e);
throw e; throw e;
} catch (RuntimeException e) { } catch (RuntimeException e) {
e.printStackTrace(); Util.printStackTrace(e);
throw e; throw e;
} }
} }

View file

@ -3,6 +3,7 @@ package uk.ac.ic.wlgitbridge.application;
import uk.ac.ic.wlgitbridge.application.exception.InvalidConfigFileException; import uk.ac.ic.wlgitbridge.application.exception.InvalidConfigFileException;
import uk.ac.ic.wlgitbridge.application.exception.InvalidProgramArgumentsException; import uk.ac.ic.wlgitbridge.application.exception.InvalidProgramArgumentsException;
import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException; import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
import uk.ac.ic.wlgitbridge.util.Util;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import java.io.IOException; import java.io.IOException;
@ -35,16 +36,16 @@ public class WLGitBridgeApplication {
printUsage(); printUsage();
System.exit(EXIT_CODE_FAILED); System.exit(EXIT_CODE_FAILED);
} catch (InvalidConfigFileException e) { } catch (InvalidConfigFileException e) {
System.out.println("The property for " + e.getMissingMember() + " is invalid. Check your config file."); System.err.println("The property for " + e.getMissingMember() + " is invalid. Check your config file.");
System.exit(EXIT_CODE_FAILED); System.exit(EXIT_CODE_FAILED);
} catch (IOException e) { } catch (IOException e) {
System.out.println("Invalid config file. Check the file path."); System.err.println("Invalid config file. Check the file path.");
System.exit(EXIT_CODE_FAILED); System.exit(EXIT_CODE_FAILED);
} }
try { try {
server = new WLGitBridgeServer(config); server = new WLGitBridgeServer(config);
} catch (ServletException e) { } catch (ServletException e) {
e.printStackTrace(); Util.printStackTrace(e);
} catch (InvalidRootDirectoryPathException e) { } catch (InvalidRootDirectoryPathException e) {
System.out.println("Invalid root git directory path. Check your config file."); System.out.println("Invalid root git directory path. Check your config file.");
System.exit(EXIT_CODE_FAILED); System.exit(EXIT_CODE_FAILED);

View file

@ -64,16 +64,16 @@ public class WLGitBridgeServer {
public void start() { public void start() {
try { try {
jettyServer.start(); jettyServer.start();
System.out.println(); Util.sout();
System.out.println(Util.getServiceName() + "-Git Bridge server started"); Util.sout(Util.getServiceName() + "-Git Bridge server started");
System.out.println("Listening on port: " + port); Util.sout("Listening on port: " + port);
System.out.println("Bridged to: " + writeLatexHostname); Util.sout("Bridged to: " + writeLatexHostname);
System.out.println("Postback base URL: " + Util.getPostbackURL()); Util.sout("Postback base URL: " + Util.getPostbackURL());
System.out.println("Root git directory path: " + rootGitDirectoryPath); Util.sout("Root git directory path: " + rootGitDirectoryPath);
} catch (BindException e) { } catch (BindException e) {
e.printStackTrace(); Util.printStackTrace(e);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Util.printStackTrace(e);
} }
} }
@ -81,7 +81,7 @@ public class WLGitBridgeServer {
try { try {
jettyServer.stop(); jettyServer.stop();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Util.printStackTrace(e);
} }
} }

View file

@ -32,7 +32,7 @@ public class WLRepositoryResolver implements RepositoryResolver<HttpServletReque
try { try {
return repositorySource.getRepositoryWithNameAtRootDirectory(Util.removeAllSuffixes(name, "/", ".git"), rootGitDirectory); return repositorySource.getRepositoryWithNameAtRootDirectory(Util.removeAllSuffixes(name, "/", ".git"), rootGitDirectory);
} catch (RepositoryNotFoundException e) { } catch (RepositoryNotFoundException e) {
e.printStackTrace(); Util.printStackTrace(e);
throw e; throw e;
/* /*
} catch (ServiceNotAuthorizedException e) { } catch (ServiceNotAuthorizedException e) {
@ -41,10 +41,10 @@ public class WLRepositoryResolver implements RepositoryResolver<HttpServletReque
cannot occur cannot occur
*/ */
} catch (ServiceMayNotContinueException e) { /* Such as FailedConnectionException */ } catch (ServiceMayNotContinueException e) { /* Such as FailedConnectionException */
e.printStackTrace(); Util.printStackTrace(e);
throw e; throw e;
} catch (RuntimeException e) { } catch (RuntimeException e) {
e.printStackTrace(); Util.printStackTrace(e);
throw new ServiceMayNotContinueException(e); throw new ServiceMayNotContinueException(e);
} }
} }

View file

@ -10,6 +10,7 @@ import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
import uk.ac.ic.wlgitbridge.git.handler.hook.exception.ForcedPushException; import uk.ac.ic.wlgitbridge.git.handler.hook.exception.ForcedPushException;
import uk.ac.ic.wlgitbridge.git.handler.hook.exception.WrongBranchException; import uk.ac.ic.wlgitbridge.git.handler.hook.exception.WrongBranchException;
import uk.ac.ic.wlgitbridge.git.util.RepositoryObjectTreeWalker; import uk.ac.ic.wlgitbridge.git.util.RepositoryObjectTreeWalker;
import uk.ac.ic.wlgitbridge.util.Util;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException; import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InternalErrorException; import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InternalErrorException;
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.OutOfDateException; import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.OutOfDateException;
@ -44,7 +45,7 @@ public class WriteLatexPutHook implements PreReceiveHook {
} catch (SnapshotPostException e) { } catch (SnapshotPostException e) {
handleSnapshotPostException(receivePack, receiveCommand, e); handleSnapshotPostException(receivePack, receiveCommand, e);
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); Util.printStackTrace(t);
handleSnapshotPostException(receivePack, receiveCommand, new InternalErrorException()); handleSnapshotPostException(receivePack, receiveCommand, new InternalErrorException());
} }
} }

View file

@ -5,6 +5,7 @@ import org.eclipse.jetty.server.handler.AbstractHandler;
import uk.ac.ic.wlgitbridge.test.exception.InvalidAPICallException; import uk.ac.ic.wlgitbridge.test.exception.InvalidAPICallException;
import uk.ac.ic.wlgitbridge.test.response.SnapshotResponse; import uk.ac.ic.wlgitbridge.test.response.SnapshotResponse;
import uk.ac.ic.wlgitbridge.test.response.SnapshotResponseBuilder; import uk.ac.ic.wlgitbridge.test.response.SnapshotResponseBuilder;
import uk.ac.ic.wlgitbridge.util.Util;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -30,9 +31,9 @@ public class MockSnapshotRequestHandler extends AbstractHandler {
response.getWriter().println(snapshotResponse.respond()); response.getWriter().println(snapshotResponse.respond());
new PostbackThread(baseRequest.getReader(), snapshotResponse.postback()).startIfNotNull(); new PostbackThread(baseRequest.getReader(), snapshotResponse.postback()).startIfNotNull();
} catch (InvalidAPICallException e) { } catch (InvalidAPICallException e) {
e.printStackTrace(); Util.printStackTrace(e);
} catch (RuntimeException e) { } catch (RuntimeException e) {
e.printStackTrace(); Util.printStackTrace(e);
} }
baseRequest.setHandled(true); baseRequest.setHandled(true);
} }

View file

@ -4,6 +4,7 @@ import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import uk.ac.ic.wlgitbridge.test.response.SnapshotResponseBuilder; import uk.ac.ic.wlgitbridge.test.response.SnapshotResponseBuilder;
import uk.ac.ic.wlgitbridge.test.state.SnapshotAPIState; import uk.ac.ic.wlgitbridge.test.state.SnapshotAPIState;
import uk.ac.ic.wlgitbridge.util.Util;
/** /**
* Created by Winston on 09/01/15. * Created by Winston on 09/01/15.
@ -24,10 +25,9 @@ public class MockSnapshotServer {
try { try {
server.start(); server.start();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); Util.printStackTrace(e);
} }
port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort(); port = ((NetworkConnector) server.getConnectors()[0]).getLocalPort();
System.out.println(port);
} }
public void setState(SnapshotAPIState state) { public void setState(SnapshotAPIState state) {

View file

@ -3,6 +3,7 @@ package uk.ac.ic.wlgitbridge.test.server;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.AsyncHttpClient;
import uk.ac.ic.wlgitbridge.util.Util;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
@ -28,11 +29,11 @@ public class PostbackThread extends Thread {
try { try {
new AsyncHttpClient().preparePost(url).setBody(postback).execute().get().getResponseBody(); new AsyncHttpClient().preparePost(url).setBody(postback).execute().get().getResponseBody();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Util.printStackTrace(e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); Util.printStackTrace(e);
} catch (ExecutionException e) { } catch (ExecutionException e) {
e.printStackTrace(); Util.printStackTrace(e);
} }
} }

View file

@ -4,6 +4,10 @@ import uk.ac.ic.wlgitbridge.application.SSLConfig;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/** /**
* Created by Winston on 19/11/14. * Created by Winston on 19/11/14.
@ -15,6 +19,7 @@ public class Util {
private static SSLConfig SSL_CONFIG; private static SSLConfig SSL_CONFIG;
private static int PORT; private static int PORT;
private static String POSTBACK_URL; private static String POSTBACK_URL;
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
public static String entries(int entries) { public static String entries(int entries) {
if (entries == 1) { if (entries == 1) {
@ -85,4 +90,41 @@ public class Util {
public static String getPostbackURL() { public static String getPostbackURL() {
return POSTBACK_URL; return POSTBACK_URL;
} }
private static void println(PrintStream ps, String ln) {
ps.println(getStringBuilder().append(ln));
}
public static void sout(String ln) {
println(System.out, ln);
}
public static void serr(String ln) {
println(System.err, ln);
}
private static StringBuilder getStringBuilder() {
StringBuilder sb = new StringBuilder("[");
sb.append(dateFormat.format(new Date()));
sb.append("] ");
return sb;
}
public static void sout() {
sout("");
}
public static void serr() {
serr("");
}
public static void serr(Object obj) {
serr(obj.toString());
}
public static void printStackTrace(Throwable t) {
serr();
t.printStackTrace();
}
} }

View file

@ -1,5 +1,6 @@
package uk.ac.ic.wlgitbridge.writelatex; package uk.ac.ic.wlgitbridge.writelatex;
import uk.ac.ic.wlgitbridge.util.Util;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException; 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.SnapshotGetDocRequest;
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocResult; import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.SnapshotGetDocResult;
@ -38,7 +39,7 @@ public class SnapshotFetcher implements PersistentStoreSource {
for (Snapshot snapshot : newSnapshots) { for (Snapshot snapshot : newSnapshots) {
persistentStore.addSnapshot(projectName, snapshot.getVersionID()); persistentStore.addSnapshot(projectName, snapshot.getVersionID());
} }
System.out.println("Fetched snapshots: " + newSnapshots); Util.sout("Fetched snapshots: " + newSnapshots);
return newSnapshots; return newSnapshots;
} }

View file

@ -38,7 +38,6 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
jsonObject.addProperty("latestVerId", previousVersionID); jsonObject.addProperty("latestVerId", previousVersionID);
jsonObject.add("files", getFilesAsJson()); jsonObject.add("files", getFilesAsJson());
jsonObject.addProperty("postbackUrl", projectURL + "/" + postbackKey + "/postback"); jsonObject.addProperty("postbackUrl", projectURL + "/" + postbackKey + "/postback");
System.out.println(jsonObject);
return jsonObject; return jsonObject;
} }

View file

@ -4,16 +4,14 @@ import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshot;
import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents; import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents;
import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents; import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents;
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource; import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
import uk.ac.ic.wlgitbridge.util.Util;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException; 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.SnapshotGetDocRequest;
import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException; 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.PostbackManager;
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.SnapshotPushRequest; 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.SnapshotPushRequestResult;
import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.UnexpectedPostbackException; import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.*;
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; import uk.ac.ic.wlgitbridge.writelatex.model.WLDataModel;
import java.io.IOException; import java.io.IOException;
@ -63,7 +61,7 @@ public class WriteLatexAPI implements WriteLatexDataSource {
@Override @Override
public List<WritableRepositoryContents> getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException { public List<WritableRepositoryContents> getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException {
System.out.println("Fetching project: " + projectName); Util.sout("Fetching project: " + projectName);
List<WritableRepositoryContents> writableRepositoryContents = dataModel.updateProjectWithName(projectName); List<WritableRepositoryContents> writableRepositoryContents = dataModel.updateProjectWithName(projectName);
return writableRepositoryContents; return writableRepositoryContents;
} }
@ -72,7 +70,7 @@ public class WriteLatexAPI implements WriteLatexDataSource {
public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents, String hostname) throws SnapshotPostException, IOException { public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents, String hostname) throws SnapshotPostException, IOException {
mainProjectLock.lockForProject(projectName); mainProjectLock.lockForProject(projectName);
try { try {
System.out.println("Pushing project: " + projectName); Util.sout("Pushing project: " + projectName);
String postbackKey = postbackManager.makeKeyForProject(projectName); String postbackKey = postbackManager.makeKeyForProject(projectName);
CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents, hostname, postbackKey); CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents, hostname, postbackKey);
SnapshotPushRequest snapshotPushRequest = new SnapshotPushRequest(candidate); SnapshotPushRequest snapshotPushRequest = new SnapshotPushRequest(candidate);
@ -83,6 +81,9 @@ public class WriteLatexAPI implements WriteLatexDataSource {
} else { } else {
throw new OutOfDateException(); throw new OutOfDateException();
} }
} catch (SevereSnapshotPostException e) {
e.printStackTrace();
throw e;
} catch (SnapshotPostException e) { } catch (SnapshotPostException e) {
throw e; throw e;
} catch (IOException e) { } catch (IOException e) {

View file

@ -7,6 +7,7 @@ import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
import com.ning.http.client.Realm; import com.ning.http.client.Realm;
import com.ning.http.client.Response; import com.ning.http.client.Response;
import uk.ac.ic.wlgitbridge.util.Util;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException; import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -62,12 +63,12 @@ public abstract class Request<T extends Result> {
} }
private void performGetRequest() { private void performGetRequest() {
System.out.println("GET -> " + url); Util.sout("GET -> " + url);
request(new AsyncHttpClient().prepareGet(url)); request(new AsyncHttpClient().prepareGet(url));
} }
private void performPostRequest() { private void performPostRequest() {
System.out.println("POST -> " + url); Util.sout("POST -> " + url);
request(new AsyncHttpClient().preparePost(url).setBody(getPostBody()).setHeader("Content-Type", "application/json")); request(new AsyncHttpClient().preparePost(url).setBody(getPostBody()).setHeader("Content-Type", "application/json"));
} }
@ -77,13 +78,13 @@ public abstract class Request<T extends Result> {
@Override @Override
public T onCompleted(Response response) throws Exception { public T onCompleted(Response response) throws Exception {
String body = response.getResponseBody(); String body = response.getResponseBody();
System.out.println(response.getStatusText() + " (" + body.length() + " data bytes) -> " + url); Util.sout(response.getStatusCode() + " " + response.getStatusText() + " (" + body.length() + "B) -> " + url);
return parseResponse(new Gson().fromJson(body, JsonElement.class)); return parseResponse(new Gson().fromJson(body, JsonElement.class));
} }
@Override @Override
public void onThrowable(Throwable t) { public void onThrowable(Throwable t) {
t.printStackTrace(); Util.printStackTrace(t);
error = true; error = true;
} }

View file

@ -38,7 +38,6 @@ public class InvalidProjectException extends SnapshotPostException {
public void fromJSON(JsonElement json) { public void fromJSON(JsonElement json) {
errors = new LinkedList<String>(); errors = new LinkedList<String>();
JsonArray errors = json.getAsJsonObject().get("errors").getAsJsonArray(); JsonArray errors = json.getAsJsonObject().get("errors").getAsJsonArray();
System.out.println(errors);
for (JsonElement error : errors) { for (JsonElement error : errors) {
this.errors.add(error.getAsString()); this.errors.add(error.getAsString());
} }

View file

@ -39,7 +39,6 @@ public class PostbackContents {
throw new PostbackTimeoutException(); throw new PostbackTimeoutException();
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace();
throw new InternalErrorException(); throw new InternalErrorException();
} }
} }

View file

@ -9,7 +9,7 @@ import java.util.List;
/** /**
* Created by Winston on 09/01/15. * Created by Winston on 09/01/15.
*/ */
public class InternalErrorException extends SnapshotPostException { public class InternalErrorException extends SevereSnapshotPostException {
@Override @Override
public String getMessage() { public String getMessage() {

View file

@ -9,7 +9,7 @@ import java.util.List;
/** /**
* Created by Winston on 09/01/15. * Created by Winston on 09/01/15.
*/ */
public class PostbackTimeoutException extends SnapshotPostException { public class PostbackTimeoutException extends SevereSnapshotPostException {
@Override @Override
public String getMessage() { public String getMessage() {

View file

@ -0,0 +1,18 @@
package uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception;
import com.google.gson.JsonElement;
/**
* Created by Winston on 10/01/15.
*/
public abstract class SevereSnapshotPostException extends SnapshotPostException {
public SevereSnapshotPostException() {
super();
}
public SevereSnapshotPostException(JsonElement json) {
super(json);
}
}

View file

@ -10,7 +10,7 @@ import java.util.List;
/** /**
* Created by Winston on 16/11/14. * Created by Winston on 16/11/14.
*/ */
public class UnexpectedErrorException extends SnapshotPostException { public class UnexpectedErrorException extends SevereSnapshotPostException {
private static final String[] DESCRIPTION_LINES = { private static final String[] DESCRIPTION_LINES = {
"There was an internal error with the " + Util.getServiceName() + " server.", "There was an internal error with the " + Util.getServiceName() + " server.",

View file

@ -16,7 +16,6 @@ public class BlobHash {
try { try {
md = MessageDigest.getInstance("SHA-256"); md = MessageDigest.getInstance("SHA-256");
hash = md.digest(blob); hash = md.digest(blob);
System.out.println(Arrays.toString(hash));
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -4,6 +4,7 @@ import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshot;
import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshotCallback; import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshotCallback;
import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents; import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents;
import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents; import uk.ac.ic.wlgitbridge.bridge.WritableRepositoryContents;
import uk.ac.ic.wlgitbridge.util.Util;
import uk.ac.ic.wlgitbridge.writelatex.WLDirectoryNodeSnapshot; import uk.ac.ic.wlgitbridge.writelatex.WLDirectoryNodeSnapshot;
import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException; 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.getdoc.exception.InvalidProjectException;
@ -29,9 +30,9 @@ public class WLDataModel implements CandidateSnapshotCallback {
File rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath); File rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath);
persistentStore = new WLGBPersistentStore(rootGitDirectory); persistentStore = new WLGBPersistentStore(rootGitDirectory);
projectStore = persistentStore.loadProjectStore(); projectStore = persistentStore.loadProjectStore();
System.out.println("Loaded projects: " + projectStore.getProjectNames().size() + "."); Util.sout("Loaded projects: " + projectStore.getProjectNames().size() + ".");
fileStore = persistentStore.loadFileStore(); fileStore = persistentStore.loadFileStore();
System.out.println("Loaded file store and index tables."); Util.sout("Loaded file store and index tables.");
List<String> excludedFromDeletion = projectStore.getProjectNames(); List<String> excludedFromDeletion = projectStore.getProjectNames();
excludedFromDeletion.add(".wlgb"); excludedFromDeletion.add(".wlgb");
WLFileStore.deleteInDirectoryApartFrom(rootGitDirectory, excludedFromDeletion.toArray(new String[] {})); WLFileStore.deleteInDirectoryApartFrom(rootGitDirectory, excludedFromDeletion.toArray(new String[] {}));

View file

@ -1,5 +1,6 @@
package uk.ac.ic.wlgitbridge.writelatex.model.db.sql; package uk.ac.ic.wlgitbridge.writelatex.model.db.sql;
import uk.ac.ic.wlgitbridge.util.Util;
import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode; import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore; import uk.ac.ic.wlgitbridge.writelatex.filestore.store.FileIndexStore;
import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetFileNodesForProjectNameSQLQuery; import uk.ac.ic.wlgitbridge.writelatex.model.db.sql.query.GetFileNodesForProjectNameSQLQuery;
@ -29,7 +30,7 @@ public class SQLiteWLDatabase {
public SQLiteWLDatabase(File rootGitDirectory) throws SQLException, ClassNotFoundException { public SQLiteWLDatabase(File rootGitDirectory) throws SQLException, ClassNotFoundException {
File databaseFile = new File(rootGitDirectory, "/.wlgb/wlgb.db"); File databaseFile = new File(rootGitDirectory, "/.wlgb/wlgb.db");
databaseFile.getParentFile().mkdirs(); databaseFile.getParentFile().mkdirs();
System.out.println("Loading data..."); Util.sout("Loading data...");
Class.forName("org.sqlite.JDBC"); Class.forName("org.sqlite.JDBC");
connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath()); connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath());
createTables(); createTables();

View file

@ -9,22 +9,6 @@ public class RequestTest {
@Test @Test
public void nothingToTest() { public void nothingToTest() {
// String projectName = "1826rqgsdb";
// Request getDoc = new SnapshotGetDocRequest(projectName);
// Request getSavedVers = new SnapshotGetSavedVersRequest(projectName);
// Request getForVersion = new SnapshotGetForVersionRequest(projectName, 76);
//
// getDoc.request();
// getSavedVers.request();
// getForVersion.request();
//
// try {
// System.out.println(getDoc.getResult());
// System.out.println(getSavedVers.getResult());
// System.out.println(getForVersion.getResult());
// } catch (Throwable e) {
// e.printStackTrace();
// }
} }
} }

View file

@ -9,14 +9,6 @@ public class SnapshotGetForVersionRequestTest {
@Test @Test
public void nothingToTest() { public void nothingToTest() {
// SnapshotGetForVersionRequest request = new SnapshotGetForVersionRequest("1826rqgsdb", 76);
// request.request();
// try {
// SnapshotGetForVersionResult result = request.getResult();
// } catch (Throwable throwable) {
// throwable.printStackTrace();
// }
} }

View file

@ -9,13 +9,7 @@ public class SnapshotGetSavedVersRequestTest {
@Test @Test
public void nothingToTest() { public void nothingToTest() {
// SnapshotGetSavedVersRequest request = new SnapshotGetSavedVersRequest("1826rqgsdb");
// request.request();
// try {
// System.out.println(request.getResult());
// } catch (Throwable throwable) {
// throwable.printStackTrace();
// }
} }
} }