id
stringlengths
7
14
text
stringlengths
1
106k
160999_75
public void start() { if (!enabled) { return; } LOG.info("Start the RequestPath collector"); immutableRequestsMap.forEach((opType, pathStatsQueue) -> pathStatsQueue.start()); // Schedule to log the top used read/write paths every 5 mins scheduledExecutor.scheduleWithFixedDelay(() -> { LOG.info("%nHere are the top Read paths:"); logTopPaths(aggregatePaths(4, queue -> !queue.isWriteOperation()), entry -> LOG.info("{} : {}", entry.getKey(), entry.getValue())); LOG.info("%nHere are the top Write paths:"); logTopPaths(aggregatePaths(4, queue -> queue.isWriteOperation()), entry -> LOG.info("{} : {}", entry.getKey(), entry.getValue())); }, COLLECTOR_INITIAL_DELAY, COLLECTOR_DELAY, TimeUnit.MINUTES); }
160999_76
public static String getUser(Id id) { AuthenticationProvider provider = ProviderRegistry.getProvider(id.getScheme()); return provider == null ? null : provider.getUserName(id.getId()); }
160999_77
public static String getUser(Id id) { AuthenticationProvider provider = ProviderRegistry.getProvider(id.getScheme()); return provider == null ? null : provider.getUserName(id.getId()); }
160999_78
public void trackReceived(long timestamp) { if (enabled) { receivedBuffer.write(new BufferedMessage(timestamp)); } }
160999_79
public void dumpToLog(String serverAddress) { if (!enabled) { return; } logMessages(serverAddress, receivedBuffer, Direction.RECEIVED); logMessages(serverAddress, sentBuffer, Direction.SENT); }
160999_80
public static String[] getHostAndPort(String s) throws ConfigException { if (s.startsWith("[")) { int i = s.indexOf("]"); if (i < 0) { throw new ConfigException(s + " starts with '[' but has no matching ']:'"); } if (i + 2 == s.length()) { throw new ConfigException(s + " doesn't have a port after colon"); } if (i + 2 < s.length()) { String[] sa = s.substring(i + 2).split(":"); String[] nsa = new String[sa.length + 1]; nsa[0] = s.substring(1, i); System.arraycopy(sa, 0, nsa, 1, sa.length); return nsa; } return new String[]{s.replaceAll("\\[|\\]", "")}; } else { return s.split(":"); } }
160999_81
public static String[] getHostAndPort(String s) throws ConfigException { if (s.startsWith("[")) { int i = s.indexOf("]"); if (i < 0) { throw new ConfigException(s + " starts with '[' but has no matching ']:'"); } if (i + 2 == s.length()) { throw new ConfigException(s + " doesn't have a port after colon"); } if (i + 2 < s.length()) { String[] sa = s.substring(i + 2).split(":"); String[] nsa = new String[sa.length + 1]; nsa[0] = s.substring(1, i); System.arraycopy(sa, 0, nsa, 1, sa.length); return nsa; } return new String[]{s.replaceAll("\\[|\\]", "")}; } else { return s.split(":"); } }
160999_82
public static String[] getHostAndPort(String s) throws ConfigException { if (s.startsWith("[")) { int i = s.indexOf("]"); if (i < 0) { throw new ConfigException(s + " starts with '[' but has no matching ']:'"); } if (i + 2 == s.length()) { throw new ConfigException(s + " doesn't have a port after colon"); } if (i + 2 < s.length()) { String[] sa = s.substring(i + 2).split(":"); String[] nsa = new String[sa.length + 1]; nsa[0] = s.substring(1, i); System.arraycopy(sa, 0, nsa, 1, sa.length); return nsa; } return new String[]{s.replaceAll("\\[|\\]", "")}; } else { return s.split(":"); } }
160999_83
public static String[] getHostAndPort(String s) throws ConfigException { if (s.startsWith("[")) { int i = s.indexOf("]"); if (i < 0) { throw new ConfigException(s + " starts with '[' but has no matching ']:'"); } if (i + 2 == s.length()) { throw new ConfigException(s + " doesn't have a port after colon"); } if (i + 2 < s.length()) { String[] sa = s.substring(i + 2).split(":"); String[] nsa = new String[sa.length + 1]; nsa[0] = s.substring(1, i); System.arraycopy(sa, 0, nsa, 1, sa.length); return nsa; } return new String[]{s.replaceAll("\\[|\\]", "")}; } else { return s.split(":"); } }
160999_84
public static String[] getHostAndPort(String s) throws ConfigException { if (s.startsWith("[")) { int i = s.indexOf("]"); if (i < 0) { throw new ConfigException(s + " starts with '[' but has no matching ']:'"); } if (i + 2 == s.length()) { throw new ConfigException(s + " doesn't have a port after colon"); } if (i + 2 < s.length()) { String[] sa = s.substring(i + 2).split(":"); String[] nsa = new String[sa.length + 1]; nsa[0] = s.substring(1, i); System.arraycopy(sa, 0, nsa, 1, sa.length); return nsa; } return new String[]{s.replaceAll("\\[|\\]", "")}; } else { return s.split(":"); } }
160999_85
public File create(String path) { File file = new File(path); return validate(file); }
160999_86
public File create(String path) { File file = new File(path); return validate(file); }
160999_87
public File create(String path) { File file = new File(path); return validate(file); }
160999_88
public File create(String path) { File file = new File(path); return validate(file); }
160999_89
public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) { return null; } byte[] data = new byte[32]; try { data = Util.marshallTxnEntry(request.getHdr(), request.getTxn(), request.getTxnDigest()); } catch (IOException e) { LOG.error("This really should be impossible", e); } return data; }
160999_90
public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) { return null; } byte[] data = new byte[32]; try { data = Util.marshallTxnEntry(request.getHdr(), request.getTxn(), request.getTxnDigest()); } catch (IOException e) { LOG.error("This really should be impossible", e); } return data; }
160999_91
public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) { return null; } byte[] data = new byte[32]; try { data = Util.marshallTxnEntry(request.getHdr(), request.getTxn(), request.getTxnDigest()); } catch (IOException e) { LOG.error("This really should be impossible", e); } return data; }
160999_92
public static byte[] serializeRequest(Request request) { if (request == null || request.getHdr() == null) { return null; } byte[] data = new byte[32]; try { data = Util.marshallTxnEntry(request.getHdr(), request.getTxn(), request.getTxnDigest()); } catch (IOException e) { LOG.error("This really should be impossible", e); } return data; }
160999_93
@SuppressWarnings("unchecked") public CircularBuffer(Class<T> clazz, int capacity) { if (capacity <= 0) { throw new IllegalArgumentException("CircularBuffer capacity should be greater than 0"); } this.buffer = (T[]) Array.newInstance(clazz, capacity); this.capacity = capacity; }
160999_94
public void processRequest(Request request) { LOG.debug("Processing request:: {}", request); if (LOG.isTraceEnabled()) { long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; if (request.type == OpCode.ping) { traceMask = ZooTrace.SERVER_PING_TRACE_MASK; } ZooTrace.logRequest(LOG, traceMask, 'E', request, ""); } ProcessTxnResult rc = null; if (!request.isThrottled()) { rc = applyRequest(request); } if (request.cnxn == null) { return; } ServerCnxn cnxn = request.cnxn; long lastZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); String lastOp = "NA"; // Notify ZooKeeperServer that the request has finished so that it can // update any request accounting/throttling limits zks.decInProcess(); zks.requestFinished(request); Code err = Code.OK; Record rsp = null; String path = null; int responseSize = 0; try { if (request.getHdr() != null && request.getHdr().getType() == OpCode.error) { AuditHelper.addAuditLog(request, rc, true); /* * When local session upgrading is disabled, leader will * reject the ephemeral node creation due to session expire. * However, if this is the follower that issue the request, * it will have the correct error code, so we should use that * and report to user */ if (request.getException() != null) { throw request.getException(); } else { throw KeeperException.create(KeeperException.Code.get(((ErrorTxn) request.getTxn()).getErr())); } } KeeperException ke = request.getException(); if (ke instanceof SessionMovedException) { throw ke; } if (ke != null && request.type != OpCode.multi) { throw ke; } LOG.debug("{}", request); if (request.isStale()) { ServerMetrics.getMetrics().STALE_REPLIES.add(1); } if (request.isThrottled()) { throw KeeperException.create(Code.THROTTLEDOP); } AuditHelper.addAuditLog(request, rc); switch (request.type) { case OpCode.ping: { lastOp = "PING"; updateStats(request, lastOp, lastZxid); responseSize = cnxn.sendResponse(new ReplyHeader(ClientCnxn.PING_XID, lastZxid, 0), null, "response"); return; } case OpCode.createSession: { lastOp = "SESS"; updateStats(request, lastOp, lastZxid); zks.finishSessionInit(request.cnxn, true); return; } case OpCode.multi: { lastOp = "MULT"; rsp = new MultiResponse(); for (ProcessTxnResult subTxnResult : rc.multiResult) { OpResult subResult; switch (subTxnResult.type) { case OpCode.check: subResult = new CheckResult(); break; case OpCode.create: subResult = new CreateResult(subTxnResult.path); break; case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: subResult = new CreateResult(subTxnResult.path, subTxnResult.stat); break; case OpCode.delete: case OpCode.deleteContainer: subResult = new DeleteResult(); break; case OpCode.setData: subResult = new SetDataResult(subTxnResult.stat); break; case OpCode.error: subResult = new ErrorResult(subTxnResult.err); if (subTxnResult.err == Code.SESSIONMOVED.intValue()) { throw new SessionMovedException(); } break; default: throw new IOException("Invalid type of op"); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.multiRead: { lastOp = "MLTR"; MultiOperationRecord multiReadRecord = new MultiOperationRecord(); ByteBufferInputStream.byteBuffer2Record(request.request, multiReadRecord); rsp = new MultiResponse(); OpResult subResult; for (Op readOp : multiReadRecord) { try { Record rec; switch (readOp.getType()) { case OpCode.getChildren: rec = handleGetChildrenRequest(readOp.toRequestRecord(), cnxn, request.authInfo); subResult = new GetChildrenResult(((GetChildrenResponse) rec).getChildren()); break; case OpCode.getData: rec = handleGetDataRequest(readOp.toRequestRecord(), cnxn, request.authInfo); GetDataResponse gdr = (GetDataResponse) rec; subResult = new GetDataResult(gdr.getData(), gdr.getStat()); break; default: throw new IOException("Invalid type of readOp"); } } catch (KeeperException e) { subResult = new ErrorResult(e.code().intValue()); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.create: { lastOp = "CREA"; rsp = new CreateResponse(rc.path); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: { lastOp = "CREA"; rsp = new Create2Response(rc.path, rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.delete: case OpCode.deleteContainer: { lastOp = "DELE"; err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.setData: { lastOp = "SETD"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.reconfig: { lastOp = "RECO"; rsp = new GetDataResponse( ((QuorumZooKeeperServer) zks).self.getQuorumVerifier().toString().getBytes(), rc.stat); err = Code.get(rc.err); break; } case OpCode.setACL: { lastOp = "SETA"; rsp = new SetACLResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.closeSession: { lastOp = "CLOS"; err = Code.get(rc.err); break; } case OpCode.sync: { lastOp = "SYNC"; SyncRequest syncRequest = new SyncRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, syncRequest); rsp = new SyncResponse(syncRequest.getPath()); requestPathMetricsCollector.registerRequest(request.type, syncRequest.getPath()); break; } case OpCode.check: { lastOp = "CHEC"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); break; } case OpCode.exists: { lastOp = "EXIS"; // TODO we need to figure out the security requirement for this! ExistsRequest existsRequest = new ExistsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, existsRequest); path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException(); } Stat stat = zks.getZKDatabase().statNode(path, existsRequest.getWatch() ? cnxn : null); rsp = new ExistsResponse(stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getData: { lastOp = "GETD"; GetDataRequest getDataRequest = new GetDataRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getDataRequest); path = getDataRequest.getPath(); rsp = handleGetDataRequest(getDataRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.setWatches: { lastOp = "SETW"; SetWatches setWatches = new SetWatches(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase() .setWatches( relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), Collections.emptyList(), Collections.emptyList(), cnxn); break; } case OpCode.setWatches2: { lastOp = "STW2"; SetWatches2 setWatches = new SetWatches2(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase().setWatches(relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), setWatches.getPersistentWatches(), setWatches.getPersistentRecursiveWatches(), cnxn); break; } case OpCode.addWatch: { lastOp = "ADDW"; AddWatchRequest addWatcherRequest = new AddWatchRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, addWatcherRequest); zks.getZKDatabase().addWatch(addWatcherRequest.getPath(), cnxn, addWatcherRequest.getMode()); rsp = new ErrorResponse(0); break; } case OpCode.getACL: { lastOp = "GETA"; GetACLRequest getACLRequest = new GetACLRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getACLRequest); path = getACLRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ | ZooDefs.Perms.ADMIN, request.authInfo, path, null); Stat stat = new Stat(); List<ACL> acl = zks.getZKDatabase().getACL(path, stat); requestPathMetricsCollector.registerRequest(request.type, getACLRequest.getPath()); try { zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.ADMIN, request.authInfo, path, null); rsp = new GetACLResponse(acl, stat); } catch (KeeperException.NoAuthException e) { List<ACL> acl1 = new ArrayList<ACL>(acl.size()); for (ACL a : acl) { if ("digest".equals(a.getId().getScheme())) { Id id = a.getId(); Id id1 = new Id(id.getScheme(), id.getId().replaceAll(":.*", ":x")); acl1.add(new ACL(a.getPerms(), id1)); } else { acl1.add(a); } } rsp = new GetACLResponse(acl1, stat); } break; } case OpCode.getChildren: { lastOp = "GETC"; GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildrenRequest); path = getChildrenRequest.getPath(); rsp = handleGetChildrenRequest(getChildrenRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getAllChildrenNumber: { lastOp = "GETACN"; GetAllChildrenNumberRequest getAllChildrenNumberRequest = new GetAllChildrenNumberRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getAllChildrenNumberRequest); path = getAllChildrenNumberRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); int number = zks.getZKDatabase().getAllChildrenNumber(path); rsp = new GetAllChildrenNumberResponse(number); break; } case OpCode.getChildren2: { lastOp = "GETC"; GetChildren2Request getChildren2Request = new GetChildren2Request(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildren2Request); Stat stat = new Stat(); path = getChildren2Request.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); List<String> children = zks.getZKDatabase() .getChildren(path, stat, getChildren2Request.getWatch() ? cnxn : null); rsp = new GetChildren2Response(children, stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.checkWatches: { lastOp = "CHKW"; CheckWatchesRequest checkWatches = new CheckWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, checkWatches); WatcherType type = WatcherType.fromInt(checkWatches.getType()); path = checkWatches.getPath(); boolean containsWatcher = zks.getZKDatabase().containsWatcher(path, type, cnxn); if (!containsWatcher) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, checkWatches.getPath()); break; } case OpCode.removeWatches: { lastOp = "REMW"; RemoveWatchesRequest removeWatches = new RemoveWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, removeWatches); WatcherType type = WatcherType.fromInt(removeWatches.getType()); path = removeWatches.getPath(); boolean removed = zks.getZKDatabase().removeWatch(path, type, cnxn); if (!removed) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, removeWatches.getPath()); break; } case OpCode.getEphemerals: { lastOp = "GETE"; GetEphemeralsRequest getEphemerals = new GetEphemeralsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getEphemerals); String prefixPath = getEphemerals.getPrefixPath(); Set<String> allEphems = zks.getZKDatabase().getDataTree().getEphemerals(request.sessionId); List<String> ephemerals = new ArrayList<>(); if (prefixPath == null || prefixPath.trim().isEmpty() || "/".equals(prefixPath.trim())) { ephemerals.addAll(allEphems); } else { for (String p : allEphems) { if (p.startsWith(prefixPath)) { ephemerals.add(p); } } } rsp = new GetEphemeralsResponse(ephemerals); break; } } } catch (SessionMovedException e) { // session moved is a connection level error, we need to tear // down the connection otw ZOOKEEPER-710 might happen // ie client on slow follower starts to renew session, fails // before this completes, then tries the fast follower (leader) // and is successful, however the initial renew is then // successfully fwd/processed by the leader and as a result // the client and leader disagree on where the client is most // recently attached (and therefore invalid SESSION MOVED generated) cnxn.sendCloseSession(); return; } catch (KeeperException e) { err = e.code(); } catch (Exception e) { // log at error level as we are returning a marshalling // error to the user LOG.error("Failed to process {}", request, e); StringBuilder sb = new StringBuilder(); ByteBuffer bb = request.request; bb.rewind(); while (bb.hasRemaining()) { sb.append(Integer.toHexString(bb.get() & 0xff)); } LOG.error("Dumping request buffer: 0x{}", sb.toString()); err = Code.MARSHALLINGERROR; } ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue()); updateStats(request, lastOp, lastZxid); try { if (path == null || rsp == null) { responseSize = cnxn.sendResponse(hdr, rsp, "response"); } else { int opCode = request.type; Stat stat = null; // Serialized read and get children responses could be cached by the connection // object. Cache entries are identified by their path and last modified zxid, // so these values are passed along with the response. switch (opCode) { case OpCode.getData : { GetDataResponse getDataResponse = (GetDataResponse) rsp; stat = getDataResponse.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } case OpCode.getChildren2 : { GetChildren2Response getChildren2Response = (GetChildren2Response) rsp; stat = getChildren2Response.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } default: responseSize = cnxn.sendResponse(hdr, rsp, "response"); } } if (request.type == OpCode.closeSession) { cnxn.sendCloseSession(); } } catch (IOException e) { LOG.error("FIXMSG", e); } finally { ServerMetrics.getMetrics().RESPONSE_BYTES.add(responseSize); } }
160999_95
public void processRequest(Request request) { LOG.debug("Processing request:: {}", request); if (LOG.isTraceEnabled()) { long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; if (request.type == OpCode.ping) { traceMask = ZooTrace.SERVER_PING_TRACE_MASK; } ZooTrace.logRequest(LOG, traceMask, 'E', request, ""); } ProcessTxnResult rc = null; if (!request.isThrottled()) { rc = applyRequest(request); } if (request.cnxn == null) { return; } ServerCnxn cnxn = request.cnxn; long lastZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); String lastOp = "NA"; // Notify ZooKeeperServer that the request has finished so that it can // update any request accounting/throttling limits zks.decInProcess(); zks.requestFinished(request); Code err = Code.OK; Record rsp = null; String path = null; int responseSize = 0; try { if (request.getHdr() != null && request.getHdr().getType() == OpCode.error) { AuditHelper.addAuditLog(request, rc, true); /* * When local session upgrading is disabled, leader will * reject the ephemeral node creation due to session expire. * However, if this is the follower that issue the request, * it will have the correct error code, so we should use that * and report to user */ if (request.getException() != null) { throw request.getException(); } else { throw KeeperException.create(KeeperException.Code.get(((ErrorTxn) request.getTxn()).getErr())); } } KeeperException ke = request.getException(); if (ke instanceof SessionMovedException) { throw ke; } if (ke != null && request.type != OpCode.multi) { throw ke; } LOG.debug("{}", request); if (request.isStale()) { ServerMetrics.getMetrics().STALE_REPLIES.add(1); } if (request.isThrottled()) { throw KeeperException.create(Code.THROTTLEDOP); } AuditHelper.addAuditLog(request, rc); switch (request.type) { case OpCode.ping: { lastOp = "PING"; updateStats(request, lastOp, lastZxid); responseSize = cnxn.sendResponse(new ReplyHeader(ClientCnxn.PING_XID, lastZxid, 0), null, "response"); return; } case OpCode.createSession: { lastOp = "SESS"; updateStats(request, lastOp, lastZxid); zks.finishSessionInit(request.cnxn, true); return; } case OpCode.multi: { lastOp = "MULT"; rsp = new MultiResponse(); for (ProcessTxnResult subTxnResult : rc.multiResult) { OpResult subResult; switch (subTxnResult.type) { case OpCode.check: subResult = new CheckResult(); break; case OpCode.create: subResult = new CreateResult(subTxnResult.path); break; case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: subResult = new CreateResult(subTxnResult.path, subTxnResult.stat); break; case OpCode.delete: case OpCode.deleteContainer: subResult = new DeleteResult(); break; case OpCode.setData: subResult = new SetDataResult(subTxnResult.stat); break; case OpCode.error: subResult = new ErrorResult(subTxnResult.err); if (subTxnResult.err == Code.SESSIONMOVED.intValue()) { throw new SessionMovedException(); } break; default: throw new IOException("Invalid type of op"); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.multiRead: { lastOp = "MLTR"; MultiOperationRecord multiReadRecord = new MultiOperationRecord(); ByteBufferInputStream.byteBuffer2Record(request.request, multiReadRecord); rsp = new MultiResponse(); OpResult subResult; for (Op readOp : multiReadRecord) { try { Record rec; switch (readOp.getType()) { case OpCode.getChildren: rec = handleGetChildrenRequest(readOp.toRequestRecord(), cnxn, request.authInfo); subResult = new GetChildrenResult(((GetChildrenResponse) rec).getChildren()); break; case OpCode.getData: rec = handleGetDataRequest(readOp.toRequestRecord(), cnxn, request.authInfo); GetDataResponse gdr = (GetDataResponse) rec; subResult = new GetDataResult(gdr.getData(), gdr.getStat()); break; default: throw new IOException("Invalid type of readOp"); } } catch (KeeperException e) { subResult = new ErrorResult(e.code().intValue()); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.create: { lastOp = "CREA"; rsp = new CreateResponse(rc.path); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: { lastOp = "CREA"; rsp = new Create2Response(rc.path, rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.delete: case OpCode.deleteContainer: { lastOp = "DELE"; err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.setData: { lastOp = "SETD"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.reconfig: { lastOp = "RECO"; rsp = new GetDataResponse( ((QuorumZooKeeperServer) zks).self.getQuorumVerifier().toString().getBytes(), rc.stat); err = Code.get(rc.err); break; } case OpCode.setACL: { lastOp = "SETA"; rsp = new SetACLResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.closeSession: { lastOp = "CLOS"; err = Code.get(rc.err); break; } case OpCode.sync: { lastOp = "SYNC"; SyncRequest syncRequest = new SyncRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, syncRequest); rsp = new SyncResponse(syncRequest.getPath()); requestPathMetricsCollector.registerRequest(request.type, syncRequest.getPath()); break; } case OpCode.check: { lastOp = "CHEC"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); break; } case OpCode.exists: { lastOp = "EXIS"; // TODO we need to figure out the security requirement for this! ExistsRequest existsRequest = new ExistsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, existsRequest); path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException(); } Stat stat = zks.getZKDatabase().statNode(path, existsRequest.getWatch() ? cnxn : null); rsp = new ExistsResponse(stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getData: { lastOp = "GETD"; GetDataRequest getDataRequest = new GetDataRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getDataRequest); path = getDataRequest.getPath(); rsp = handleGetDataRequest(getDataRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.setWatches: { lastOp = "SETW"; SetWatches setWatches = new SetWatches(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase() .setWatches( relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), Collections.emptyList(), Collections.emptyList(), cnxn); break; } case OpCode.setWatches2: { lastOp = "STW2"; SetWatches2 setWatches = new SetWatches2(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase().setWatches(relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), setWatches.getPersistentWatches(), setWatches.getPersistentRecursiveWatches(), cnxn); break; } case OpCode.addWatch: { lastOp = "ADDW"; AddWatchRequest addWatcherRequest = new AddWatchRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, addWatcherRequest); zks.getZKDatabase().addWatch(addWatcherRequest.getPath(), cnxn, addWatcherRequest.getMode()); rsp = new ErrorResponse(0); break; } case OpCode.getACL: { lastOp = "GETA"; GetACLRequest getACLRequest = new GetACLRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getACLRequest); path = getACLRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ | ZooDefs.Perms.ADMIN, request.authInfo, path, null); Stat stat = new Stat(); List<ACL> acl = zks.getZKDatabase().getACL(path, stat); requestPathMetricsCollector.registerRequest(request.type, getACLRequest.getPath()); try { zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.ADMIN, request.authInfo, path, null); rsp = new GetACLResponse(acl, stat); } catch (KeeperException.NoAuthException e) { List<ACL> acl1 = new ArrayList<ACL>(acl.size()); for (ACL a : acl) { if ("digest".equals(a.getId().getScheme())) { Id id = a.getId(); Id id1 = new Id(id.getScheme(), id.getId().replaceAll(":.*", ":x")); acl1.add(new ACL(a.getPerms(), id1)); } else { acl1.add(a); } } rsp = new GetACLResponse(acl1, stat); } break; } case OpCode.getChildren: { lastOp = "GETC"; GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildrenRequest); path = getChildrenRequest.getPath(); rsp = handleGetChildrenRequest(getChildrenRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getAllChildrenNumber: { lastOp = "GETACN"; GetAllChildrenNumberRequest getAllChildrenNumberRequest = new GetAllChildrenNumberRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getAllChildrenNumberRequest); path = getAllChildrenNumberRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); int number = zks.getZKDatabase().getAllChildrenNumber(path); rsp = new GetAllChildrenNumberResponse(number); break; } case OpCode.getChildren2: { lastOp = "GETC"; GetChildren2Request getChildren2Request = new GetChildren2Request(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildren2Request); Stat stat = new Stat(); path = getChildren2Request.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); List<String> children = zks.getZKDatabase() .getChildren(path, stat, getChildren2Request.getWatch() ? cnxn : null); rsp = new GetChildren2Response(children, stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.checkWatches: { lastOp = "CHKW"; CheckWatchesRequest checkWatches = new CheckWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, checkWatches); WatcherType type = WatcherType.fromInt(checkWatches.getType()); path = checkWatches.getPath(); boolean containsWatcher = zks.getZKDatabase().containsWatcher(path, type, cnxn); if (!containsWatcher) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, checkWatches.getPath()); break; } case OpCode.removeWatches: { lastOp = "REMW"; RemoveWatchesRequest removeWatches = new RemoveWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, removeWatches); WatcherType type = WatcherType.fromInt(removeWatches.getType()); path = removeWatches.getPath(); boolean removed = zks.getZKDatabase().removeWatch(path, type, cnxn); if (!removed) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, removeWatches.getPath()); break; } case OpCode.getEphemerals: { lastOp = "GETE"; GetEphemeralsRequest getEphemerals = new GetEphemeralsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getEphemerals); String prefixPath = getEphemerals.getPrefixPath(); Set<String> allEphems = zks.getZKDatabase().getDataTree().getEphemerals(request.sessionId); List<String> ephemerals = new ArrayList<>(); if (prefixPath == null || prefixPath.trim().isEmpty() || "/".equals(prefixPath.trim())) { ephemerals.addAll(allEphems); } else { for (String p : allEphems) { if (p.startsWith(prefixPath)) { ephemerals.add(p); } } } rsp = new GetEphemeralsResponse(ephemerals); break; } } } catch (SessionMovedException e) { // session moved is a connection level error, we need to tear // down the connection otw ZOOKEEPER-710 might happen // ie client on slow follower starts to renew session, fails // before this completes, then tries the fast follower (leader) // and is successful, however the initial renew is then // successfully fwd/processed by the leader and as a result // the client and leader disagree on where the client is most // recently attached (and therefore invalid SESSION MOVED generated) cnxn.sendCloseSession(); return; } catch (KeeperException e) { err = e.code(); } catch (Exception e) { // log at error level as we are returning a marshalling // error to the user LOG.error("Failed to process {}", request, e); StringBuilder sb = new StringBuilder(); ByteBuffer bb = request.request; bb.rewind(); while (bb.hasRemaining()) { sb.append(Integer.toHexString(bb.get() & 0xff)); } LOG.error("Dumping request buffer: 0x{}", sb.toString()); err = Code.MARSHALLINGERROR; } ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue()); updateStats(request, lastOp, lastZxid); try { if (path == null || rsp == null) { responseSize = cnxn.sendResponse(hdr, rsp, "response"); } else { int opCode = request.type; Stat stat = null; // Serialized read and get children responses could be cached by the connection // object. Cache entries are identified by their path and last modified zxid, // so these values are passed along with the response. switch (opCode) { case OpCode.getData : { GetDataResponse getDataResponse = (GetDataResponse) rsp; stat = getDataResponse.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } case OpCode.getChildren2 : { GetChildren2Response getChildren2Response = (GetChildren2Response) rsp; stat = getChildren2Response.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } default: responseSize = cnxn.sendResponse(hdr, rsp, "response"); } } if (request.type == OpCode.closeSession) { cnxn.sendCloseSession(); } } catch (IOException e) { LOG.error("FIXMSG", e); } finally { ServerMetrics.getMetrics().RESPONSE_BYTES.add(responseSize); } }
160999_96
public void processRequest(Request request) { LOG.debug("Processing request:: {}", request); if (LOG.isTraceEnabled()) { long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; if (request.type == OpCode.ping) { traceMask = ZooTrace.SERVER_PING_TRACE_MASK; } ZooTrace.logRequest(LOG, traceMask, 'E', request, ""); } ProcessTxnResult rc = null; if (!request.isThrottled()) { rc = applyRequest(request); } if (request.cnxn == null) { return; } ServerCnxn cnxn = request.cnxn; long lastZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); String lastOp = "NA"; // Notify ZooKeeperServer that the request has finished so that it can // update any request accounting/throttling limits zks.decInProcess(); zks.requestFinished(request); Code err = Code.OK; Record rsp = null; String path = null; int responseSize = 0; try { if (request.getHdr() != null && request.getHdr().getType() == OpCode.error) { AuditHelper.addAuditLog(request, rc, true); /* * When local session upgrading is disabled, leader will * reject the ephemeral node creation due to session expire. * However, if this is the follower that issue the request, * it will have the correct error code, so we should use that * and report to user */ if (request.getException() != null) { throw request.getException(); } else { throw KeeperException.create(KeeperException.Code.get(((ErrorTxn) request.getTxn()).getErr())); } } KeeperException ke = request.getException(); if (ke instanceof SessionMovedException) { throw ke; } if (ke != null && request.type != OpCode.multi) { throw ke; } LOG.debug("{}", request); if (request.isStale()) { ServerMetrics.getMetrics().STALE_REPLIES.add(1); } if (request.isThrottled()) { throw KeeperException.create(Code.THROTTLEDOP); } AuditHelper.addAuditLog(request, rc); switch (request.type) { case OpCode.ping: { lastOp = "PING"; updateStats(request, lastOp, lastZxid); responseSize = cnxn.sendResponse(new ReplyHeader(ClientCnxn.PING_XID, lastZxid, 0), null, "response"); return; } case OpCode.createSession: { lastOp = "SESS"; updateStats(request, lastOp, lastZxid); zks.finishSessionInit(request.cnxn, true); return; } case OpCode.multi: { lastOp = "MULT"; rsp = new MultiResponse(); for (ProcessTxnResult subTxnResult : rc.multiResult) { OpResult subResult; switch (subTxnResult.type) { case OpCode.check: subResult = new CheckResult(); break; case OpCode.create: subResult = new CreateResult(subTxnResult.path); break; case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: subResult = new CreateResult(subTxnResult.path, subTxnResult.stat); break; case OpCode.delete: case OpCode.deleteContainer: subResult = new DeleteResult(); break; case OpCode.setData: subResult = new SetDataResult(subTxnResult.stat); break; case OpCode.error: subResult = new ErrorResult(subTxnResult.err); if (subTxnResult.err == Code.SESSIONMOVED.intValue()) { throw new SessionMovedException(); } break; default: throw new IOException("Invalid type of op"); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.multiRead: { lastOp = "MLTR"; MultiOperationRecord multiReadRecord = new MultiOperationRecord(); ByteBufferInputStream.byteBuffer2Record(request.request, multiReadRecord); rsp = new MultiResponse(); OpResult subResult; for (Op readOp : multiReadRecord) { try { Record rec; switch (readOp.getType()) { case OpCode.getChildren: rec = handleGetChildrenRequest(readOp.toRequestRecord(), cnxn, request.authInfo); subResult = new GetChildrenResult(((GetChildrenResponse) rec).getChildren()); break; case OpCode.getData: rec = handleGetDataRequest(readOp.toRequestRecord(), cnxn, request.authInfo); GetDataResponse gdr = (GetDataResponse) rec; subResult = new GetDataResult(gdr.getData(), gdr.getStat()); break; default: throw new IOException("Invalid type of readOp"); } } catch (KeeperException e) { subResult = new ErrorResult(e.code().intValue()); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.create: { lastOp = "CREA"; rsp = new CreateResponse(rc.path); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: { lastOp = "CREA"; rsp = new Create2Response(rc.path, rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.delete: case OpCode.deleteContainer: { lastOp = "DELE"; err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.setData: { lastOp = "SETD"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.reconfig: { lastOp = "RECO"; rsp = new GetDataResponse( ((QuorumZooKeeperServer) zks).self.getQuorumVerifier().toString().getBytes(), rc.stat); err = Code.get(rc.err); break; } case OpCode.setACL: { lastOp = "SETA"; rsp = new SetACLResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.closeSession: { lastOp = "CLOS"; err = Code.get(rc.err); break; } case OpCode.sync: { lastOp = "SYNC"; SyncRequest syncRequest = new SyncRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, syncRequest); rsp = new SyncResponse(syncRequest.getPath()); requestPathMetricsCollector.registerRequest(request.type, syncRequest.getPath()); break; } case OpCode.check: { lastOp = "CHEC"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); break; } case OpCode.exists: { lastOp = "EXIS"; // TODO we need to figure out the security requirement for this! ExistsRequest existsRequest = new ExistsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, existsRequest); path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException(); } Stat stat = zks.getZKDatabase().statNode(path, existsRequest.getWatch() ? cnxn : null); rsp = new ExistsResponse(stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getData: { lastOp = "GETD"; GetDataRequest getDataRequest = new GetDataRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getDataRequest); path = getDataRequest.getPath(); rsp = handleGetDataRequest(getDataRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.setWatches: { lastOp = "SETW"; SetWatches setWatches = new SetWatches(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase() .setWatches( relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), Collections.emptyList(), Collections.emptyList(), cnxn); break; } case OpCode.setWatches2: { lastOp = "STW2"; SetWatches2 setWatches = new SetWatches2(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase().setWatches(relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), setWatches.getPersistentWatches(), setWatches.getPersistentRecursiveWatches(), cnxn); break; } case OpCode.addWatch: { lastOp = "ADDW"; AddWatchRequest addWatcherRequest = new AddWatchRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, addWatcherRequest); zks.getZKDatabase().addWatch(addWatcherRequest.getPath(), cnxn, addWatcherRequest.getMode()); rsp = new ErrorResponse(0); break; } case OpCode.getACL: { lastOp = "GETA"; GetACLRequest getACLRequest = new GetACLRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getACLRequest); path = getACLRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ | ZooDefs.Perms.ADMIN, request.authInfo, path, null); Stat stat = new Stat(); List<ACL> acl = zks.getZKDatabase().getACL(path, stat); requestPathMetricsCollector.registerRequest(request.type, getACLRequest.getPath()); try { zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.ADMIN, request.authInfo, path, null); rsp = new GetACLResponse(acl, stat); } catch (KeeperException.NoAuthException e) { List<ACL> acl1 = new ArrayList<ACL>(acl.size()); for (ACL a : acl) { if ("digest".equals(a.getId().getScheme())) { Id id = a.getId(); Id id1 = new Id(id.getScheme(), id.getId().replaceAll(":.*", ":x")); acl1.add(new ACL(a.getPerms(), id1)); } else { acl1.add(a); } } rsp = new GetACLResponse(acl1, stat); } break; } case OpCode.getChildren: { lastOp = "GETC"; GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildrenRequest); path = getChildrenRequest.getPath(); rsp = handleGetChildrenRequest(getChildrenRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getAllChildrenNumber: { lastOp = "GETACN"; GetAllChildrenNumberRequest getAllChildrenNumberRequest = new GetAllChildrenNumberRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getAllChildrenNumberRequest); path = getAllChildrenNumberRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); int number = zks.getZKDatabase().getAllChildrenNumber(path); rsp = new GetAllChildrenNumberResponse(number); break; } case OpCode.getChildren2: { lastOp = "GETC"; GetChildren2Request getChildren2Request = new GetChildren2Request(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildren2Request); Stat stat = new Stat(); path = getChildren2Request.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); List<String> children = zks.getZKDatabase() .getChildren(path, stat, getChildren2Request.getWatch() ? cnxn : null); rsp = new GetChildren2Response(children, stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.checkWatches: { lastOp = "CHKW"; CheckWatchesRequest checkWatches = new CheckWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, checkWatches); WatcherType type = WatcherType.fromInt(checkWatches.getType()); path = checkWatches.getPath(); boolean containsWatcher = zks.getZKDatabase().containsWatcher(path, type, cnxn); if (!containsWatcher) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, checkWatches.getPath()); break; } case OpCode.removeWatches: { lastOp = "REMW"; RemoveWatchesRequest removeWatches = new RemoveWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, removeWatches); WatcherType type = WatcherType.fromInt(removeWatches.getType()); path = removeWatches.getPath(); boolean removed = zks.getZKDatabase().removeWatch(path, type, cnxn); if (!removed) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, removeWatches.getPath()); break; } case OpCode.getEphemerals: { lastOp = "GETE"; GetEphemeralsRequest getEphemerals = new GetEphemeralsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getEphemerals); String prefixPath = getEphemerals.getPrefixPath(); Set<String> allEphems = zks.getZKDatabase().getDataTree().getEphemerals(request.sessionId); List<String> ephemerals = new ArrayList<>(); if (prefixPath == null || prefixPath.trim().isEmpty() || "/".equals(prefixPath.trim())) { ephemerals.addAll(allEphems); } else { for (String p : allEphems) { if (p.startsWith(prefixPath)) { ephemerals.add(p); } } } rsp = new GetEphemeralsResponse(ephemerals); break; } } } catch (SessionMovedException e) { // session moved is a connection level error, we need to tear // down the connection otw ZOOKEEPER-710 might happen // ie client on slow follower starts to renew session, fails // before this completes, then tries the fast follower (leader) // and is successful, however the initial renew is then // successfully fwd/processed by the leader and as a result // the client and leader disagree on where the client is most // recently attached (and therefore invalid SESSION MOVED generated) cnxn.sendCloseSession(); return; } catch (KeeperException e) { err = e.code(); } catch (Exception e) { // log at error level as we are returning a marshalling // error to the user LOG.error("Failed to process {}", request, e); StringBuilder sb = new StringBuilder(); ByteBuffer bb = request.request; bb.rewind(); while (bb.hasRemaining()) { sb.append(Integer.toHexString(bb.get() & 0xff)); } LOG.error("Dumping request buffer: 0x{}", sb.toString()); err = Code.MARSHALLINGERROR; } ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue()); updateStats(request, lastOp, lastZxid); try { if (path == null || rsp == null) { responseSize = cnxn.sendResponse(hdr, rsp, "response"); } else { int opCode = request.type; Stat stat = null; // Serialized read and get children responses could be cached by the connection // object. Cache entries are identified by their path and last modified zxid, // so these values are passed along with the response. switch (opCode) { case OpCode.getData : { GetDataResponse getDataResponse = (GetDataResponse) rsp; stat = getDataResponse.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } case OpCode.getChildren2 : { GetChildren2Response getChildren2Response = (GetChildren2Response) rsp; stat = getChildren2Response.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } default: responseSize = cnxn.sendResponse(hdr, rsp, "response"); } } if (request.type == OpCode.closeSession) { cnxn.sendCloseSession(); } } catch (IOException e) { LOG.error("FIXMSG", e); } finally { ServerMetrics.getMetrics().RESPONSE_BYTES.add(responseSize); } }
160999_97
public void processRequest(Request request) { LOG.debug("Processing request:: {}", request); if (LOG.isTraceEnabled()) { long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; if (request.type == OpCode.ping) { traceMask = ZooTrace.SERVER_PING_TRACE_MASK; } ZooTrace.logRequest(LOG, traceMask, 'E', request, ""); } ProcessTxnResult rc = null; if (!request.isThrottled()) { rc = applyRequest(request); } if (request.cnxn == null) { return; } ServerCnxn cnxn = request.cnxn; long lastZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); String lastOp = "NA"; // Notify ZooKeeperServer that the request has finished so that it can // update any request accounting/throttling limits zks.decInProcess(); zks.requestFinished(request); Code err = Code.OK; Record rsp = null; String path = null; int responseSize = 0; try { if (request.getHdr() != null && request.getHdr().getType() == OpCode.error) { AuditHelper.addAuditLog(request, rc, true); /* * When local session upgrading is disabled, leader will * reject the ephemeral node creation due to session expire. * However, if this is the follower that issue the request, * it will have the correct error code, so we should use that * and report to user */ if (request.getException() != null) { throw request.getException(); } else { throw KeeperException.create(KeeperException.Code.get(((ErrorTxn) request.getTxn()).getErr())); } } KeeperException ke = request.getException(); if (ke instanceof SessionMovedException) { throw ke; } if (ke != null && request.type != OpCode.multi) { throw ke; } LOG.debug("{}", request); if (request.isStale()) { ServerMetrics.getMetrics().STALE_REPLIES.add(1); } if (request.isThrottled()) { throw KeeperException.create(Code.THROTTLEDOP); } AuditHelper.addAuditLog(request, rc); switch (request.type) { case OpCode.ping: { lastOp = "PING"; updateStats(request, lastOp, lastZxid); responseSize = cnxn.sendResponse(new ReplyHeader(ClientCnxn.PING_XID, lastZxid, 0), null, "response"); return; } case OpCode.createSession: { lastOp = "SESS"; updateStats(request, lastOp, lastZxid); zks.finishSessionInit(request.cnxn, true); return; } case OpCode.multi: { lastOp = "MULT"; rsp = new MultiResponse(); for (ProcessTxnResult subTxnResult : rc.multiResult) { OpResult subResult; switch (subTxnResult.type) { case OpCode.check: subResult = new CheckResult(); break; case OpCode.create: subResult = new CreateResult(subTxnResult.path); break; case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: subResult = new CreateResult(subTxnResult.path, subTxnResult.stat); break; case OpCode.delete: case OpCode.deleteContainer: subResult = new DeleteResult(); break; case OpCode.setData: subResult = new SetDataResult(subTxnResult.stat); break; case OpCode.error: subResult = new ErrorResult(subTxnResult.err); if (subTxnResult.err == Code.SESSIONMOVED.intValue()) { throw new SessionMovedException(); } break; default: throw new IOException("Invalid type of op"); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.multiRead: { lastOp = "MLTR"; MultiOperationRecord multiReadRecord = new MultiOperationRecord(); ByteBufferInputStream.byteBuffer2Record(request.request, multiReadRecord); rsp = new MultiResponse(); OpResult subResult; for (Op readOp : multiReadRecord) { try { Record rec; switch (readOp.getType()) { case OpCode.getChildren: rec = handleGetChildrenRequest(readOp.toRequestRecord(), cnxn, request.authInfo); subResult = new GetChildrenResult(((GetChildrenResponse) rec).getChildren()); break; case OpCode.getData: rec = handleGetDataRequest(readOp.toRequestRecord(), cnxn, request.authInfo); GetDataResponse gdr = (GetDataResponse) rec; subResult = new GetDataResult(gdr.getData(), gdr.getStat()); break; default: throw new IOException("Invalid type of readOp"); } } catch (KeeperException e) { subResult = new ErrorResult(e.code().intValue()); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.create: { lastOp = "CREA"; rsp = new CreateResponse(rc.path); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: { lastOp = "CREA"; rsp = new Create2Response(rc.path, rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.delete: case OpCode.deleteContainer: { lastOp = "DELE"; err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.setData: { lastOp = "SETD"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.reconfig: { lastOp = "RECO"; rsp = new GetDataResponse( ((QuorumZooKeeperServer) zks).self.getQuorumVerifier().toString().getBytes(), rc.stat); err = Code.get(rc.err); break; } case OpCode.setACL: { lastOp = "SETA"; rsp = new SetACLResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.closeSession: { lastOp = "CLOS"; err = Code.get(rc.err); break; } case OpCode.sync: { lastOp = "SYNC"; SyncRequest syncRequest = new SyncRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, syncRequest); rsp = new SyncResponse(syncRequest.getPath()); requestPathMetricsCollector.registerRequest(request.type, syncRequest.getPath()); break; } case OpCode.check: { lastOp = "CHEC"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); break; } case OpCode.exists: { lastOp = "EXIS"; // TODO we need to figure out the security requirement for this! ExistsRequest existsRequest = new ExistsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, existsRequest); path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException(); } Stat stat = zks.getZKDatabase().statNode(path, existsRequest.getWatch() ? cnxn : null); rsp = new ExistsResponse(stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getData: { lastOp = "GETD"; GetDataRequest getDataRequest = new GetDataRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getDataRequest); path = getDataRequest.getPath(); rsp = handleGetDataRequest(getDataRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.setWatches: { lastOp = "SETW"; SetWatches setWatches = new SetWatches(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase() .setWatches( relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), Collections.emptyList(), Collections.emptyList(), cnxn); break; } case OpCode.setWatches2: { lastOp = "STW2"; SetWatches2 setWatches = new SetWatches2(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase().setWatches(relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), setWatches.getPersistentWatches(), setWatches.getPersistentRecursiveWatches(), cnxn); break; } case OpCode.addWatch: { lastOp = "ADDW"; AddWatchRequest addWatcherRequest = new AddWatchRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, addWatcherRequest); zks.getZKDatabase().addWatch(addWatcherRequest.getPath(), cnxn, addWatcherRequest.getMode()); rsp = new ErrorResponse(0); break; } case OpCode.getACL: { lastOp = "GETA"; GetACLRequest getACLRequest = new GetACLRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getACLRequest); path = getACLRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ | ZooDefs.Perms.ADMIN, request.authInfo, path, null); Stat stat = new Stat(); List<ACL> acl = zks.getZKDatabase().getACL(path, stat); requestPathMetricsCollector.registerRequest(request.type, getACLRequest.getPath()); try { zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.ADMIN, request.authInfo, path, null); rsp = new GetACLResponse(acl, stat); } catch (KeeperException.NoAuthException e) { List<ACL> acl1 = new ArrayList<ACL>(acl.size()); for (ACL a : acl) { if ("digest".equals(a.getId().getScheme())) { Id id = a.getId(); Id id1 = new Id(id.getScheme(), id.getId().replaceAll(":.*", ":x")); acl1.add(new ACL(a.getPerms(), id1)); } else { acl1.add(a); } } rsp = new GetACLResponse(acl1, stat); } break; } case OpCode.getChildren: { lastOp = "GETC"; GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildrenRequest); path = getChildrenRequest.getPath(); rsp = handleGetChildrenRequest(getChildrenRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getAllChildrenNumber: { lastOp = "GETACN"; GetAllChildrenNumberRequest getAllChildrenNumberRequest = new GetAllChildrenNumberRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getAllChildrenNumberRequest); path = getAllChildrenNumberRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); int number = zks.getZKDatabase().getAllChildrenNumber(path); rsp = new GetAllChildrenNumberResponse(number); break; } case OpCode.getChildren2: { lastOp = "GETC"; GetChildren2Request getChildren2Request = new GetChildren2Request(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildren2Request); Stat stat = new Stat(); path = getChildren2Request.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); List<String> children = zks.getZKDatabase() .getChildren(path, stat, getChildren2Request.getWatch() ? cnxn : null); rsp = new GetChildren2Response(children, stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.checkWatches: { lastOp = "CHKW"; CheckWatchesRequest checkWatches = new CheckWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, checkWatches); WatcherType type = WatcherType.fromInt(checkWatches.getType()); path = checkWatches.getPath(); boolean containsWatcher = zks.getZKDatabase().containsWatcher(path, type, cnxn); if (!containsWatcher) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, checkWatches.getPath()); break; } case OpCode.removeWatches: { lastOp = "REMW"; RemoveWatchesRequest removeWatches = new RemoveWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, removeWatches); WatcherType type = WatcherType.fromInt(removeWatches.getType()); path = removeWatches.getPath(); boolean removed = zks.getZKDatabase().removeWatch(path, type, cnxn); if (!removed) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, removeWatches.getPath()); break; } case OpCode.getEphemerals: { lastOp = "GETE"; GetEphemeralsRequest getEphemerals = new GetEphemeralsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getEphemerals); String prefixPath = getEphemerals.getPrefixPath(); Set<String> allEphems = zks.getZKDatabase().getDataTree().getEphemerals(request.sessionId); List<String> ephemerals = new ArrayList<>(); if (prefixPath == null || prefixPath.trim().isEmpty() || "/".equals(prefixPath.trim())) { ephemerals.addAll(allEphems); } else { for (String p : allEphems) { if (p.startsWith(prefixPath)) { ephemerals.add(p); } } } rsp = new GetEphemeralsResponse(ephemerals); break; } } } catch (SessionMovedException e) { // session moved is a connection level error, we need to tear // down the connection otw ZOOKEEPER-710 might happen // ie client on slow follower starts to renew session, fails // before this completes, then tries the fast follower (leader) // and is successful, however the initial renew is then // successfully fwd/processed by the leader and as a result // the client and leader disagree on where the client is most // recently attached (and therefore invalid SESSION MOVED generated) cnxn.sendCloseSession(); return; } catch (KeeperException e) { err = e.code(); } catch (Exception e) { // log at error level as we are returning a marshalling // error to the user LOG.error("Failed to process {}", request, e); StringBuilder sb = new StringBuilder(); ByteBuffer bb = request.request; bb.rewind(); while (bb.hasRemaining()) { sb.append(Integer.toHexString(bb.get() & 0xff)); } LOG.error("Dumping request buffer: 0x{}", sb.toString()); err = Code.MARSHALLINGERROR; } ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue()); updateStats(request, lastOp, lastZxid); try { if (path == null || rsp == null) { responseSize = cnxn.sendResponse(hdr, rsp, "response"); } else { int opCode = request.type; Stat stat = null; // Serialized read and get children responses could be cached by the connection // object. Cache entries are identified by their path and last modified zxid, // so these values are passed along with the response. switch (opCode) { case OpCode.getData : { GetDataResponse getDataResponse = (GetDataResponse) rsp; stat = getDataResponse.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } case OpCode.getChildren2 : { GetChildren2Response getChildren2Response = (GetChildren2Response) rsp; stat = getChildren2Response.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } default: responseSize = cnxn.sendResponse(hdr, rsp, "response"); } } if (request.type == OpCode.closeSession) { cnxn.sendCloseSession(); } } catch (IOException e) { LOG.error("FIXMSG", e); } finally { ServerMetrics.getMetrics().RESPONSE_BYTES.add(responseSize); } }
160999_98
public void processRequest(Request request) { LOG.debug("Processing request:: {}", request); if (LOG.isTraceEnabled()) { long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; if (request.type == OpCode.ping) { traceMask = ZooTrace.SERVER_PING_TRACE_MASK; } ZooTrace.logRequest(LOG, traceMask, 'E', request, ""); } ProcessTxnResult rc = null; if (!request.isThrottled()) { rc = applyRequest(request); } if (request.cnxn == null) { return; } ServerCnxn cnxn = request.cnxn; long lastZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); String lastOp = "NA"; // Notify ZooKeeperServer that the request has finished so that it can // update any request accounting/throttling limits zks.decInProcess(); zks.requestFinished(request); Code err = Code.OK; Record rsp = null; String path = null; int responseSize = 0; try { if (request.getHdr() != null && request.getHdr().getType() == OpCode.error) { AuditHelper.addAuditLog(request, rc, true); /* * When local session upgrading is disabled, leader will * reject the ephemeral node creation due to session expire. * However, if this is the follower that issue the request, * it will have the correct error code, so we should use that * and report to user */ if (request.getException() != null) { throw request.getException(); } else { throw KeeperException.create(KeeperException.Code.get(((ErrorTxn) request.getTxn()).getErr())); } } KeeperException ke = request.getException(); if (ke instanceof SessionMovedException) { throw ke; } if (ke != null && request.type != OpCode.multi) { throw ke; } LOG.debug("{}", request); if (request.isStale()) { ServerMetrics.getMetrics().STALE_REPLIES.add(1); } if (request.isThrottled()) { throw KeeperException.create(Code.THROTTLEDOP); } AuditHelper.addAuditLog(request, rc); switch (request.type) { case OpCode.ping: { lastOp = "PING"; updateStats(request, lastOp, lastZxid); responseSize = cnxn.sendResponse(new ReplyHeader(ClientCnxn.PING_XID, lastZxid, 0), null, "response"); return; } case OpCode.createSession: { lastOp = "SESS"; updateStats(request, lastOp, lastZxid); zks.finishSessionInit(request.cnxn, true); return; } case OpCode.multi: { lastOp = "MULT"; rsp = new MultiResponse(); for (ProcessTxnResult subTxnResult : rc.multiResult) { OpResult subResult; switch (subTxnResult.type) { case OpCode.check: subResult = new CheckResult(); break; case OpCode.create: subResult = new CreateResult(subTxnResult.path); break; case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: subResult = new CreateResult(subTxnResult.path, subTxnResult.stat); break; case OpCode.delete: case OpCode.deleteContainer: subResult = new DeleteResult(); break; case OpCode.setData: subResult = new SetDataResult(subTxnResult.stat); break; case OpCode.error: subResult = new ErrorResult(subTxnResult.err); if (subTxnResult.err == Code.SESSIONMOVED.intValue()) { throw new SessionMovedException(); } break; default: throw new IOException("Invalid type of op"); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.multiRead: { lastOp = "MLTR"; MultiOperationRecord multiReadRecord = new MultiOperationRecord(); ByteBufferInputStream.byteBuffer2Record(request.request, multiReadRecord); rsp = new MultiResponse(); OpResult subResult; for (Op readOp : multiReadRecord) { try { Record rec; switch (readOp.getType()) { case OpCode.getChildren: rec = handleGetChildrenRequest(readOp.toRequestRecord(), cnxn, request.authInfo); subResult = new GetChildrenResult(((GetChildrenResponse) rec).getChildren()); break; case OpCode.getData: rec = handleGetDataRequest(readOp.toRequestRecord(), cnxn, request.authInfo); GetDataResponse gdr = (GetDataResponse) rec; subResult = new GetDataResult(gdr.getData(), gdr.getStat()); break; default: throw new IOException("Invalid type of readOp"); } } catch (KeeperException e) { subResult = new ErrorResult(e.code().intValue()); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.create: { lastOp = "CREA"; rsp = new CreateResponse(rc.path); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: { lastOp = "CREA"; rsp = new Create2Response(rc.path, rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.delete: case OpCode.deleteContainer: { lastOp = "DELE"; err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.setData: { lastOp = "SETD"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.reconfig: { lastOp = "RECO"; rsp = new GetDataResponse( ((QuorumZooKeeperServer) zks).self.getQuorumVerifier().toString().getBytes(), rc.stat); err = Code.get(rc.err); break; } case OpCode.setACL: { lastOp = "SETA"; rsp = new SetACLResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.closeSession: { lastOp = "CLOS"; err = Code.get(rc.err); break; } case OpCode.sync: { lastOp = "SYNC"; SyncRequest syncRequest = new SyncRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, syncRequest); rsp = new SyncResponse(syncRequest.getPath()); requestPathMetricsCollector.registerRequest(request.type, syncRequest.getPath()); break; } case OpCode.check: { lastOp = "CHEC"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); break; } case OpCode.exists: { lastOp = "EXIS"; // TODO we need to figure out the security requirement for this! ExistsRequest existsRequest = new ExistsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, existsRequest); path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException(); } Stat stat = zks.getZKDatabase().statNode(path, existsRequest.getWatch() ? cnxn : null); rsp = new ExistsResponse(stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getData: { lastOp = "GETD"; GetDataRequest getDataRequest = new GetDataRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getDataRequest); path = getDataRequest.getPath(); rsp = handleGetDataRequest(getDataRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.setWatches: { lastOp = "SETW"; SetWatches setWatches = new SetWatches(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase() .setWatches( relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), Collections.emptyList(), Collections.emptyList(), cnxn); break; } case OpCode.setWatches2: { lastOp = "STW2"; SetWatches2 setWatches = new SetWatches2(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase().setWatches(relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), setWatches.getPersistentWatches(), setWatches.getPersistentRecursiveWatches(), cnxn); break; } case OpCode.addWatch: { lastOp = "ADDW"; AddWatchRequest addWatcherRequest = new AddWatchRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, addWatcherRequest); zks.getZKDatabase().addWatch(addWatcherRequest.getPath(), cnxn, addWatcherRequest.getMode()); rsp = new ErrorResponse(0); break; } case OpCode.getACL: { lastOp = "GETA"; GetACLRequest getACLRequest = new GetACLRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getACLRequest); path = getACLRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ | ZooDefs.Perms.ADMIN, request.authInfo, path, null); Stat stat = new Stat(); List<ACL> acl = zks.getZKDatabase().getACL(path, stat); requestPathMetricsCollector.registerRequest(request.type, getACLRequest.getPath()); try { zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.ADMIN, request.authInfo, path, null); rsp = new GetACLResponse(acl, stat); } catch (KeeperException.NoAuthException e) { List<ACL> acl1 = new ArrayList<ACL>(acl.size()); for (ACL a : acl) { if ("digest".equals(a.getId().getScheme())) { Id id = a.getId(); Id id1 = new Id(id.getScheme(), id.getId().replaceAll(":.*", ":x")); acl1.add(new ACL(a.getPerms(), id1)); } else { acl1.add(a); } } rsp = new GetACLResponse(acl1, stat); } break; } case OpCode.getChildren: { lastOp = "GETC"; GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildrenRequest); path = getChildrenRequest.getPath(); rsp = handleGetChildrenRequest(getChildrenRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getAllChildrenNumber: { lastOp = "GETACN"; GetAllChildrenNumberRequest getAllChildrenNumberRequest = new GetAllChildrenNumberRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getAllChildrenNumberRequest); path = getAllChildrenNumberRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); int number = zks.getZKDatabase().getAllChildrenNumber(path); rsp = new GetAllChildrenNumberResponse(number); break; } case OpCode.getChildren2: { lastOp = "GETC"; GetChildren2Request getChildren2Request = new GetChildren2Request(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildren2Request); Stat stat = new Stat(); path = getChildren2Request.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); List<String> children = zks.getZKDatabase() .getChildren(path, stat, getChildren2Request.getWatch() ? cnxn : null); rsp = new GetChildren2Response(children, stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.checkWatches: { lastOp = "CHKW"; CheckWatchesRequest checkWatches = new CheckWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, checkWatches); WatcherType type = WatcherType.fromInt(checkWatches.getType()); path = checkWatches.getPath(); boolean containsWatcher = zks.getZKDatabase().containsWatcher(path, type, cnxn); if (!containsWatcher) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, checkWatches.getPath()); break; } case OpCode.removeWatches: { lastOp = "REMW"; RemoveWatchesRequest removeWatches = new RemoveWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, removeWatches); WatcherType type = WatcherType.fromInt(removeWatches.getType()); path = removeWatches.getPath(); boolean removed = zks.getZKDatabase().removeWatch(path, type, cnxn); if (!removed) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, removeWatches.getPath()); break; } case OpCode.getEphemerals: { lastOp = "GETE"; GetEphemeralsRequest getEphemerals = new GetEphemeralsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getEphemerals); String prefixPath = getEphemerals.getPrefixPath(); Set<String> allEphems = zks.getZKDatabase().getDataTree().getEphemerals(request.sessionId); List<String> ephemerals = new ArrayList<>(); if (prefixPath == null || prefixPath.trim().isEmpty() || "/".equals(prefixPath.trim())) { ephemerals.addAll(allEphems); } else { for (String p : allEphems) { if (p.startsWith(prefixPath)) { ephemerals.add(p); } } } rsp = new GetEphemeralsResponse(ephemerals); break; } } } catch (SessionMovedException e) { // session moved is a connection level error, we need to tear // down the connection otw ZOOKEEPER-710 might happen // ie client on slow follower starts to renew session, fails // before this completes, then tries the fast follower (leader) // and is successful, however the initial renew is then // successfully fwd/processed by the leader and as a result // the client and leader disagree on where the client is most // recently attached (and therefore invalid SESSION MOVED generated) cnxn.sendCloseSession(); return; } catch (KeeperException e) { err = e.code(); } catch (Exception e) { // log at error level as we are returning a marshalling // error to the user LOG.error("Failed to process {}", request, e); StringBuilder sb = new StringBuilder(); ByteBuffer bb = request.request; bb.rewind(); while (bb.hasRemaining()) { sb.append(Integer.toHexString(bb.get() & 0xff)); } LOG.error("Dumping request buffer: 0x{}", sb.toString()); err = Code.MARSHALLINGERROR; } ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue()); updateStats(request, lastOp, lastZxid); try { if (path == null || rsp == null) { responseSize = cnxn.sendResponse(hdr, rsp, "response"); } else { int opCode = request.type; Stat stat = null; // Serialized read and get children responses could be cached by the connection // object. Cache entries are identified by their path and last modified zxid, // so these values are passed along with the response. switch (opCode) { case OpCode.getData : { GetDataResponse getDataResponse = (GetDataResponse) rsp; stat = getDataResponse.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } case OpCode.getChildren2 : { GetChildren2Response getChildren2Response = (GetChildren2Response) rsp; stat = getChildren2Response.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } default: responseSize = cnxn.sendResponse(hdr, rsp, "response"); } } if (request.type == OpCode.closeSession) { cnxn.sendCloseSession(); } } catch (IOException e) { LOG.error("FIXMSG", e); } finally { ServerMetrics.getMetrics().RESPONSE_BYTES.add(responseSize); } }
160999_99
public void processRequest(Request request) { LOG.debug("Processing request:: {}", request); if (LOG.isTraceEnabled()) { long traceMask = ZooTrace.CLIENT_REQUEST_TRACE_MASK; if (request.type == OpCode.ping) { traceMask = ZooTrace.SERVER_PING_TRACE_MASK; } ZooTrace.logRequest(LOG, traceMask, 'E', request, ""); } ProcessTxnResult rc = null; if (!request.isThrottled()) { rc = applyRequest(request); } if (request.cnxn == null) { return; } ServerCnxn cnxn = request.cnxn; long lastZxid = zks.getZKDatabase().getDataTreeLastProcessedZxid(); String lastOp = "NA"; // Notify ZooKeeperServer that the request has finished so that it can // update any request accounting/throttling limits zks.decInProcess(); zks.requestFinished(request); Code err = Code.OK; Record rsp = null; String path = null; int responseSize = 0; try { if (request.getHdr() != null && request.getHdr().getType() == OpCode.error) { AuditHelper.addAuditLog(request, rc, true); /* * When local session upgrading is disabled, leader will * reject the ephemeral node creation due to session expire. * However, if this is the follower that issue the request, * it will have the correct error code, so we should use that * and report to user */ if (request.getException() != null) { throw request.getException(); } else { throw KeeperException.create(KeeperException.Code.get(((ErrorTxn) request.getTxn()).getErr())); } } KeeperException ke = request.getException(); if (ke instanceof SessionMovedException) { throw ke; } if (ke != null && request.type != OpCode.multi) { throw ke; } LOG.debug("{}", request); if (request.isStale()) { ServerMetrics.getMetrics().STALE_REPLIES.add(1); } if (request.isThrottled()) { throw KeeperException.create(Code.THROTTLEDOP); } AuditHelper.addAuditLog(request, rc); switch (request.type) { case OpCode.ping: { lastOp = "PING"; updateStats(request, lastOp, lastZxid); responseSize = cnxn.sendResponse(new ReplyHeader(ClientCnxn.PING_XID, lastZxid, 0), null, "response"); return; } case OpCode.createSession: { lastOp = "SESS"; updateStats(request, lastOp, lastZxid); zks.finishSessionInit(request.cnxn, true); return; } case OpCode.multi: { lastOp = "MULT"; rsp = new MultiResponse(); for (ProcessTxnResult subTxnResult : rc.multiResult) { OpResult subResult; switch (subTxnResult.type) { case OpCode.check: subResult = new CheckResult(); break; case OpCode.create: subResult = new CreateResult(subTxnResult.path); break; case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: subResult = new CreateResult(subTxnResult.path, subTxnResult.stat); break; case OpCode.delete: case OpCode.deleteContainer: subResult = new DeleteResult(); break; case OpCode.setData: subResult = new SetDataResult(subTxnResult.stat); break; case OpCode.error: subResult = new ErrorResult(subTxnResult.err); if (subTxnResult.err == Code.SESSIONMOVED.intValue()) { throw new SessionMovedException(); } break; default: throw new IOException("Invalid type of op"); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.multiRead: { lastOp = "MLTR"; MultiOperationRecord multiReadRecord = new MultiOperationRecord(); ByteBufferInputStream.byteBuffer2Record(request.request, multiReadRecord); rsp = new MultiResponse(); OpResult subResult; for (Op readOp : multiReadRecord) { try { Record rec; switch (readOp.getType()) { case OpCode.getChildren: rec = handleGetChildrenRequest(readOp.toRequestRecord(), cnxn, request.authInfo); subResult = new GetChildrenResult(((GetChildrenResponse) rec).getChildren()); break; case OpCode.getData: rec = handleGetDataRequest(readOp.toRequestRecord(), cnxn, request.authInfo); GetDataResponse gdr = (GetDataResponse) rec; subResult = new GetDataResult(gdr.getData(), gdr.getStat()); break; default: throw new IOException("Invalid type of readOp"); } } catch (KeeperException e) { subResult = new ErrorResult(e.code().intValue()); } ((MultiResponse) rsp).add(subResult); } break; } case OpCode.create: { lastOp = "CREA"; rsp = new CreateResponse(rc.path); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.create2: case OpCode.createTTL: case OpCode.createContainer: { lastOp = "CREA"; rsp = new Create2Response(rc.path, rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.delete: case OpCode.deleteContainer: { lastOp = "DELE"; err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.setData: { lastOp = "SETD"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.reconfig: { lastOp = "RECO"; rsp = new GetDataResponse( ((QuorumZooKeeperServer) zks).self.getQuorumVerifier().toString().getBytes(), rc.stat); err = Code.get(rc.err); break; } case OpCode.setACL: { lastOp = "SETA"; rsp = new SetACLResponse(rc.stat); err = Code.get(rc.err); requestPathMetricsCollector.registerRequest(request.type, rc.path); break; } case OpCode.closeSession: { lastOp = "CLOS"; err = Code.get(rc.err); break; } case OpCode.sync: { lastOp = "SYNC"; SyncRequest syncRequest = new SyncRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, syncRequest); rsp = new SyncResponse(syncRequest.getPath()); requestPathMetricsCollector.registerRequest(request.type, syncRequest.getPath()); break; } case OpCode.check: { lastOp = "CHEC"; rsp = new SetDataResponse(rc.stat); err = Code.get(rc.err); break; } case OpCode.exists: { lastOp = "EXIS"; // TODO we need to figure out the security requirement for this! ExistsRequest existsRequest = new ExistsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, existsRequest); path = existsRequest.getPath(); if (path.indexOf('\0') != -1) { throw new KeeperException.BadArgumentsException(); } Stat stat = zks.getZKDatabase().statNode(path, existsRequest.getWatch() ? cnxn : null); rsp = new ExistsResponse(stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getData: { lastOp = "GETD"; GetDataRequest getDataRequest = new GetDataRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getDataRequest); path = getDataRequest.getPath(); rsp = handleGetDataRequest(getDataRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.setWatches: { lastOp = "SETW"; SetWatches setWatches = new SetWatches(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase() .setWatches( relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), Collections.emptyList(), Collections.emptyList(), cnxn); break; } case OpCode.setWatches2: { lastOp = "STW2"; SetWatches2 setWatches = new SetWatches2(); // TODO we really should not need this request.request.rewind(); ByteBufferInputStream.byteBuffer2Record(request.request, setWatches); long relativeZxid = setWatches.getRelativeZxid(); zks.getZKDatabase().setWatches(relativeZxid, setWatches.getDataWatches(), setWatches.getExistWatches(), setWatches.getChildWatches(), setWatches.getPersistentWatches(), setWatches.getPersistentRecursiveWatches(), cnxn); break; } case OpCode.addWatch: { lastOp = "ADDW"; AddWatchRequest addWatcherRequest = new AddWatchRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, addWatcherRequest); zks.getZKDatabase().addWatch(addWatcherRequest.getPath(), cnxn, addWatcherRequest.getMode()); rsp = new ErrorResponse(0); break; } case OpCode.getACL: { lastOp = "GETA"; GetACLRequest getACLRequest = new GetACLRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getACLRequest); path = getACLRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ | ZooDefs.Perms.ADMIN, request.authInfo, path, null); Stat stat = new Stat(); List<ACL> acl = zks.getZKDatabase().getACL(path, stat); requestPathMetricsCollector.registerRequest(request.type, getACLRequest.getPath()); try { zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.ADMIN, request.authInfo, path, null); rsp = new GetACLResponse(acl, stat); } catch (KeeperException.NoAuthException e) { List<ACL> acl1 = new ArrayList<ACL>(acl.size()); for (ACL a : acl) { if ("digest".equals(a.getId().getScheme())) { Id id = a.getId(); Id id1 = new Id(id.getScheme(), id.getId().replaceAll(":.*", ":x")); acl1.add(new ACL(a.getPerms(), id1)); } else { acl1.add(a); } } rsp = new GetACLResponse(acl1, stat); } break; } case OpCode.getChildren: { lastOp = "GETC"; GetChildrenRequest getChildrenRequest = new GetChildrenRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildrenRequest); path = getChildrenRequest.getPath(); rsp = handleGetChildrenRequest(getChildrenRequest, cnxn, request.authInfo); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.getAllChildrenNumber: { lastOp = "GETACN"; GetAllChildrenNumberRequest getAllChildrenNumberRequest = new GetAllChildrenNumberRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getAllChildrenNumberRequest); path = getAllChildrenNumberRequest.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); int number = zks.getZKDatabase().getAllChildrenNumber(path); rsp = new GetAllChildrenNumberResponse(number); break; } case OpCode.getChildren2: { lastOp = "GETC"; GetChildren2Request getChildren2Request = new GetChildren2Request(); ByteBufferInputStream.byteBuffer2Record(request.request, getChildren2Request); Stat stat = new Stat(); path = getChildren2Request.getPath(); DataNode n = zks.getZKDatabase().getNode(path); if (n == null) { throw new KeeperException.NoNodeException(); } zks.checkACL( request.cnxn, zks.getZKDatabase().aclForNode(n), ZooDefs.Perms.READ, request.authInfo, path, null); List<String> children = zks.getZKDatabase() .getChildren(path, stat, getChildren2Request.getWatch() ? cnxn : null); rsp = new GetChildren2Response(children, stat); requestPathMetricsCollector.registerRequest(request.type, path); break; } case OpCode.checkWatches: { lastOp = "CHKW"; CheckWatchesRequest checkWatches = new CheckWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, checkWatches); WatcherType type = WatcherType.fromInt(checkWatches.getType()); path = checkWatches.getPath(); boolean containsWatcher = zks.getZKDatabase().containsWatcher(path, type, cnxn); if (!containsWatcher) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, checkWatches.getPath()); break; } case OpCode.removeWatches: { lastOp = "REMW"; RemoveWatchesRequest removeWatches = new RemoveWatchesRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, removeWatches); WatcherType type = WatcherType.fromInt(removeWatches.getType()); path = removeWatches.getPath(); boolean removed = zks.getZKDatabase().removeWatch(path, type, cnxn); if (!removed) { String msg = String.format(Locale.ENGLISH, "%s (type: %s)", path, type); throw new KeeperException.NoWatcherException(msg); } requestPathMetricsCollector.registerRequest(request.type, removeWatches.getPath()); break; } case OpCode.getEphemerals: { lastOp = "GETE"; GetEphemeralsRequest getEphemerals = new GetEphemeralsRequest(); ByteBufferInputStream.byteBuffer2Record(request.request, getEphemerals); String prefixPath = getEphemerals.getPrefixPath(); Set<String> allEphems = zks.getZKDatabase().getDataTree().getEphemerals(request.sessionId); List<String> ephemerals = new ArrayList<>(); if (prefixPath == null || prefixPath.trim().isEmpty() || "/".equals(prefixPath.trim())) { ephemerals.addAll(allEphems); } else { for (String p : allEphems) { if (p.startsWith(prefixPath)) { ephemerals.add(p); } } } rsp = new GetEphemeralsResponse(ephemerals); break; } } } catch (SessionMovedException e) { // session moved is a connection level error, we need to tear // down the connection otw ZOOKEEPER-710 might happen // ie client on slow follower starts to renew session, fails // before this completes, then tries the fast follower (leader) // and is successful, however the initial renew is then // successfully fwd/processed by the leader and as a result // the client and leader disagree on where the client is most // recently attached (and therefore invalid SESSION MOVED generated) cnxn.sendCloseSession(); return; } catch (KeeperException e) { err = e.code(); } catch (Exception e) { // log at error level as we are returning a marshalling // error to the user LOG.error("Failed to process {}", request, e); StringBuilder sb = new StringBuilder(); ByteBuffer bb = request.request; bb.rewind(); while (bb.hasRemaining()) { sb.append(Integer.toHexString(bb.get() & 0xff)); } LOG.error("Dumping request buffer: 0x{}", sb.toString()); err = Code.MARSHALLINGERROR; } ReplyHeader hdr = new ReplyHeader(request.cxid, lastZxid, err.intValue()); updateStats(request, lastOp, lastZxid); try { if (path == null || rsp == null) { responseSize = cnxn.sendResponse(hdr, rsp, "response"); } else { int opCode = request.type; Stat stat = null; // Serialized read and get children responses could be cached by the connection // object. Cache entries are identified by their path and last modified zxid, // so these values are passed along with the response. switch (opCode) { case OpCode.getData : { GetDataResponse getDataResponse = (GetDataResponse) rsp; stat = getDataResponse.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } case OpCode.getChildren2 : { GetChildren2Response getChildren2Response = (GetChildren2Response) rsp; stat = getChildren2Response.getStat(); responseSize = cnxn.sendResponse(hdr, rsp, "response", path, stat, opCode); break; } default: responseSize = cnxn.sendResponse(hdr, rsp, "response"); } } if (request.type == OpCode.closeSession) { cnxn.sendCloseSession(); } } catch (IOException e) { LOG.error("FIXMSG", e); } finally { ServerMetrics.getMetrics().RESPONSE_BYTES.add(responseSize); } }
161005_10
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_11
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_12
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_13
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_14
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_15
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_16
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_17
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_18
public static boolean isOlderOrEqual( final String version ) throws IllegalArgumentException { if( version == null ) { return true; } final String[] versionComponents = StringUtils.split( version, VERSION_SEPARATORS ); final int reqVersion = versionComponents.length > 0 ? Integer.parseInt( versionComponents[0] ) : Release.VERSION; final int reqRevision = versionComponents.length > 1 ? Integer.parseInt( versionComponents[1] ) : Release.REVISION; final int reqMinorRevision = versionComponents.length > 2 ? Integer.parseInt( versionComponents[2] ) : Release.MINORREVISION; if( VERSION == reqVersion ) { if( REVISION == reqRevision ) { if( MINORREVISION == reqMinorRevision ) { return true; } return MINORREVISION < reqMinorRevision; } return REVISION < reqRevision; } return VERSION < reqVersion; }
161005_19
Properties initWikiSPIs( final ServletContextEvent sce ) { return Wiki.init( sce.getServletContext() ); }
161005_20
boolean initWikiLoggingFramework( final Properties properties ) { final String useExternalLogConfig = TextUtil.getStringProperty( properties,"jspwiki.use.external.logconfig","false" ); if( useExternalLogConfig.equals( "false" ) ) { if( ClassUtil.exists( "org.apache.log4j.Logger" ) ) { PropertyConfigurator.configure( properties ); } } return useExternalLogConfig.equals( "false" ); }
161005_21
@Override protected String getAttachmentContent( final Attachment att ) { final AttachmentManager mgr = getEngine().getManager( AttachmentManager.class ); final StringBuilder out = new StringBuilder(); try( final InputStream attStream = mgr.getAttachmentStream( att ) ) { final Metadata metadata = new Metadata(); metadata.set( TikaMetadataKeys.RESOURCE_NAME_KEY, att.getFileName() ); final ContentHandler handler = new BodyContentHandler(-1 ); // -1 disables the character size limit; otherwise only the first 100.000 characters are indexed parser.parse( attStream, handler, metadata ); out.append( handler.toString() ); final String[] names = metadata.names(); for( final String name : names ) { if( textualMetadataFields.contains( name ) ) { out.append( " " ).append( metadata.get( name ) ); } } } catch( final TikaException | SAXException e ) { LOG.error( "Attachment cannot be parsed", e ); } catch( final ProviderException | IOException e ) { LOG.error( "Attachment cannot be loaded", e ); } return out.toString(); }
161005_22
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_23
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_24
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_25
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_26
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_27
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_28
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_29
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_30
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_31
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_32
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_33
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_34
private String makeURL( final String context, final String name ) { return doReplacement( getURLPattern( context, name ), name ); }
161005_35
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_36
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_37
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_38
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_39
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_40
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_41
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_42
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_43
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_44
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_45
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_46
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_47
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } return doReplacement( DefaultURLConstructor.getURLPattern( context, name ), name ); }
161005_48
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_49
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_50
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_51
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_52
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_53
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_54
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_55
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_56
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_57
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_58
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_59
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_60
private String makeURL( final String context, final String name ) { final String viewurl = "%p" + m_urlPrefix + "%n"; if( context.equals( ContextEnum.PAGE_VIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl, name ); } else if( context.equals( ContextEnum.PAGE_PREVIEW.getRequestContext() ) ) { if( name == null ) { return doReplacement("%u","" ); } return doReplacement( viewurl + "?do=Preview", name ); } else if( context.equals( ContextEnum.PAGE_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Edit", name ); } else if( context.equals( ContextEnum.PAGE_ATTACH.getRequestContext() ) ) { return doReplacement( "%uattach/%n", name ); } else if( context.equals( ContextEnum.PAGE_INFO.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageInfo", name ); } else if( context.equals( ContextEnum.PAGE_DIFF.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Diff", name ); } else if( context.equals( ContextEnum.PAGE_NONE.getRequestContext() ) ) { return doReplacement( "%u%n", name ); } else if( context.equals( ContextEnum.PAGE_UPLOAD.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Upload", name ); } else if( context.equals( ContextEnum.PAGE_COMMENT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Comment", name ); } else if( context.equals( ContextEnum.WIKI_LOGIN.getRequestContext() ) ) { final String loginUrl = "%pLogin.jsp?redirect=%n"; return doReplacement( loginUrl, name ); } else if( context.equals( ContextEnum.PAGE_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Delete", name ); } else if( context.equals( ContextEnum.PAGE_CONFLICT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=PageModified", name ); } else if( context.equals( ContextEnum.WIKI_PREFS.getRequestContext() ) ) { return doReplacement( viewurl + "?do=UserPreferences", name ); } else if( context.equals( ContextEnum.WIKI_FIND.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Search", name ); } else if( context.equals( ContextEnum.WIKI_ERROR.getRequestContext() ) ) { return doReplacement( "%uError.jsp", name ); } else if( context.equals( ContextEnum.WIKI_CREATE_GROUP.getRequestContext() ) ) { return doReplacement( viewurl + "?do=NewGroup", name ); } else if( context.equals( ContextEnum.GROUP_DELETE.getRequestContext() ) ) { return doReplacement( viewurl + "?do=DeleteGroup", name ); } else if( context.equals( ContextEnum.GROUP_EDIT.getRequestContext() ) ) { return doReplacement( viewurl + "?do=EditGroup", name ); } else if( context.equals( ContextEnum.GROUP_VIEW.getRequestContext() ) ) { return doReplacement( viewurl + "?do=Group&group=%n", name ); } throw new InternalWikiException( "Requested unsupported context " + context ); }
161005_61
@Override public Properties getWikiProperties() { return m_properties; }
161005_62
@Override public String getFinalPageName( final String page ) throws ProviderException { return getManager( CommandResolver.class ).getFinalPageName( page ); }
161005_63
@Override public String getFinalPageName( final String page ) throws ProviderException { return getManager( CommandResolver.class ).getFinalPageName( page ); }
161005_64
@Override public String getFinalPageName( final String page ) throws ProviderException { return getManager( CommandResolver.class ).getFinalPageName( page ); }
161005_65
@Override public String encodeName( final String pagename ) { try { return URLEncoder.encode( pagename, m_useUTF8 ? "UTF-8" : "ISO-8859-1" ); } catch( final UnsupportedEncodingException e ) { throw new InternalWikiException( "ISO-8859-1 not a supported encoding!?! Your platform is borked." , e); } }
161005_66
@Override public String encodeName( final String pagename ) { try { return URLEncoder.encode( pagename, m_useUTF8 ? "UTF-8" : "ISO-8859-1" ); } catch( final UnsupportedEncodingException e ) { throw new InternalWikiException( "ISO-8859-1 not a supported encoding!?! Your platform is borked." , e); } }
161005_67
@Override @SuppressWarnings( "unchecked" ) public < T > T getManager( final Class< T > manager ) { return ( T )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .findFirst().orElse( null ); }
161005_68
@Override @SuppressWarnings( "unchecked" ) public < T > T getManager( final Class< T > manager ) { return ( T )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .findFirst().orElse( null ); }
161005_69
@Override @SuppressWarnings( "unchecked" ) public < T > T getManager( final Class< T > manager ) { return ( T )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .findFirst().orElse( null ); }
161005_70
@Override @SuppressWarnings( "unchecked" ) public < T > T getManager( final Class< T > manager ) { return ( T )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .findFirst().orElse( null ); }
161005_71
@Override @SuppressWarnings( "unchecked" ) public < T > T getManager( final Class< T > manager ) { return ( T )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .findFirst().orElse( null ); }
161005_72
@Override @SuppressWarnings( "unchecked" ) public < T > T getManager( final Class< T > manager ) { return ( T )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .findFirst().orElse( null ); }
161005_73
@Override @SuppressWarnings( "unchecked" ) public < T > T getManager( final Class< T > manager ) { return ( T )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .findFirst().orElse( null ); }
161005_74
@Override @SuppressWarnings( "unchecked" ) public < T > List< T > getManagers( final Class< T > manager ) { return ( List< T > )managers.entrySet().stream() .filter( e -> manager.isAssignableFrom( e.getKey() ) ) .map( Map.Entry::getValue ) .collect( Collectors.toList() ); }
161005_75
@Override public String execute( final Context context, final Map< String, String > params ) throws PluginException { final int since = TextUtil.parseIntParameter( params.get( "since" ), DEFAULT_DAYS ); String spacing = "4"; boolean showAuthor = true; boolean showChangenote = true; String tablewidth = "4"; final Engine engine = context.getEngine(); // // Which format we want to see? // if( "compact".equals( params.get( PARAM_FORMAT ) ) ) { spacing = "0"; showAuthor = false; showChangenote = false; tablewidth = "2"; } final Calendar sincedate = new GregorianCalendar(); sincedate.add( Calendar.DAY_OF_MONTH, -since ); log.debug("Calculating recent changes from "+sincedate.getTime()); // FIXME: Should really have a since date on the getRecentChanges method. Collection< Page > changes = engine.getManager( PageManager.class ).getRecentChanges(); super.initialize( context, params ); changes = filterWikiPageCollection( changes ); if ( changes != null ) { Date olddate = new Date( 0 ); final DateFormat fmt = getDateFormat( context, params ); final DateFormat tfmt = getTimeFormat( context, params ); final Element rt = XhtmlUtil.element( XHTML.table ); rt.setAttribute( XHTML.ATTR_class, "recentchanges" ); rt.setAttribute( XHTML.ATTR_cellpadding, spacing ); for( final Page pageref : changes ) { final Date lastmod = pageref.getLastModified(); if( lastmod.before( sincedate.getTime() ) ) { break; } if( !isSameDay( lastmod, olddate ) ) { final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_colspan, tablewidth ); col.setAttribute( XHTML.ATTR_class, "date" ); col.addContent( XhtmlUtil.element( XHTML.b, fmt.format( lastmod ) ) ); rt.addContent( row ); row.addContent( col ); olddate = lastmod; } final String href = context.getURL( pageref instanceof Attachment ? ContextEnum.PAGE_ATTACH.getRequestContext() : ContextEnum.PAGE_VIEW.getRequestContext(), pageref.getName() ); Element link = XhtmlUtil.link( href, engine.getManager( RenderingManager.class ).beautifyTitle( pageref.getName() ) ); final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_width, "30%" ); col.addContent( link ); // // Add the direct link to the attachment info. // if( pageref instanceof Attachment ) { link = XhtmlUtil.link( context.getURL( WikiContext.INFO, pageref.getName() ), null ); link.setAttribute( XHTML.ATTR_class, "infolink" ); final Element img = XhtmlUtil.img( context.getURL( WikiContext.NONE, "images/attachment_small.png" ), null ); link.addContent( img ); col.addContent( link ); } row.addContent( col ); rt.addContent( row ); if( pageref instanceof Attachment ) { final Element td = XhtmlUtil.element( XHTML.td, tfmt.format( lastmod ) ); td.setAttribute( XHTML.ATTR_class, "lastchange" ); row.addContent( td ); } else { final Element infocol = XhtmlUtil.element( XHTML.td ); infocol.setAttribute( XHTML.ATTR_class, "lastchange" ); infocol.addContent( XhtmlUtil.link( context.getURL( WikiContext.DIFF, pageref.getName(), "r1=-1" ), tfmt.format( lastmod ) ) ); row.addContent( infocol ); } // // Display author information. // if( showAuthor ) { final String author = pageref.getAuthor(); final Element authorinfo = XhtmlUtil.element( XHTML.td ); authorinfo.setAttribute( XHTML.ATTR_class, "author" ); if( author != null ) { if( engine.getManager( PageManager.class ).wikiPageExists( author ) ) { authorinfo.addContent( XhtmlUtil.link( context.getURL( WikiContext.VIEW, author ), author ) ); } else { authorinfo.addContent( author ); } } else { authorinfo.addContent( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE ) .getString( "common.unknownauthor" ) ); } row.addContent( authorinfo ); } // Change note if( showChangenote ) { final String changenote = pageref.getAttribute( Page.CHANGENOTE ); final Element td_changenote = XhtmlUtil.element( XHTML.td, changenote ); td_changenote.setAttribute( XHTML.ATTR_class, "changenote" ); row.addContent( td_changenote ); } // Revert note if( context.hasAdminPermissions() ) { row.addElement( new td("Revert") ); } } return XhtmlUtil.serialize( rt, XhtmlUtil.EXPAND_EMPTY_NODES ); } return ""; }
161005_76
@Override public String execute( final Context context, final Map< String, String > params ) throws PluginException { final int since = TextUtil.parseIntParameter( params.get( "since" ), DEFAULT_DAYS ); String spacing = "4"; boolean showAuthor = true; boolean showChangenote = true; String tablewidth = "4"; final Engine engine = context.getEngine(); // // Which format we want to see? // if( "compact".equals( params.get( PARAM_FORMAT ) ) ) { spacing = "0"; showAuthor = false; showChangenote = false; tablewidth = "2"; } final Calendar sincedate = new GregorianCalendar(); sincedate.add( Calendar.DAY_OF_MONTH, -since ); log.debug("Calculating recent changes from "+sincedate.getTime()); // FIXME: Should really have a since date on the getRecentChanges method. Collection< Page > changes = engine.getManager( PageManager.class ).getRecentChanges(); super.initialize( context, params ); changes = filterWikiPageCollection( changes ); if ( changes != null ) { Date olddate = new Date( 0 ); final DateFormat fmt = getDateFormat( context, params ); final DateFormat tfmt = getTimeFormat( context, params ); final Element rt = XhtmlUtil.element( XHTML.table ); rt.setAttribute( XHTML.ATTR_class, "recentchanges" ); rt.setAttribute( XHTML.ATTR_cellpadding, spacing ); for( final Page pageref : changes ) { final Date lastmod = pageref.getLastModified(); if( lastmod.before( sincedate.getTime() ) ) { break; } if( !isSameDay( lastmod, olddate ) ) { final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_colspan, tablewidth ); col.setAttribute( XHTML.ATTR_class, "date" ); col.addContent( XhtmlUtil.element( XHTML.b, fmt.format( lastmod ) ) ); rt.addContent( row ); row.addContent( col ); olddate = lastmod; } final String href = context.getURL( pageref instanceof Attachment ? ContextEnum.PAGE_ATTACH.getRequestContext() : ContextEnum.PAGE_VIEW.getRequestContext(), pageref.getName() ); Element link = XhtmlUtil.link( href, engine.getManager( RenderingManager.class ).beautifyTitle( pageref.getName() ) ); final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_width, "30%" ); col.addContent( link ); // // Add the direct link to the attachment info. // if( pageref instanceof Attachment ) { link = XhtmlUtil.link( context.getURL( WikiContext.INFO, pageref.getName() ), null ); link.setAttribute( XHTML.ATTR_class, "infolink" ); final Element img = XhtmlUtil.img( context.getURL( WikiContext.NONE, "images/attachment_small.png" ), null ); link.addContent( img ); col.addContent( link ); } row.addContent( col ); rt.addContent( row ); if( pageref instanceof Attachment ) { final Element td = XhtmlUtil.element( XHTML.td, tfmt.format( lastmod ) ); td.setAttribute( XHTML.ATTR_class, "lastchange" ); row.addContent( td ); } else { final Element infocol = XhtmlUtil.element( XHTML.td ); infocol.setAttribute( XHTML.ATTR_class, "lastchange" ); infocol.addContent( XhtmlUtil.link( context.getURL( WikiContext.DIFF, pageref.getName(), "r1=-1" ), tfmt.format( lastmod ) ) ); row.addContent( infocol ); } // // Display author information. // if( showAuthor ) { final String author = pageref.getAuthor(); final Element authorinfo = XhtmlUtil.element( XHTML.td ); authorinfo.setAttribute( XHTML.ATTR_class, "author" ); if( author != null ) { if( engine.getManager( PageManager.class ).wikiPageExists( author ) ) { authorinfo.addContent( XhtmlUtil.link( context.getURL( WikiContext.VIEW, author ), author ) ); } else { authorinfo.addContent( author ); } } else { authorinfo.addContent( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE ) .getString( "common.unknownauthor" ) ); } row.addContent( authorinfo ); } // Change note if( showChangenote ) { final String changenote = pageref.getAttribute( Page.CHANGENOTE ); final Element td_changenote = XhtmlUtil.element( XHTML.td, changenote ); td_changenote.setAttribute( XHTML.ATTR_class, "changenote" ); row.addContent( td_changenote ); } // Revert note if( context.hasAdminPermissions() ) { row.addElement( new td("Revert") ); } } return XhtmlUtil.serialize( rt, XhtmlUtil.EXPAND_EMPTY_NODES ); } return ""; }
161005_77
@Override public String execute( final Context context, final Map< String, String > params ) throws PluginException { final int since = TextUtil.parseIntParameter( params.get( "since" ), DEFAULT_DAYS ); String spacing = "4"; boolean showAuthor = true; boolean showChangenote = true; String tablewidth = "4"; final Engine engine = context.getEngine(); // // Which format we want to see? // if( "compact".equals( params.get( PARAM_FORMAT ) ) ) { spacing = "0"; showAuthor = false; showChangenote = false; tablewidth = "2"; } final Calendar sincedate = new GregorianCalendar(); sincedate.add( Calendar.DAY_OF_MONTH, -since ); log.debug("Calculating recent changes from "+sincedate.getTime()); // FIXME: Should really have a since date on the getRecentChanges method. Collection< Page > changes = engine.getManager( PageManager.class ).getRecentChanges(); super.initialize( context, params ); changes = filterWikiPageCollection( changes ); if ( changes != null ) { Date olddate = new Date( 0 ); final DateFormat fmt = getDateFormat( context, params ); final DateFormat tfmt = getTimeFormat( context, params ); final Element rt = XhtmlUtil.element( XHTML.table ); rt.setAttribute( XHTML.ATTR_class, "recentchanges" ); rt.setAttribute( XHTML.ATTR_cellpadding, spacing ); for( final Page pageref : changes ) { final Date lastmod = pageref.getLastModified(); if( lastmod.before( sincedate.getTime() ) ) { break; } if( !isSameDay( lastmod, olddate ) ) { final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_colspan, tablewidth ); col.setAttribute( XHTML.ATTR_class, "date" ); col.addContent( XhtmlUtil.element( XHTML.b, fmt.format( lastmod ) ) ); rt.addContent( row ); row.addContent( col ); olddate = lastmod; } final String href = context.getURL( pageref instanceof Attachment ? ContextEnum.PAGE_ATTACH.getRequestContext() : ContextEnum.PAGE_VIEW.getRequestContext(), pageref.getName() ); Element link = XhtmlUtil.link( href, engine.getManager( RenderingManager.class ).beautifyTitle( pageref.getName() ) ); final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_width, "30%" ); col.addContent( link ); // // Add the direct link to the attachment info. // if( pageref instanceof Attachment ) { link = XhtmlUtil.link( context.getURL( WikiContext.INFO, pageref.getName() ), null ); link.setAttribute( XHTML.ATTR_class, "infolink" ); final Element img = XhtmlUtil.img( context.getURL( WikiContext.NONE, "images/attachment_small.png" ), null ); link.addContent( img ); col.addContent( link ); } row.addContent( col ); rt.addContent( row ); if( pageref instanceof Attachment ) { final Element td = XhtmlUtil.element( XHTML.td, tfmt.format( lastmod ) ); td.setAttribute( XHTML.ATTR_class, "lastchange" ); row.addContent( td ); } else { final Element infocol = XhtmlUtil.element( XHTML.td ); infocol.setAttribute( XHTML.ATTR_class, "lastchange" ); infocol.addContent( XhtmlUtil.link( context.getURL( WikiContext.DIFF, pageref.getName(), "r1=-1" ), tfmt.format( lastmod ) ) ); row.addContent( infocol ); } // // Display author information. // if( showAuthor ) { final String author = pageref.getAuthor(); final Element authorinfo = XhtmlUtil.element( XHTML.td ); authorinfo.setAttribute( XHTML.ATTR_class, "author" ); if( author != null ) { if( engine.getManager( PageManager.class ).wikiPageExists( author ) ) { authorinfo.addContent( XhtmlUtil.link( context.getURL( WikiContext.VIEW, author ), author ) ); } else { authorinfo.addContent( author ); } } else { authorinfo.addContent( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE ) .getString( "common.unknownauthor" ) ); } row.addContent( authorinfo ); } // Change note if( showChangenote ) { final String changenote = pageref.getAttribute( Page.CHANGENOTE ); final Element td_changenote = XhtmlUtil.element( XHTML.td, changenote ); td_changenote.setAttribute( XHTML.ATTR_class, "changenote" ); row.addContent( td_changenote ); } // Revert note if( context.hasAdminPermissions() ) { row.addElement( new td("Revert") ); } } return XhtmlUtil.serialize( rt, XhtmlUtil.EXPAND_EMPTY_NODES ); } return ""; }
161005_78
@Override public String execute( final Context context, final Map< String, String > params ) throws PluginException { final int since = TextUtil.parseIntParameter( params.get( "since" ), DEFAULT_DAYS ); String spacing = "4"; boolean showAuthor = true; boolean showChangenote = true; String tablewidth = "4"; final Engine engine = context.getEngine(); // // Which format we want to see? // if( "compact".equals( params.get( PARAM_FORMAT ) ) ) { spacing = "0"; showAuthor = false; showChangenote = false; tablewidth = "2"; } final Calendar sincedate = new GregorianCalendar(); sincedate.add( Calendar.DAY_OF_MONTH, -since ); log.debug("Calculating recent changes from "+sincedate.getTime()); // FIXME: Should really have a since date on the getRecentChanges method. Collection< Page > changes = engine.getManager( PageManager.class ).getRecentChanges(); super.initialize( context, params ); changes = filterWikiPageCollection( changes ); if ( changes != null ) { Date olddate = new Date( 0 ); final DateFormat fmt = getDateFormat( context, params ); final DateFormat tfmt = getTimeFormat( context, params ); final Element rt = XhtmlUtil.element( XHTML.table ); rt.setAttribute( XHTML.ATTR_class, "recentchanges" ); rt.setAttribute( XHTML.ATTR_cellpadding, spacing ); for( final Page pageref : changes ) { final Date lastmod = pageref.getLastModified(); if( lastmod.before( sincedate.getTime() ) ) { break; } if( !isSameDay( lastmod, olddate ) ) { final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_colspan, tablewidth ); col.setAttribute( XHTML.ATTR_class, "date" ); col.addContent( XhtmlUtil.element( XHTML.b, fmt.format( lastmod ) ) ); rt.addContent( row ); row.addContent( col ); olddate = lastmod; } final String href = context.getURL( pageref instanceof Attachment ? ContextEnum.PAGE_ATTACH.getRequestContext() : ContextEnum.PAGE_VIEW.getRequestContext(), pageref.getName() ); Element link = XhtmlUtil.link( href, engine.getManager( RenderingManager.class ).beautifyTitle( pageref.getName() ) ); final Element row = XhtmlUtil.element( XHTML.tr ); final Element col = XhtmlUtil.element( XHTML.td ); col.setAttribute( XHTML.ATTR_width, "30%" ); col.addContent( link ); // // Add the direct link to the attachment info. // if( pageref instanceof Attachment ) { link = XhtmlUtil.link( context.getURL( WikiContext.INFO, pageref.getName() ), null ); link.setAttribute( XHTML.ATTR_class, "infolink" ); final Element img = XhtmlUtil.img( context.getURL( WikiContext.NONE, "images/attachment_small.png" ), null ); link.addContent( img ); col.addContent( link ); } row.addContent( col ); rt.addContent( row ); if( pageref instanceof Attachment ) { final Element td = XhtmlUtil.element( XHTML.td, tfmt.format( lastmod ) ); td.setAttribute( XHTML.ATTR_class, "lastchange" ); row.addContent( td ); } else { final Element infocol = XhtmlUtil.element( XHTML.td ); infocol.setAttribute( XHTML.ATTR_class, "lastchange" ); infocol.addContent( XhtmlUtil.link( context.getURL( WikiContext.DIFF, pageref.getName(), "r1=-1" ), tfmt.format( lastmod ) ) ); row.addContent( infocol ); } // // Display author information. // if( showAuthor ) { final String author = pageref.getAuthor(); final Element authorinfo = XhtmlUtil.element( XHTML.td ); authorinfo.setAttribute( XHTML.ATTR_class, "author" ); if( author != null ) { if( engine.getManager( PageManager.class ).wikiPageExists( author ) ) { authorinfo.addContent( XhtmlUtil.link( context.getURL( WikiContext.VIEW, author ), author ) ); } else { authorinfo.addContent( author ); } } else { authorinfo.addContent( Preferences.getBundle( context, InternationalizationManager.CORE_BUNDLE ) .getString( "common.unknownauthor" ) ); } row.addContent( authorinfo ); } // Change note if( showChangenote ) { final String changenote = pageref.getAttribute( Page.CHANGENOTE ); final Element td_changenote = XhtmlUtil.element( XHTML.td, changenote ); td_changenote.setAttribute( XHTML.ATTR_class, "changenote" ); row.addContent( td_changenote ); } // Revert note if( context.hasAdminPermissions() ) { row.addElement( new td("Revert") ); } } return XhtmlUtil.serialize( rt, XhtmlUtil.EXPAND_EMPTY_NODES ); } return ""; }
161005_79
@Override public String execute( final Context context, final Map< String, String > params ) throws PluginException { final ReferenceManager refmgr = context.getEngine().getManager( ReferenceManager.class ); super.initialize( context, params ); Collection< String > links = refmgr.findUncreated(); links = filterAndSortCollection( links ); if( m_lastModified ) { throw new PluginException( "parameter " + PARAM_LASTMODIFIED + " is not valid for the UndefinedPagesPlugin" ); } final String wikitext; if( m_show.equals( PARAM_SHOW_VALUE_COUNT ) ) { wikitext = "" + links.size(); } else { wikitext = wikitizeCollection( links, m_separator, ALL_ITEMS ); } return makeHTML( context, wikitext ); }
161005_80
@Override public String execute( final Context context, final Map< String, String > params ) throws PluginException { final ReferenceManager refmgr = context.getEngine().getManager( ReferenceManager.class ); super.initialize( context, params ); Collection< String > links = refmgr.findUncreated(); links = filterAndSortCollection( links ); if( m_lastModified ) { throw new PluginException( "parameter " + PARAM_LASTMODIFIED + " is not valid for the UndefinedPagesPlugin" ); } final String wikitext; if( m_show.equals( PARAM_SHOW_VALUE_COUNT ) ) { wikitext = "" + links.size(); } else { wikitext = wikitizeCollection( links, m_separator, ALL_ITEMS ); } return makeHTML( context, wikitext ); }
161005_81
@Override public String execute( final Context context, final String classname, final Map< String, String > params ) throws PluginException { if( !m_pluginsEnabled ) { return ""; } final ResourceBundle rb = Preferences.getBundle( context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE ); final boolean debug = TextUtil.isPositive( params.get( PARAM_DEBUG ) ); try { // Create... final Plugin plugin = newWikiPlugin( classname, rb ); if( plugin == null ) { return "Plugin '" + classname + "' not compatible with this version of JSPWiki"; } // ...and launch. try { return plugin.execute( context, params ); } catch( final PluginException e ) { if( debug ) { return stackTrace( params, e ); } // Just pass this exception onward. throw ( PluginException )e.fillInStackTrace(); } catch( final Throwable t ) { // But all others get captured here. log.info( "Plugin failed while executing:", t ); if( debug ) { return stackTrace( params, t ); } throw new PluginException( rb.getString( "plugin.error.failed" ), t ); } } catch( final ClassCastException e ) { throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.notawikiplugin" ), classname ), e ); } }
161005_82
@Override public String execute( final Context context, final String classname, final Map< String, String > params ) throws PluginException { if( !m_pluginsEnabled ) { return ""; } final ResourceBundle rb = Preferences.getBundle( context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE ); final boolean debug = TextUtil.isPositive( params.get( PARAM_DEBUG ) ); try { // Create... final Plugin plugin = newWikiPlugin( classname, rb ); if( plugin == null ) { return "Plugin '" + classname + "' not compatible with this version of JSPWiki"; } // ...and launch. try { return plugin.execute( context, params ); } catch( final PluginException e ) { if( debug ) { return stackTrace( params, e ); } // Just pass this exception onward. throw ( PluginException )e.fillInStackTrace(); } catch( final Throwable t ) { // But all others get captured here. log.info( "Plugin failed while executing:", t ); if( debug ) { return stackTrace( params, t ); } throw new PluginException( rb.getString( "plugin.error.failed" ), t ); } } catch( final ClassCastException e ) { throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.notawikiplugin" ), classname ), e ); } }
161005_83
@Override public String execute( final Context context, final String classname, final Map< String, String > params ) throws PluginException { if( !m_pluginsEnabled ) { return ""; } final ResourceBundle rb = Preferences.getBundle( context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE ); final boolean debug = TextUtil.isPositive( params.get( PARAM_DEBUG ) ); try { // Create... final Plugin plugin = newWikiPlugin( classname, rb ); if( plugin == null ) { return "Plugin '" + classname + "' not compatible with this version of JSPWiki"; } // ...and launch. try { return plugin.execute( context, params ); } catch( final PluginException e ) { if( debug ) { return stackTrace( params, e ); } // Just pass this exception onward. throw ( PluginException )e.fillInStackTrace(); } catch( final Throwable t ) { // But all others get captured here. log.info( "Plugin failed while executing:", t ); if( debug ) { return stackTrace( params, t ); } throw new PluginException( rb.getString( "plugin.error.failed" ), t ); } } catch( final ClassCastException e ) { throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.notawikiplugin" ), classname ), e ); } }
161005_84
@Override public String execute( final Context context, final String classname, final Map< String, String > params ) throws PluginException { if( !m_pluginsEnabled ) { return ""; } final ResourceBundle rb = Preferences.getBundle( context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE ); final boolean debug = TextUtil.isPositive( params.get( PARAM_DEBUG ) ); try { // Create... final Plugin plugin = newWikiPlugin( classname, rb ); if( plugin == null ) { return "Plugin '" + classname + "' not compatible with this version of JSPWiki"; } // ...and launch. try { return plugin.execute( context, params ); } catch( final PluginException e ) { if( debug ) { return stackTrace( params, e ); } // Just pass this exception onward. throw ( PluginException )e.fillInStackTrace(); } catch( final Throwable t ) { // But all others get captured here. log.info( "Plugin failed while executing:", t ); if( debug ) { return stackTrace( params, t ); } throw new PluginException( rb.getString( "plugin.error.failed" ), t ); } } catch( final ClassCastException e ) { throw new PluginException( MessageFormat.format( rb.getString( "plugin.error.notawikiplugin" ), classname ), e ); } }