This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 4c0e41c [AVRO-732] Remove AvroRemoteException from generated
interfaces Patch from Sebastien Launay applied
4c0e41c is described below
commit 4c0e41cebc0804c563dffe98a58c06b1c39098e1
Author: Daniel Kulp <[email protected]>
AuthorDate: Thu Apr 4 18:12:50 2019 -0400
[AVRO-732] Remove AvroRemoteException from generated interfaces
Patch from Sebastien Launay applied
---
.../src/main/java/service/SimpleOrderService.java | 3 +-
.../java/transport/SimpleOrderServiceClient.java | 3 +-
.../java/org/apache/avro/AvroRemoteException.java | 4 +-
.../java/org/apache/avro/reflect/ReflectData.java | 4 +-
.../specific/templates/java/classic/protocol.vm | 7 ++-
.../org/apache/avro/grpc/TestAvroProtocolGrpc.java | 11 ++--
.../apache/avro/ipc/jetty/StatsPluginOverhead.java | 2 +-
.../apache/avro/ipc/jetty/TestProtocolHttp.java | 12 ++--
.../avro/ipc/jetty/TestStatsPluginAndServlet.java | 6 +-
.../netty/TestNettyServerConcurrentExecution.java | 13 ++---
.../ipc/netty/TestNettyServerWithCallbacks.java | 25 ++++----
.../main/java/org/apache/avro/ipc/Requestor.java | 67 +++++++++++++---------
.../java/org/apache/avro/ipc/SocketServer.java | 5 +-
.../apache/avro/ipc/generic/GenericRequestor.java | 27 ---------
.../avro/ipc/specific/SpecificRequestor.java | 5 +-
.../avro/ipc/specific/SpecificResponder.java | 7 ++-
.../org/apache/avro/TestNamespaceSpecific.java | 2 +-
.../java/org/apache/avro/TestProtocolGeneric.java | 16 +++---
.../java/org/apache/avro/TestProtocolReflect.java | 2 +-
.../java/org/apache/avro/TestProtocolSpecific.java | 2 +-
.../compiler/specific/TestSpecificCompiler.java | 2 +-
.../org/apache/avro/ipc/TestLocalTransceiver.java | 4 +-
.../org/apache/avro/ipc/TestRpcPluginOrdering.java | 3 +-
pom.xml | 1 +
24 files changed, 109 insertions(+), 124 deletions(-)
diff --git
a/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
b/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
index e9a103a..49985cd 100644
---
a/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
+++
b/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/service/SimpleOrderService.java
@@ -21,7 +21,6 @@
package ${package}.service;
-import org.apache.avro.AvroRemoteException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -34,7 +33,7 @@ public class SimpleOrderService implements
OrderProcessingService {
private Logger log = LoggerFactory.getLogger(SimpleOrderService.class);
@Override
- public Confirmation submitOrder(Order order) throws AvroRemoteException,
OrderFailure {
+ public Confirmation submitOrder(Order order) throws OrderFailure {
log.info("Received order for '{}' items from customer with id '{}'",
new Object[] {order.getOrderItems().size(), order.getCustomerId()});
diff --git
a/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
b/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
index b76bf40..75db945 100644
---
a/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
+++
b/lang/java/archetypes/avro-service-archetype/src/main/resources/archetype-resources/src/main/java/transport/SimpleOrderServiceClient.java
@@ -24,7 +24,6 @@ package ${package}.transport;
import java.io.IOException;
import java.net.InetSocketAddress;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.ipc.Transceiver;
import org.apache.avro.ipc.netty.NettyTransceiver;
import org.apache.avro.ipc.specific.SpecificRequestor;
@@ -72,7 +71,7 @@ public class SimpleOrderServiceClient implements
OrderProcessingService {
}
@Override
- public Confirmation submitOrder(Order order) throws AvroRemoteException,
OrderFailure {
+ public Confirmation submitOrder(Order order) throws OrderFailure {
return service.submitOrder(order);
}
diff --git
a/lang/java/avro/src/main/java/org/apache/avro/AvroRemoteException.java
b/lang/java/avro/src/main/java/org/apache/avro/AvroRemoteException.java
index 25aae66..747b236 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/AvroRemoteException.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/AvroRemoteException.java
@@ -18,10 +18,8 @@
package org.apache.avro;
-import java.io.IOException;
-
/** Base class for exceptions thrown to client by server. */
-public class AvroRemoteException extends IOException {
+public class AvroRemoteException extends Exception {
private Object value;
protected AvroRemoteException() {
diff --git
a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
index 5d0d0a6..372b81e 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
@@ -41,7 +41,6 @@ import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.AvroRuntimeException;
import org.apache.avro.AvroTypeException;
import org.apache.avro.Conversion;
@@ -821,8 +820,7 @@ public class ReflectData extends SpecificData {
List<Schema> errs = new ArrayList<>();
errs.add(Protocol.SYSTEM_ERROR); // every method can throw
for (Type err : method.getGenericExceptionTypes())
- if (err != AvroRemoteException.class)
- errs.add(getSchema(err, names));
+ errs.add(getSchema(err, names));
Schema errors = Schema.createUnion(errs);
return protocol.createMessage(method.getName(), null /* doc */, new
LinkedHashMap<String, String>() /* propMap */,
request, response, errors);
diff --git
a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
index 2d53f62..48d51b9 100644
---
a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
+++
b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
@@ -49,11 +49,12 @@ public interface $this.mangle($protocol.getName()) {
#foreach ($p in $message.getRequest().getFields())##
#* *#${this.javaUnbox($p.schema())} ${this.mangle($p.name())}#if
($foreach.hasNext), #end
#end
-)#if (! $message.isOneWay())
- throws org.apache.avro.AvroRemoteException##
+)#if (! $message.isOneWay() && $message.getErrors().getTypes().size() > 1)
+ throws ##
## The first error is always "string", so we skip it.
#foreach ($error in $message.getErrors().getTypes().subList(1,
$message.getErrors().getTypes().size()))
-, ${this.mangle($error.getFullName())}##
+${this.mangle($error.getFullName())}##
+#if ($foreach.hasNext), #end
#end## (error list)
#end## (one way)
;
diff --git
a/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
b/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
index 99bb2a8..850b476 100644
---
a/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
+++
b/lang/java/grpc/src/test/java/org/apache/avro/grpc/TestAvroProtocolGrpc.java
@@ -18,7 +18,6 @@
package org.apache.avro.grpc;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.AvroRuntimeException;
import org.apache.avro.grpc.test.Kind;
import org.apache.avro.grpc.test.MD5;
@@ -159,7 +158,7 @@ public class TestAvroProtocolGrpc {
public void testNullableResponse() throws Exception {
setUpServerAndClient(new TestServiceImplBase() {
@Override
- public String concatenate(String val1, boolean val2, long val3, int
val4) throws AvroRemoteException {
+ public String concatenate(String val1, boolean val2, long val3, int
val4) {
return null;
}
});
@@ -227,17 +226,17 @@ public class TestAvroProtocolGrpc {
private class TestServiceImplBase implements TestService {
@Override
- public TestRecord echo(TestRecord record) throws AvroRemoteException {
+ public TestRecord echo(TestRecord record) {
return record;
}
@Override
- public int add(int arg1, int arg2, int arg3) throws AvroRemoteException {
+ public int add(int arg1, int arg2, int arg3) {
return arg1 + arg2 + arg3;
}
@Override
- public void error(boolean declared) throws AvroRemoteException, TestError {
+ public void error(boolean declared) throws TestError {
if (declared) {
throw declaredError;
}
@@ -256,7 +255,7 @@ public class TestAvroProtocolGrpc {
}
@Override
- public String concatenate(String val1, boolean val2, long val3, int val4)
throws AvroRemoteException {
+ public String concatenate(String val1, boolean val2, long val3, int val4) {
return val1 + val2 + val3 + val4;
}
}
diff --git
a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/StatsPluginOverhead.java
b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/StatsPluginOverhead.java
index 35a9db7..2164c91 100644
---
a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/StatsPluginOverhead.java
+++
b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/StatsPluginOverhead.java
@@ -63,7 +63,7 @@ public class StatsPluginOverhead {
}
/** Sends RPCs and returns nanos elapsed. */
- private static long sendRpcs(boolean withPlugin) throws IOException {
+ private static long sendRpcs(boolean withPlugin) throws Exception {
HttpServer server = createServer(withPlugin);
Transceiver t = new HttpTransceiver(new URL("http://127.0.0.1:" +
server.getPort() + "/"));
GenericRequestor requestor = new GenericRequestor(NULL_PROTOCOL, t);
diff --git
a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestProtocolHttp.java
b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestProtocolHttp.java
index 2c333cf..ed8c59f 100644
---
a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestProtocolHttp.java
+++
b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestProtocolHttp.java
@@ -17,7 +17,10 @@
*/
package org.apache.avro.ipc.jetty;
-import org.apache.avro.AvroRemoteException;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.avro.AvroRuntimeException;
import org.apache.avro.Protocol;
import org.apache.avro.Schema;
import org.apache.avro.TestProtocolSpecific;
@@ -54,7 +57,7 @@ public class TestProtocolHttp extends TestProtocolSpecific {
return REPEATING;
}
- @Test(expected = SocketTimeoutException.class)
+ @Test
public void testTimeout() throws Throwable {
ServerSocket s = new ServerSocket(0);
HttpTransceiver client = new HttpTransceiver(new URL("http://127.0.0.1:" +
s.getLocalPort() + "/"));
@@ -62,8 +65,9 @@ public class TestProtocolHttp extends TestProtocolSpecific {
Simple proxy = SpecificRequestor.getClient(Simple.class, client);
try {
proxy.hello("foo");
- } catch (AvroRemoteException e) {
- throw e.getCause();
+ fail("Should have failed with an exception");
+ } catch (AvroRuntimeException e) {
+ assertTrue("Got unwanted exception: " + e.getCause(), e.getCause()
instanceof SocketTimeoutException);
} finally {
s.close();
}
diff --git
a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestStatsPluginAndServlet.java
b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestStatsPluginAndServlet.java
index 9152527..3d83b89 100644
---
a/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestStatsPluginAndServlet.java
+++
b/lang/java/ipc-jetty/src/test/java/org/apache/avro/ipc/jetty/TestStatsPluginAndServlet.java
@@ -83,7 +83,7 @@ public class TestStatsPluginAndServlet {
}
- private void makeRequest(Transceiver t) throws IOException {
+ private void makeRequest(Transceiver t) throws Exception {
GenericRecord params = new
GenericData.Record(protocol.getMessages().get("m").getRequest());
params.put("x", 0);
GenericRequestor r = new GenericRequestor(protocol, t);
@@ -91,7 +91,7 @@ public class TestStatsPluginAndServlet {
}
@Test
- public void testFullServerPath() throws IOException {
+ public void testFullServerPath() throws Exception {
Responder r = new TestResponder(protocol);
StatsPlugin statsPlugin = new StatsPlugin();
r.addRPCPlugin(statsPlugin);
@@ -126,7 +126,7 @@ public class TestStatsPluginAndServlet {
}
@Test
- public void testPayloadSize() throws IOException {
+ public void testPayloadSize() throws Exception {
Responder r = new TestResponder(protocol);
StatsPlugin statsPlugin = new StatsPlugin();
r.addRPCPlugin(statsPlugin);
diff --git
a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerConcurrentExecution.java
b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerConcurrentExecution.java
index b0375db..4bb9a79 100644
---
a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerConcurrentExecution.java
+++
b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerConcurrentExecution.java
@@ -24,7 +24,6 @@ import java.nio.ByteBuffer;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.ipc.Server;
import org.apache.avro.ipc.Transceiver;
import org.apache.avro.ipc.specific.SpecificRequestor;
@@ -137,7 +136,7 @@ public class TestNettyServerConcurrentExecution {
/**
* Creates a SimpleImpl that uses the given CountDownLatch.
- *
+ *
* @param waitLatch the CountDownLatch to use in {@link #hello(String)}.
*/
public SimpleImpl(final CountDownLatch waitLatch) {
@@ -145,13 +144,13 @@ public class TestNettyServerConcurrentExecution {
}
@Override
- public int add(int arg1, int arg2) throws AvroRemoteException {
+ public int add(int arg1, int arg2) {
// Step 1:
return arg1 + arg2;
}
@Override
- public String hello(String greeting) throws AvroRemoteException {
+ public String hello(String greeting) {
if (greeting.equals("wait")) {
try {
// Step 3a:
@@ -176,17 +175,17 @@ public class TestNettyServerConcurrentExecution {
// All RPCs below this line are irrelevant to this test:
@Override
- public TestRecord echo(TestRecord record) throws AvroRemoteException {
+ public TestRecord echo(TestRecord record) {
return record;
}
@Override
- public ByteBuffer echoBytes(ByteBuffer data) throws AvroRemoteException {
+ public ByteBuffer echoBytes(ByteBuffer data) {
return data;
}
@Override
- public void error() throws AvroRemoteException, TestError {
+ public void error() throws TestError {
throw new TestError("TestError");
}
}
diff --git
a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java
b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java
index 7baa6c9..05e8c53 100644
---
a/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java
+++
b/lang/java/ipc-netty/src/test/java/org/apache/avro/ipc/netty/TestNettyServerWithCallbacks.java
@@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.avro.AvroRemoteException;
+import org.apache.avro.AvroRuntimeException;
import org.apache.avro.ipc.CallFuture;
import org.apache.avro.ipc.Callback;
import org.apache.avro.ipc.Responder;
@@ -293,7 +294,7 @@ public class TestNettyServerWithCallbacks {
try {
simpleClient2.add(1, 2);
Assert.fail("Send after server close should have thrown Exception");
- } catch (AvroRemoteException e) {
+ } catch (AvroRuntimeException e) {
ioeCaught = e.getCause() instanceof IOException;
Assert.assertTrue("Expected IOException", ioeCaught);
} catch (Exception e) {
@@ -517,7 +518,7 @@ public class TestNettyServerWithCallbacks {
/**
* Creates a SimpleImpl.
- *
+ *
* @param ackFlag the AtomicBoolean to toggle when ack() is called.
*/
public SimpleImpl(final AtomicBoolean ackFlag) {
@@ -525,27 +526,27 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public String hello(String greeting) throws AvroRemoteException {
+ public String hello(String greeting) {
return "Hello, " + greeting;
}
@Override
- public TestRecord echo(TestRecord record) throws AvroRemoteException {
+ public TestRecord echo(TestRecord record) {
return record;
}
@Override
- public int add(int arg1, int arg2) throws AvroRemoteException {
+ public int add(int arg1, int arg2) {
return arg1 + arg2;
}
@Override
- public ByteBuffer echoBytes(ByteBuffer data) throws AvroRemoteException {
+ public ByteBuffer echoBytes(ByteBuffer data) {
return data;
}
@Override
- public void error() throws AvroRemoteException, TestError {
+ public void error() throws TestError {
throw TestError.newBuilder().setMessage$("Test Message").build();
}
@@ -573,7 +574,7 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public String hello(String greeting) throws AvroRemoteException {
+ public String hello(String greeting) {
releaseEnterPermit();
acquireRunPermit();
try {
@@ -584,7 +585,7 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public TestRecord echo(TestRecord record) throws AvroRemoteException {
+ public TestRecord echo(TestRecord record) {
releaseEnterPermit();
acquireRunPermit();
try {
@@ -595,7 +596,7 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public int add(int arg1, int arg2) throws AvroRemoteException {
+ public int add(int arg1, int arg2) {
releaseEnterPermit();
acquireRunPermit();
try {
@@ -606,7 +607,7 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public ByteBuffer echoBytes(ByteBuffer data) throws AvroRemoteException {
+ public ByteBuffer echoBytes(ByteBuffer data) {
releaseEnterPermit();
acquireRunPermit();
try {
@@ -617,7 +618,7 @@ public class TestNettyServerWithCallbacks {
}
@Override
- public void error() throws AvroRemoteException, TestError {
+ public void error() throws TestError {
releaseEnterPermit();
acquireRunPermit();
try {
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
index c0835ef..eb9f230 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/Requestor.java
@@ -81,7 +81,7 @@ public abstract class Requestor {
/**
* Adds a new plugin to manipulate RPC metadata. Plugins are executed in the
* order that they are added.
- *
+ *
* @param plugin a plugin that will manipulate RPC metadata
*/
public void addRPCPlugin(RPCPlugin plugin) {
@@ -105,10 +105,11 @@ public abstract class Requestor {
try { // the message is two-way, wait for the result
return future.get();
} catch (ExecutionException e) {
- if (e.getCause() instanceof Exception) {
- throw (Exception) e.getCause();
+ Throwable error = e.getCause();
+ if (error instanceof Exception) {
+ throw (Exception) error;
} else {
- throw new AvroRemoteException(e.getCause());
+ throw new AvroRuntimeException(error);
}
}
}
@@ -117,20 +118,25 @@ public abstract class Requestor {
* Writes a request message and returns the result through a Callback.
Clients
* can also use a Future interface by creating a new CallFuture<T>, passing
it
* in as the Callback parameter, and then waiting on that Future.
- *
+ *
* @param <T> the return type of the message.
* @param messageName the name of the message to invoke.
* @param request the request data to send.
* @param callback the callback which will be invoked when the response is
* returned or an error occurs.
- * @throws Exception if an error occurs sending the message.
+ * @throws AvroRemoteException if an exception is thrown to client by
server.
+ * @throws IOException if an I/O error occurs while sending the
+ * message.
+ * @throws AvroRuntimeException for another undeclared error while sending
the
+ * message.
*/
- public <T> void request(String messageName, Object request, Callback<T>
callback) throws Exception {
+ public <T> void request(String messageName, Object request, Callback<T>
callback)
+ throws AvroRemoteException, IOException {
request(new Request(messageName, request, new RPCContext()), callback);
}
/** Writes a request message and returns the result through a Callback. */
- <T> void request(Request request, Callback<T> callback) throws Exception {
+ <T> void request(Request request, Callback<T> callback) throws
AvroRemoteException, IOException {
Transceiver t = getTransceiver();
if (!t.isConnected()) {
// Acquire handshake lock so that only one thread is performing the
@@ -144,15 +150,24 @@ public abstract class Requestor {
} else {
CallFuture<T> callFuture = new CallFuture<>(callback);
t.transceive(request.getBytes(), new TransceiverCallback<>(request,
callFuture));
- // Block until handshake complete
- callFuture.await();
+ try {
+ // Block until handshake complete
+ callFuture.await();
+ } catch (InterruptedException e) {
+ // Restore the interrupted status
+ Thread.currentThread().interrupt();
+ }
if (request.getMessage().isOneWay()) {
Throwable error = callFuture.getError();
if (error != null) {
- if (error instanceof Exception) {
- throw (Exception) error;
+ if (error instanceof AvroRemoteException) {
+ throw (AvroRemoteException) error;
+ } else if (error instanceof AvroRuntimeException) {
+ throw (AvroRuntimeException) error;
+ } else if (error instanceof IOException) {
+ throw (IOException) error;
} else {
- throw new AvroRemoteException(error);
+ throw new AvroRuntimeException(error);
}
}
}
@@ -318,7 +333,7 @@ public abstract class Requestor {
/**
* Creates a TransceiverCallback.
- *
+ *
* @param request the request to set.
* @param callback the callback to set.
*/
@@ -382,7 +397,7 @@ public abstract class Requestor {
/**
* Creates a Request.
- *
+ *
* @param messageName the name of the message to invoke.
* @param request the request data to send.
* @param context the RPC context to use.
@@ -393,7 +408,7 @@ public abstract class Requestor {
/**
* Creates a Request.
- *
+ *
* @param messageName the name of the message to invoke.
* @param request the request data to send.
* @param context the RPC context to use.
@@ -408,7 +423,7 @@ public abstract class Requestor {
/**
* Copy constructor.
- *
+ *
* @param other Request from which to copy fields.
*/
public Request(Request other) {
@@ -420,7 +435,7 @@ public abstract class Requestor {
/**
* Gets the message name.
- *
+ *
* @return the message name.
*/
public String getMessageName() {
@@ -429,7 +444,7 @@ public abstract class Requestor {
/**
* Gets the RPC context.
- *
+ *
* @return the RPC context.
*/
public RPCContext getContext() {
@@ -438,7 +453,7 @@ public abstract class Requestor {
/**
* Gets the Message associated with this request.
- *
+ *
* @return this request's message.
*/
public Message getMessage() {
@@ -453,11 +468,11 @@ public abstract class Requestor {
/**
* Gets the request data, generating it first if necessary.
- *
+ *
* @return the request data.
- * @throws Exception if an error occurs generating the request data.
+ * @throws IOException if an error occurs generating the request data.
*/
- public List<ByteBuffer> getBytes() throws Exception {
+ public List<ByteBuffer> getBytes() throws IOException {
if (requestBytes == null) {
ByteBufferOutputStream bbo = new ByteBufferOutputStream();
BinaryEncoder out = ENCODER_FACTORY.binaryEncoder(bbo, encoder);
@@ -499,7 +514,7 @@ public abstract class Requestor {
/**
* Creates a Response.
- *
+ *
* @param request the Request associated with this response.
*/
public Response(Request request) {
@@ -508,7 +523,7 @@ public abstract class Requestor {
/**
* Creates a Creates a Response.
- *
+ *
* @param request the Request associated with this response.
* @param in the BinaryDecoder to use to deserialize the response.
*/
@@ -519,7 +534,7 @@ public abstract class Requestor {
/**
* Gets the RPC response, reading/deserializing it first if necessary.
- *
+ *
* @return the RPC response.
* @throws Exception if an error occurs reading/deserializing the response.
*/
diff --git a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
index 262c12c..a268b46 100644
--- a/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
+++ b/lang/java/ipc/src/main/java/org/apache/avro/ipc/SocketServer.java
@@ -29,6 +29,7 @@ import java.nio.channels.SocketChannel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.avro.AvroRemoteException;
import org.apache.avro.Protocol;
import org.apache.avro.Protocol.Message;
import org.apache.avro.ipc.generic.GenericResponder;
@@ -36,7 +37,7 @@ import org.apache.avro.ipc.generic.GenericResponder;
/**
* A socket-based server implementation. This uses a simple, non-standard wire
* protocol and is not intended for production services.
- *
+ *
* @deprecated use {@link SaslSocketServer} instead.
*/
@Deprecated
@@ -139,7 +140,7 @@ public class SocketServer extends Thread implements Server {
Responder responder = new GenericResponder(Protocol.parse("{\"protocol\":
\"X\"}")) {
@Override
public Object respond(Message message, Object request) throws Exception {
- throw new IOException("no messages!");
+ throw new AvroRemoteException("no messages!");
}
};
SocketServer server = new SocketServer(responder, new
InetSocketAddress(0));
diff --git
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
index 454d814..8fe00fd 100644
---
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
+++
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/generic/GenericRequestor.java
@@ -29,7 +29,6 @@ import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.io.Decoder;
import org.apache.avro.io.Encoder;
-import org.apache.avro.ipc.Callback;
import org.apache.avro.ipc.Requestor;
import org.apache.avro.ipc.Transceiver;
@@ -51,32 +50,6 @@ public class GenericRequestor extends Requestor {
}
@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);
- }
- }
-
- @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 void writeRequest(Schema schema, Object request, Encoder out) throws
IOException {
new GenericDatumWriter<>(schema, data).write(request, out);
}
diff --git
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
index 471d668..7e6cf3c 100644
---
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
+++
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificRequestor.java
@@ -25,7 +25,6 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Type;
import java.util.Arrays;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.Protocol;
import org.apache.avro.Schema;
import org.apache.avro.AvroRuntimeException;
@@ -121,8 +120,8 @@ public class SpecificRequestor extends Requestor implements
InvocationHandler {
throw e;
}
- // Not an expected Exception, so wrap it in AvroRemoteException:
- throw new AvroRemoteException(e);
+ // Not an expected Exception, so wrap it in AvroRuntimeException:
+ throw new AvroRuntimeException(e);
}
}
}
diff --git
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java
index 7d37f61..cd69cfe 100644
---
a/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java
+++
b/lang/java/ipc/src/main/java/org/apache/avro/ipc/specific/SpecificResponder.java
@@ -91,10 +91,11 @@ public class SpecificResponder extends GenericResponder {
method.setAccessible(true);
return method.invoke(impl, params);
} catch (InvocationTargetException e) {
- if (e.getTargetException() instanceof Exception) {
- throw (Exception) e.getTargetException();
+ Throwable error = e.getTargetException();
+ if (error instanceof Exception) {
+ throw (Exception) error;
} else {
- throw new Exception(e.getTargetException());
+ throw new AvroRuntimeException(error);
}
} catch (NoSuchMethodException | IllegalAccessException e) {
throw new AvroRuntimeException(e);
diff --git
a/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java
b/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java
index d429092..7afd609 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestNamespaceSpecific.java
@@ -42,7 +42,7 @@ public class TestNamespaceSpecific {
return record;
}
- public void error() throws AvroRemoteException {
+ public void error() throws TestError {
throw TestError.newBuilder().setMessage$("an error").build();
}
}
diff --git
a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
index 43ead73..3692644 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolGeneric.java
@@ -113,7 +113,7 @@ public class TestProtocolGeneric {
}
@Test
- public void testHello() throws IOException {
+ public void testHello() throws Exception {
GenericRecord params = new
GenericData.Record(PROTOCOL.getMessages().get("hello").getRequest());
params.put("greeting", new Utf8("bob"));
Utf8 response = (Utf8) requestor.request("hello", params);
@@ -121,7 +121,7 @@ public class TestProtocolGeneric {
}
@Test
- public void testEcho() throws IOException {
+ public void testEcho() throws Exception {
GenericRecord record = new
GenericData.Record(PROTOCOL.getType("TestRecord"));
record.put("name", new Utf8("foo"));
record.put("kind", new GenericData.EnumSymbol(PROTOCOL.getType("Kind"),
"BAR"));
@@ -134,7 +134,7 @@ public class TestProtocolGeneric {
}
@Test
- public void testEchoBytes() throws IOException {
+ public void testEchoBytes() throws Exception {
Random random = new Random();
int length = random.nextInt(1024 * 16);
GenericRecord params = new
GenericData.Record(PROTOCOL.getMessages().get("echoBytes").getRequest());
@@ -147,7 +147,7 @@ public class TestProtocolGeneric {
}
@Test
- public void testError() throws IOException {
+ public void testError() throws Exception {
GenericRecord params = new
GenericData.Record(PROTOCOL.getMessages().get("error").getRequest());
AvroRemoteException error = null;
try {
@@ -160,7 +160,7 @@ public class TestProtocolGeneric {
}
@Test
- public void testUndeclaredError() throws IOException {
+ public void testUndeclaredError() throws Exception {
this.throwUndeclaredError = true;
RuntimeException error = null;
GenericRecord params = new
GenericData.Record(PROTOCOL.getMessages().get("error").getRequest());
@@ -180,7 +180,7 @@ public class TestProtocolGeneric {
* Construct and use a different protocol whose "hello" method has an extra
* argument to check that schema is sent to parse request.
*/
- public void testHandshake() throws IOException {
+ public void testHandshake() throws Exception {
Protocol protocol = new Protocol("Simple", "org.apache.avro.test");
List<Field> fields = new ArrayList<>();
fields.add(new Schema.Field("extra", Schema.create(Schema.Type.BOOLEAN),
null, null));
@@ -203,7 +203,7 @@ public class TestProtocolGeneric {
* Construct and use a different protocol whose "echo" response has an extra
* field to check that correct schema is used to parse response.
*/
- public void testResponseChange() throws IOException {
+ public void testResponseChange() throws Exception {
List<Field> fields = new ArrayList<>();
for (Field f : PROTOCOL.getType("TestRecord").getFields())
@@ -235,7 +235,7 @@ public class TestProtocolGeneric {
}
@AfterClass
- public static void testStopServer() throws IOException {
+ public static void testStopServer() throws Exception {
client.close();
server.close();
}
diff --git
a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java
b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java
index 854cb41..3064abc 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolReflect.java
@@ -163,7 +163,7 @@ public class TestProtocolReflect {
RuntimeException error = null;
try {
proxy.error();
- } catch (RuntimeException e) {
+ } catch (AvroRuntimeException e) {
error = e;
} finally {
this.throwUndeclaredError = false;
diff --git
a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
index 4aaedb4..5b6875e 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/TestProtocolSpecific.java
@@ -79,7 +79,7 @@ public class TestProtocolSpecific {
return data;
}
- public void error() throws AvroRemoteException {
+ public void error() throws TestError {
if (throwUndeclaredError)
throw new RuntimeException("foo");
throw TestError.newBuilder().setMessage$("an error").build();
diff --git
a/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
b/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
index 84edb58..2aefffc 100644
---
a/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
+++
b/lang/java/ipc/src/test/java/org/apache/avro/compiler/specific/TestSpecificCompiler.java
@@ -118,7 +118,7 @@ public class TestSpecificCompiler {
assertTrue(protocol.contains("java.lang.CharSequence
goto$(java.lang.CharSequence break$)"));
assertTrue(protocol.contains("public interface default$"));
- assertTrue(protocol.contains("throws org.apache.avro.AvroRemoteException,
finally$"));
+ assertTrue(protocol.contains(" finally$"));
assertCompilesWithJavaCompiler(new File(INPUT_DIR.getRoot(),
name.getMethodName()), outputs);
diff --git
a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
index e235668..c1db6d9 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestLocalTransceiver.java
@@ -19,8 +19,6 @@ package org.apache.avro.ipc;
import static org.junit.Assert.assertEquals;
-import java.io.IOException;
-
import org.apache.avro.AvroRemoteException;
import org.apache.avro.Protocol;
import org.apache.avro.Protocol.Message;
@@ -50,7 +48,7 @@ public class TestLocalTransceiver {
}
@Test
- public void testSingleRpc() throws IOException {
+ public void testSingleRpc() throws Exception {
Transceiver t = new LocalTransceiver(new TestResponder(protocol));
GenericRecord params = new
GenericData.Record(protocol.getMessages().get("m").getRequest());
params.put("x", new Utf8("hello"));
diff --git
a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
index f6fa24b..a895600 100644
--- a/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
+++ b/lang/java/ipc/src/test/java/org/apache/avro/ipc/TestRpcPluginOrdering.java
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertEquals;
import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.avro.AvroRemoteException;
import org.apache.avro.ipc.specific.SpecificRequestor;
import org.apache.avro.ipc.specific.SpecificResponder;
import org.apache.avro.test.Mail;
@@ -85,7 +84,7 @@ public class TestRpcPluginOrdering {
}
private static class TestMailImpl implements Mail {
- public String send(Message message) throws AvroRemoteException {
+ public String send(Message message) {
return "Received";
}
diff --git a/pom.xml b/pom.xml
index 040ed28..9754cae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -288,6 +288,7 @@
<exclude>**/.gitignore</exclude>
<!-- build or test files (some are generated files that we
commit as-is for testing purposes) -->
<exclude>**/*.log</exclude>
+ <exclude>**/*.rej</exclude>
<exclude>build/**</exclude>
<exclude>doc/build/**</exclude>
<exclude>lang/java/archetypes/**</exclude>