X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Flibrary%2FRemoteLibraryServer.java;h=dc9688c4de69c0348a1ee7dbac4665ec581d905a;hb=b6b657954954280c9ab0efcec67f3fe4a3ae0945;hp=ada467311d1e2d77801b6a7df379ee0272dad3f4;hpb=c1b31971129284c53f79dd3ba38f32ec084d06cb;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java index ada4673..dc9688c 100644 --- a/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java +++ b/src/be/nikiroo/fanfix/library/RemoteLibraryServer.java @@ -2,7 +2,6 @@ package be.nikiroo.fanfix.library; import java.io.IOException; import java.net.URL; -import java.nio.file.AccessDeniedException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -142,14 +141,14 @@ public class RemoteLibraryServer extends ServerObject { for (Object arg : args) { trace += arg + " "; } - System.out.println(trace); + long now = System.currentTimeMillis(); + System.out.println(StringUtils.fromTime(now) + ": " + trace); Object rep = null; - Exception oops = null; try { rep = doRequest(action, command, args, rw, whitelist); - } catch (Exception e) { - oops = e; + } catch (IOException e) { + rep = new RemoteLibraryException(e, true); } commands.put(id, command); @@ -157,10 +156,6 @@ public class RemoteLibraryServer extends ServerObject { rws.put(id, rw); times.put(id, (new Date().getTime() - start)); - if (oops != null) { - throw oops; - } - return rep; } @@ -185,9 +180,12 @@ public class RemoteLibraryServer extends ServerObject { String rec = StringUtils.formatNumber(bytesReceived) + "b"; String sent = StringUtils.formatNumber(bytesSent) + "b"; - System.out.println(String.format("%s[>%s]: (%s sent, %s rec) in %d ms", - display(whitelist, rw), commands.get(id), sent, rec, - times.get(id))); + long now = System.currentTimeMillis(); + System.out.println(StringUtils.fromTime(now) + + ": " + + String.format("%s[>%s]: (%s sent, %s rec) in %d ms", + display(whitelist, rw), commands.get(id), sent, rec, + times.get(id))); commands.remove(id); times.remove(id); @@ -267,8 +265,8 @@ public class RemoteLibraryServer extends ServerObject { } } else if ("SAVE_STORY".equals(command)) { if (!rw) { - throw new AccessDeniedException("" + args[0], null, - "Read-Only remote library"); + throw new RemoteLibraryException("Read-Only remote library: " + + args[0], false); } List list = new ArrayList(); @@ -286,19 +284,19 @@ public class RemoteLibraryServer extends ServerObject { return story.getMeta().getLuid(); } else if ("IMPORT".equals(command)) { if (!rw) { - throw new AccessDeniedException("" + args[0], null, - "Read-Only remote library"); + throw new RemoteLibraryException("Read-Only remote library: " + + args[0], false); } Progress pg = createPgForwarder(action); - Story story = Instance.getLibrary().imprt( + MetaData meta = Instance.getLibrary().imprt( new URL((String) args[0]), pg); forcePgDoneSent(pg); - return story.getMeta().getLuid(); + return meta.getLuid(); } else if ("DELETE_STORY".equals(command)) { if (!rw) { - throw new AccessDeniedException("" + args[0], null, - "Read-Only remote library"); + throw new RemoteLibraryException("Read-Only remote library: " + + args[0], false); } Instance.getLibrary().delete((String) args[0]); @@ -316,8 +314,8 @@ public class RemoteLibraryServer extends ServerObject { } } else if ("SET_COVER".equals(command)) { if (!rw) { - throw new AccessDeniedException("" + args[0], "" + args[1], - "Read-Only remote library"); + throw new RemoteLibraryException("Read-Only remote library: " + + args[0] + ", " + args[1], false); } if ("SOURCE".equals(args[0])) { @@ -329,8 +327,8 @@ public class RemoteLibraryServer extends ServerObject { } } else if ("CHANGE_STA".equals(command)) { if (!rw) { - throw new AccessDeniedException("" + args[0], "" + args[1], - "Read-Only remote library"); + throw new RemoteLibraryException("Read-Only remote library: " + + args[0] + ", " + args[1], false); } Progress pg = createPgForwarder(action); @@ -339,8 +337,8 @@ public class RemoteLibraryServer extends ServerObject { forcePgDoneSent(pg); } else if ("EXIT".equals(command)) { if (!rw) { - throw new AccessDeniedException("EXIT", "", - "Read-Only remote library, cannot close it"); + throw new RemoteLibraryException( + "Read-Only remote library: EXIT", false); } stop(0, false); @@ -352,7 +350,9 @@ public class RemoteLibraryServer extends ServerObject { @Override protected void onError(Exception e) { if (e instanceof SSLException) { - System.out.println("[Client connection refused (bad key)]"); + long now = System.currentTimeMillis(); + System.out.println(StringUtils.fromTime(now) + ": " + + "[Client connection refused (bad key)]"); } else { getTraceHandler().error(e); }