@Test(expected = ServiceTemporarilyDownException.class) public void testServiceTemporarilyDown() throws RpcException { StringReader s = new StringReader("421 Service temporarily down.\r\n"); DefaultRpcMessageReader r = new DefaultRpcMessageReader(s); r.readResponse(); }
public RpcResponse readResponse() throws RpcException { long start = System.currentTimeMillis(); long waitMillis = -1; long receiveMillis = -1; String securitySegment = null; String applicationSegment = null; try { securitySegment = readServerPacket(); waitMillis = System.currentTimeMillis() - start; applicationSegment = readServerPacket(); } catch (RpcException e) { if (securitySegment != null && securitySegment.startsWith(ServiceTemporarilyDownException.RPC_SERVICE_TEMPORARILY_DOWN_MESSAGE)) { throw new ServiceTemporarilyDownException(); } else { throw e; } } StringBuilder responseBuf = new StringBuilder(); int c = -1; do { try { c = reader.read(); if (c < 0) throw new IOException("unexpected end of stream"); } catch (InterruptedIOException e) { throw new TimeoutWaitingForRpcResponseException(e); } catch (IOException e) { throw new RpcIoException("unable to read response", e); } responseBuf.append((char) c); } while (c != 4); responseBuf.deleteCharAt(responseBuf.length() - 1); if ("U411".equals(applicationSegment)) throw new BadReadsException(); String responseString = responseBuf.toString(); RpcResponse response = new RpcResponse(securitySegment, applicationSegment, responseString); if (response.length() > 0) { String[] lines = response.toLines(); if (lines.length > 0) { if (lines[0].length() > 0) { if (lines[0].charAt(0) == (char) 24) throw new InternalServerException(response.toLines()[1]); } } else { LOGGER.warn("RPC response '" + responseString + "' produced a 0-length lines array"); } } receiveMillis = System.currentTimeMillis() - start - waitMillis; response.setElapsedMillis(RpcPhase.WAITING, waitMillis); response.setElapsedMillis(RpcPhase.RECEIVING, receiveMillis); return response; }
DefaultRpcMessageReader implements RpcMessageReader { public RpcResponse readResponse() throws RpcException { long start = System.currentTimeMillis(); long waitMillis = -1; long receiveMillis = -1; String securitySegment = null; String applicationSegment = null; try { securitySegment = readServerPacket(); waitMillis = System.currentTimeMillis() - start; applicationSegment = readServerPacket(); } catch (RpcException e) { if (securitySegment != null && securitySegment.startsWith(ServiceTemporarilyDownException.RPC_SERVICE_TEMPORARILY_DOWN_MESSAGE)) { throw new ServiceTemporarilyDownException(); } else { throw e; } } StringBuilder responseBuf = new StringBuilder(); int c = -1; do { try { c = reader.read(); if (c < 0) throw new IOException("unexpected end of stream"); } catch (InterruptedIOException e) { throw new TimeoutWaitingForRpcResponseException(e); } catch (IOException e) { throw new RpcIoException("unable to read response", e); } responseBuf.append((char) c); } while (c != 4); responseBuf.deleteCharAt(responseBuf.length() - 1); if ("U411".equals(applicationSegment)) throw new BadReadsException(); String responseString = responseBuf.toString(); RpcResponse response = new RpcResponse(securitySegment, applicationSegment, responseString); if (response.length() > 0) { String[] lines = response.toLines(); if (lines.length > 0) { if (lines[0].length() > 0) { if (lines[0].charAt(0) == (char) 24) throw new InternalServerException(response.toLines()[1]); } } else { LOGGER.warn("RPC response '" + responseString + "' produced a 0-length lines array"); } } receiveMillis = System.currentTimeMillis() - start - waitMillis; response.setElapsedMillis(RpcPhase.WAITING, waitMillis); response.setElapsedMillis(RpcPhase.RECEIVING, receiveMillis); return response; } }
DefaultRpcMessageReader implements RpcMessageReader { public RpcResponse readResponse() throws RpcException { long start = System.currentTimeMillis(); long waitMillis = -1; long receiveMillis = -1; String securitySegment = null; String applicationSegment = null; try { securitySegment = readServerPacket(); waitMillis = System.currentTimeMillis() - start; applicationSegment = readServerPacket(); } catch (RpcException e) { if (securitySegment != null && securitySegment.startsWith(ServiceTemporarilyDownException.RPC_SERVICE_TEMPORARILY_DOWN_MESSAGE)) { throw new ServiceTemporarilyDownException(); } else { throw e; } } StringBuilder responseBuf = new StringBuilder(); int c = -1; do { try { c = reader.read(); if (c < 0) throw new IOException("unexpected end of stream"); } catch (InterruptedIOException e) { throw new TimeoutWaitingForRpcResponseException(e); } catch (IOException e) { throw new RpcIoException("unable to read response", e); } responseBuf.append((char) c); } while (c != 4); responseBuf.deleteCharAt(responseBuf.length() - 1); if ("U411".equals(applicationSegment)) throw new BadReadsException(); String responseString = responseBuf.toString(); RpcResponse response = new RpcResponse(securitySegment, applicationSegment, responseString); if (response.length() > 0) { String[] lines = response.toLines(); if (lines.length > 0) { if (lines[0].length() > 0) { if (lines[0].charAt(0) == (char) 24) throw new InternalServerException(response.toLines()[1]); } } else { LOGGER.warn("RPC response '" + responseString + "' produced a 0-length lines array"); } } receiveMillis = System.currentTimeMillis() - start - waitMillis; response.setElapsedMillis(RpcPhase.WAITING, waitMillis); response.setElapsedMillis(RpcPhase.RECEIVING, receiveMillis); return response; } DefaultRpcMessageReader(final Reader r); }
DefaultRpcMessageReader implements RpcMessageReader { public RpcResponse readResponse() throws RpcException { long start = System.currentTimeMillis(); long waitMillis = -1; long receiveMillis = -1; String securitySegment = null; String applicationSegment = null; try { securitySegment = readServerPacket(); waitMillis = System.currentTimeMillis() - start; applicationSegment = readServerPacket(); } catch (RpcException e) { if (securitySegment != null && securitySegment.startsWith(ServiceTemporarilyDownException.RPC_SERVICE_TEMPORARILY_DOWN_MESSAGE)) { throw new ServiceTemporarilyDownException(); } else { throw e; } } StringBuilder responseBuf = new StringBuilder(); int c = -1; do { try { c = reader.read(); if (c < 0) throw new IOException("unexpected end of stream"); } catch (InterruptedIOException e) { throw new TimeoutWaitingForRpcResponseException(e); } catch (IOException e) { throw new RpcIoException("unable to read response", e); } responseBuf.append((char) c); } while (c != 4); responseBuf.deleteCharAt(responseBuf.length() - 1); if ("U411".equals(applicationSegment)) throw new BadReadsException(); String responseString = responseBuf.toString(); RpcResponse response = new RpcResponse(securitySegment, applicationSegment, responseString); if (response.length() > 0) { String[] lines = response.toLines(); if (lines.length > 0) { if (lines[0].length() > 0) { if (lines[0].charAt(0) == (char) 24) throw new InternalServerException(response.toLines()[1]); } } else { LOGGER.warn("RPC response '" + responseString + "' produced a 0-length lines array"); } } receiveMillis = System.currentTimeMillis() - start - waitMillis; response.setElapsedMillis(RpcPhase.WAITING, waitMillis); response.setElapsedMillis(RpcPhase.RECEIVING, receiveMillis); return response; } DefaultRpcMessageReader(final Reader r); RpcResponse readResponse(); String readServerPacket(); }
DefaultRpcMessageReader implements RpcMessageReader { public RpcResponse readResponse() throws RpcException { long start = System.currentTimeMillis(); long waitMillis = -1; long receiveMillis = -1; String securitySegment = null; String applicationSegment = null; try { securitySegment = readServerPacket(); waitMillis = System.currentTimeMillis() - start; applicationSegment = readServerPacket(); } catch (RpcException e) { if (securitySegment != null && securitySegment.startsWith(ServiceTemporarilyDownException.RPC_SERVICE_TEMPORARILY_DOWN_MESSAGE)) { throw new ServiceTemporarilyDownException(); } else { throw e; } } StringBuilder responseBuf = new StringBuilder(); int c = -1; do { try { c = reader.read(); if (c < 0) throw new IOException("unexpected end of stream"); } catch (InterruptedIOException e) { throw new TimeoutWaitingForRpcResponseException(e); } catch (IOException e) { throw new RpcIoException("unable to read response", e); } responseBuf.append((char) c); } while (c != 4); responseBuf.deleteCharAt(responseBuf.length() - 1); if ("U411".equals(applicationSegment)) throw new BadReadsException(); String responseString = responseBuf.toString(); RpcResponse response = new RpcResponse(securitySegment, applicationSegment, responseString); if (response.length() > 0) { String[] lines = response.toLines(); if (lines.length > 0) { if (lines[0].length() > 0) { if (lines[0].charAt(0) == (char) 24) throw new InternalServerException(response.toLines()[1]); } } else { LOGGER.warn("RPC response '" + responseString + "' produced a 0-length lines array"); } } receiveMillis = System.currentTimeMillis() - start - waitMillis; response.setElapsedMillis(RpcPhase.WAITING, waitMillis); response.setElapsedMillis(RpcPhase.RECEIVING, receiveMillis); return response; } DefaultRpcMessageReader(final Reader r); RpcResponse readResponse(); String readServerPacket();  }