@Override public void sendResponse(Throwable error) throws IOException { BytesStreamOutput stream; try { stream = BytesStreamOutput.Cached.cached(); writeResponseExceptionHeader(stream); RemoteTransportException tx = new RemoteTransportException( transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, error); ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); too.writeObject(tx); too.close(); } catch (NotSerializableException e) { stream = BytesStreamOutput.Cached.cached(); writeResponseExceptionHeader(stream); RemoteTransportException tx = new RemoteTransportException( transport.nodeName(), transport.wrapAddress(channel.getLocalAddress()), action, new NotSerializableTransportException(error)); ThrowableObjectOutputStream too = new ThrowableObjectOutputStream(stream); too.writeObject(tx); too.close(); } ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(stream.copiedByteArray()); buffer.setInt(0, buffer.writerIndex() - 4); // update real size. channel.write(buffer); }
private void writeResponseExceptionHeader(BytesStreamOutput stream) throws IOException { stream.writeBytes(LENGTH_PLACEHOLDER); stream.writeLong(requestId); byte status = 0; status = setResponse(status); status = setError(status); stream.writeByte(status); }