@Override public Object request(String messageName, Object request) throws IOException { try { return super.request(messageName, request); } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException)e; if (e instanceof IOException) throw (IOException)e; throw new AvroRemoteException(e); } }
public AvroRemoteException(Throwable value) { this(value.toString()); initCause(value); }
@Test(expected=SocketTimeoutException.class) public void testTimeout() throws Throwable { ServerSocket s = new ServerSocket(0); HttpTransceiver client = new HttpTransceiver(new URL("http://127.0.0.1:"+s.getLocalPort()+"/")); client.setTimeout(100); Simple proxy = SpecificRequestor.getClient(Simple.class, client); try { proxy.hello("foo"); } catch (AvroRemoteException e) { throw e.getCause(); } finally { s.close(); } }
e.printStackTrace(); Assert.fail("Unexpected error: " + e.toString());
public RemoteException convert(AvroRemoteException exception) { return new RemoteException(exception.getMessage(), exception); }
@Override public void writeError(Schema schema, Object error, Encoder out) throws IOException { if (error instanceof AvroRemoteException) error = ((AvroRemoteException)error).getValue(); getDatumWriter(schema).write(error, out); }
@Override public boolean isAlive() { try { return proxy.isAlive(); } catch (AvroRemoteException e) { e.printStackTrace(); } return false; }
@Override public byte[] retrieveFile(String filePath, int offset, int numBytes) throws DataTransferException { try { return this.proxy.retrieveFile(filePath, offset, numBytes).array(); } catch (AvroRemoteException e) { throw new DataTransferException(e.getMessage()); } }
@Test public void testError() throws IOException { GenericRecord params = new GenericData.Record(PROTOCOL.getMessages().get("error").getRequest()); AvroRemoteException error = null; try { requestor.request("error", params); } catch (AvroRemoteException e) { error = e; } assertNotNull(error); assertEquals("an error", ((GenericRecord)error.getValue()).get("message").toString()); }
public boolean killJob() { try { this.client = new NettyTransceiver(new InetSocketAddress(remoteHost.getIpAddr().getPort())); this.proxy = (AvroRpcBatchStub) SpecificRequestor.getClient(AvroRpcBatchStub.class, client); } catch (IOException e) { LOG.log(Level.SEVERE, "Failed connection with the server.", e); } boolean result = false; try { result = proxy.killJob(AvroTypeFactory.getAvroJob(jobSpec.getJob())); } catch (AvroRemoteException e) { e.printStackTrace(); result = false; } if (result) { parent.jobKilled(jobSpec); } return result; }
@Override public Exception readError(Schema writer, Schema reader, Decoder in) throws IOException { Object error = new GenericDatumReader<>(writer, reader, data) .read(null,in); if (error instanceof CharSequence) return new AvroRuntimeException(error.toString()); // system error return new AvroRemoteException(error); }
@Override public void transferFile(String filePath, byte[] fileData, int offset, int numBytes) throws DataTransferException { try { this.proxy.transferFile(filePath, ByteBuffer.wrap(fileData), offset, numBytes); } catch (AvroRemoteException e) { throw new DataTransferException(e.getMessage()); } }
public AvroRemoteException(Throwable value) { this(value.toString()); initCause(value); }
Assert.fail("Send after server close should have thrown Exception"); } catch (AvroRemoteException e) { ioeCaught = e.getCause() instanceof IOException; Assert.assertTrue("Expected IOException", ioeCaught); } catch (Exception e) {
@Override public void writeError(Schema schema, Object error, Encoder out) throws IOException { if (error instanceof AvroRemoteException) error = ((AvroRemoteException)error).getValue(); getDatumWriter(schema).write(error, out); }
@Override public <T> void request(String messageName, Object request, Callback<T> callback) throws IOException { try { super.request(messageName, request, callback); } catch (Exception e) { if (e instanceof RuntimeException) throw (RuntimeException)e; if (e instanceof IOException) throw (IOException)e; throw new AvroRemoteException(e); } }
@Override public boolean hasProduct(String productName) throws CatalogException { try { return this.proxy.hasProduct(productName); } catch (AvroRemoteException e) { throw new CatalogException(e.getMessage()); } }
public AvroRemoteException(Throwable value) { this(value.toString()); initCause(value); }
private RuntimeException handleAvroRemoteException(AvroRemoteException e) throws TypeException { // AvroRemoteException's are exceptions which are not declared in the avro protocol and // which are not RuntimeException's. if (e.getCause() instanceof IOException) { throw new IOTypeException(e.getCause()); } else { throw converter.convert(e); } }
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { try { return invokeUnaryMethod(method, args); } catch (RuntimeException re) { //rethrow any runtime exception throw re; } catch (Exception e) { //throw any of the declared exceptions for (Class<?> exceptionClass : method.getExceptionTypes()) { if (exceptionClass.isInstance(e)) { throw e; } } //wrap all other exceptions throw new AvroRemoteException(e); } }