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;
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);
rws.put(id, rw);
times.put(id, (new Date().getTime() - start));
- if (oops != null) {
- throw oops;
- }
-
return rep;
}
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);
}
} 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<Object> list = new ArrayList<Object>();
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);
return story.getMeta().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]);
}
} 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])) {
}
} 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);
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);
@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);
}