diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java index 31c8029a63..ca72b14434 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/AttsResourceHandler.java @@ -4,6 +4,7 @@ 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.util.Util; import uk.ac.ic.wlgitbridge.writelatex.WriteLatexAPI; import uk.ac.ic.wlgitbridge.writelatex.api.request.push.exception.InvalidPostbackKeyException; @@ -28,7 +29,7 @@ public class AttsResourceHandler extends ResourceHandler { String method = baseRequest.getMethod(); if (method.equals("GET")) { HttpURI uri = baseRequest.getUri(); - System.out.println(method + " " + uri); + Util.sout(method + " " + uri); MultiMap multimap = new MultiMap(); uri.decodeQueryTo(multimap); String[] pathSections = uri.getPath().split("/"); diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackContents.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackContents.java index 41e5b3abf1..ee330fe5f8 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackContents.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackContents.java @@ -35,7 +35,6 @@ public class SnapshotPushPostbackContents implements JSONSource { @Override public void fromJSON(JsonElement json) { - System.out.println(json); JsonObject responseObject = json.getAsJsonObject(); String code = responseObject.get("code").getAsString(); setResult(responseObject, code); diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java index ad1aa0715b..7e90bbe8b5 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/SnapshotPushPostbackHandler.java @@ -33,12 +33,11 @@ public class SnapshotPushPostbackHandler extends AbstractHandler { String contents = Util.getContentsOfReader(request.getReader()); String[] parts = request.getRequestURI().split("/"); if (parts.length < 4) { - System.out.println("Invalid postback url"); throw new ServletException(); } String projectName = parts[1]; 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); JsonObject body = new JsonObject(); @@ -57,13 +56,13 @@ public class SnapshotPushPostbackHandler extends AbstractHandler { baseRequest.setHandled(true); } } catch (IOException e) { - e.printStackTrace(); + Util.printStackTrace(e); throw e; } catch (ServletException e) { - e.printStackTrace(); + Util.printStackTrace(e); throw e; } catch (RuntimeException e) { - e.printStackTrace(); + Util.printStackTrace(e); throw e; } } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java index 0d6fd5c66b..1a9e6262e1 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java @@ -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.InvalidProgramArgumentsException; import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException; +import uk.ac.ic.wlgitbridge.util.Util; import javax.servlet.ServletException; import java.io.IOException; @@ -35,16 +36,16 @@ public class WLGitBridgeApplication { printUsage(); System.exit(EXIT_CODE_FAILED); } 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); } 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); } try { server = new WLGitBridgeServer(config); } catch (ServletException e) { - e.printStackTrace(); + Util.printStackTrace(e); } catch (InvalidRootDirectoryPathException e) { System.out.println("Invalid root git directory path. Check your config file."); System.exit(EXIT_CODE_FAILED); diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java index 2482f9dda0..9c78718c87 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java @@ -64,16 +64,16 @@ public class WLGitBridgeServer { public void start() { try { jettyServer.start(); - System.out.println(); - System.out.println(Util.getServiceName() + "-Git Bridge server started"); - System.out.println("Listening on port: " + port); - System.out.println("Bridged to: " + writeLatexHostname); - System.out.println("Postback base URL: " + Util.getPostbackURL()); - System.out.println("Root git directory path: " + rootGitDirectoryPath); + Util.sout(); + Util.sout(Util.getServiceName() + "-Git Bridge server started"); + Util.sout("Listening on port: " + port); + Util.sout("Bridged to: " + writeLatexHostname); + Util.sout("Postback base URL: " + Util.getPostbackURL()); + Util.sout("Root git directory path: " + rootGitDirectoryPath); } catch (BindException e) { - e.printStackTrace(); + Util.printStackTrace(e); } catch (Exception e) { - e.printStackTrace(); + Util.printStackTrace(e); } } @@ -81,7 +81,7 @@ public class WLGitBridgeServer { try { jettyServer.stop(); } catch (Exception e) { - e.printStackTrace(); + Util.printStackTrace(e); } } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java index 4e16b9d433..7ec5caa615 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java @@ -32,7 +32,7 @@ public class WLRepositoryResolver implements RepositoryResolver getWritableRepositories(String projectName) throws FailedConnectionException, InvalidProjectException { - System.out.println("Fetching project: " + projectName); + Util.sout("Fetching project: " + projectName); List writableRepositoryContents = dataModel.updateProjectWithName(projectName); return writableRepositoryContents; } @@ -72,7 +70,7 @@ public class WriteLatexAPI implements WriteLatexDataSource { public void putDirectoryContentsToProjectWithName(String projectName, RawDirectoryContents directoryContents, String hostname) throws SnapshotPostException, IOException { mainProjectLock.lockForProject(projectName); try { - System.out.println("Pushing project: " + projectName); + Util.sout("Pushing project: " + projectName); String postbackKey = postbackManager.makeKeyForProject(projectName); CandidateSnapshot candidate = dataModel.createCandidateSnapshotFromProjectWithContents(projectName, directoryContents, hostname, postbackKey); SnapshotPushRequest snapshotPushRequest = new SnapshotPushRequest(candidate); @@ -83,6 +81,9 @@ public class WriteLatexAPI implements WriteLatexDataSource { } else { throw new OutOfDateException(); } + } catch (SevereSnapshotPostException e) { + e.printStackTrace(); + throw e; } catch (SnapshotPostException e) { throw e; } catch (IOException e) { diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/base/Request.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/base/Request.java index cd158f21ad..a0625ffe7f 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/base/Request.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/base/Request.java @@ -7,6 +7,7 @@ import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; import com.ning.http.client.Realm; import com.ning.http.client.Response; +import uk.ac.ic.wlgitbridge.util.Util; import uk.ac.ic.wlgitbridge.writelatex.api.request.exception.FailedConnectionException; import java.util.concurrent.ExecutionException; @@ -62,12 +63,12 @@ public abstract class Request { } private void performGetRequest() { - System.out.println("GET -> " + url); + Util.sout("GET -> " + url); request(new AsyncHttpClient().prepareGet(url)); } private void performPostRequest() { - System.out.println("POST -> " + url); + Util.sout("POST -> " + url); request(new AsyncHttpClient().preparePost(url).setBody(getPostBody()).setHeader("Content-Type", "application/json")); } @@ -77,13 +78,13 @@ public abstract class Request { @Override public T onCompleted(Response response) throws Exception { 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)); } @Override public void onThrowable(Throwable t) { - t.printStackTrace(); + Util.printStackTrace(t); error = true; } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/getdoc/exception/InvalidProjectException.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/getdoc/exception/InvalidProjectException.java index 53d22ea829..50e3fc69ef 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/getdoc/exception/InvalidProjectException.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/getdoc/exception/InvalidProjectException.java @@ -38,7 +38,6 @@ public class InvalidProjectException extends SnapshotPostException { public void fromJSON(JsonElement json) { errors = new LinkedList(); JsonArray errors = json.getAsJsonObject().get("errors").getAsJsonArray(); - System.out.println(errors); for (JsonElement error : errors) { this.errors.add(error.getAsString()); } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/PostbackContents.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/PostbackContents.java index f0bc388430..4b4f6487a7 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/PostbackContents.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/PostbackContents.java @@ -39,7 +39,6 @@ public class PostbackContents { throw new PostbackTimeoutException(); } } catch (InterruptedException e) { - e.printStackTrace(); throw new InternalErrorException(); } } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/InternalErrorException.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/InternalErrorException.java index 5aa3011f2e..4d36f5313d 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/InternalErrorException.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/InternalErrorException.java @@ -9,7 +9,7 @@ import java.util.List; /** * Created by Winston on 09/01/15. */ -public class InternalErrorException extends SnapshotPostException { +public class InternalErrorException extends SevereSnapshotPostException { @Override public String getMessage() { diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/PostbackTimeoutException.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/PostbackTimeoutException.java index cea41d61e1..e99306f430 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/PostbackTimeoutException.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/PostbackTimeoutException.java @@ -9,7 +9,7 @@ import java.util.List; /** * Created by Winston on 09/01/15. */ -public class PostbackTimeoutException extends SnapshotPostException { +public class PostbackTimeoutException extends SevereSnapshotPostException { @Override public String getMessage() { diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/SevereSnapshotPostException.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/SevereSnapshotPostException.java new file mode 100644 index 0000000000..a365f9ed58 --- /dev/null +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/SevereSnapshotPostException.java @@ -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); + } + +} diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/UnexpectedErrorException.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/UnexpectedErrorException.java index 492428a79c..5d7889af50 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/UnexpectedErrorException.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/api/request/push/exception/UnexpectedErrorException.java @@ -10,7 +10,7 @@ import java.util.List; /** * Created by Winston on 16/11/14. */ -public class UnexpectedErrorException extends SnapshotPostException { +public class UnexpectedErrorException extends SevereSnapshotPostException { private static final String[] DESCRIPTION_LINES = { "There was an internal error with the " + Util.getServiceName() + " server.", diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/BlobHash.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/BlobHash.java index 7e9513ec96..b1d508051e 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/BlobHash.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/filestore/store/BlobHash.java @@ -16,7 +16,6 @@ public class BlobHash { try { md = MessageDigest.getInstance("SHA-256"); hash = md.digest(blob); - System.out.println(Arrays.toString(hash)); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java index de0347e873..87e60675b0 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/WLDataModel.java @@ -4,6 +4,7 @@ import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshot; import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshotCallback; import uk.ac.ic.wlgitbridge.bridge.RawDirectoryContents; 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.api.request.exception.FailedConnectionException; import uk.ac.ic.wlgitbridge.writelatex.api.request.getdoc.exception.InvalidProjectException; @@ -29,9 +30,9 @@ public class WLDataModel implements CandidateSnapshotCallback { File rootGitDirectory = initRootGitDirectory(rootGitDirectoryPath); persistentStore = new WLGBPersistentStore(rootGitDirectory); projectStore = persistentStore.loadProjectStore(); - System.out.println("Loaded projects: " + projectStore.getProjectNames().size() + "."); + Util.sout("Loaded projects: " + projectStore.getProjectNames().size() + "."); fileStore = persistentStore.loadFileStore(); - System.out.println("Loaded file store and index tables."); + Util.sout("Loaded file store and index tables."); List excludedFromDeletion = projectStore.getProjectNames(); excludedFromDeletion.add(".wlgb"); WLFileStore.deleteInDirectoryApartFrom(rootGitDirectory, excludedFromDeletion.toArray(new String[] {})); diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/db/sql/SQLiteWLDatabase.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/db/sql/SQLiteWLDatabase.java index 3f73cec3c2..d539da231a 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/db/sql/SQLiteWLDatabase.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/writelatex/model/db/sql/SQLiteWLDatabase.java @@ -1,5 +1,6 @@ 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.store.FileIndexStore; 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 { File databaseFile = new File(rootGitDirectory, "/.wlgb/wlgb.db"); databaseFile.getParentFile().mkdirs(); - System.out.println("Loading data..."); + Util.sout("Loading data..."); Class.forName("org.sqlite.JDBC"); connection = DriverManager.getConnection("jdbc:sqlite:" + databaseFile.getAbsolutePath()); createTables(); diff --git a/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/base/RequestTest.java b/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/base/RequestTest.java index a168eb6f73..072030223c 100644 --- a/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/base/RequestTest.java +++ b/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/base/RequestTest.java @@ -9,22 +9,6 @@ public class RequestTest { @Test 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(); -// } } } diff --git a/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getforversion/SnapshotGetForVersionRequestTest.java b/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getforversion/SnapshotGetForVersionRequestTest.java index 04cc556a4e..d94be9c5a8 100644 --- a/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getforversion/SnapshotGetForVersionRequestTest.java +++ b/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getforversion/SnapshotGetForVersionRequestTest.java @@ -9,14 +9,6 @@ public class SnapshotGetForVersionRequestTest { @Test public void nothingToTest() { -// SnapshotGetForVersionRequest request = new SnapshotGetForVersionRequest("1826rqgsdb", 76); -// request.request(); -// try { -// SnapshotGetForVersionResult result = request.getResult(); -// } catch (Throwable throwable) { -// throwable.printStackTrace(); -// } - } diff --git a/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getsavedvers/SnapshotGetSavedVersRequestTest.java b/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getsavedvers/SnapshotGetSavedVersRequestTest.java index 25d86f62d2..6f51a249f1 100644 --- a/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getsavedvers/SnapshotGetSavedVersRequestTest.java +++ b/services/git-bridge/test/unit/uk/ac/ic/wlgitbridge/writelatex/api/request/getsavedvers/SnapshotGetSavedVersRequestTest.java @@ -9,13 +9,7 @@ public class SnapshotGetSavedVersRequestTest { @Test public void nothingToTest() { -// SnapshotGetSavedVersRequest request = new SnapshotGetSavedVersRequest("1826rqgsdb"); -// request.request(); -// try { -// System.out.println(request.getResult()); -// } catch (Throwable throwable) { -// throwable.printStackTrace(); -// } + } }