本文整理汇总了Java中org.apache.thrift.TApplicationException.write方法的典型用法代码示例。如果您正苦于以下问题:Java TApplicationException.write方法的具体用法?Java TApplicationException.write怎么用?Java TApplicationException.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.TApplicationException
的用法示例。
在下文中一共展示了TApplicationException.write方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@Override
public boolean process(TProtocol in, TProtocol out) throws TException {
TMessage msg = in.readMessageBegin();
Controller<?, ?> fn = (Controller<?, ?>) this.beanFactory
.getBean(msg.name);
if (fn == null) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Invalid request: failed to find interface="
+ msg.name + ", from: " + getInetAddress(in));
}
TProtocolUtil.skip(in, TType.STRUCT);
in.readMessageEnd();
TApplicationException x = new TApplicationException(
TApplicationException.UNKNOWN_METHOD,
"Invalid method name: '" + msg.name + "'");
out.writeMessageBegin(new TMessage(msg.name,
TMessageType.EXCEPTION, msg.seqid));
x.write(out);
out.writeMessageEnd();
out.getTransport().flush();
return true;
}
process(msg.seqid, msg.name, in, out, fn);
return true;
}
示例2: process
import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@Override
public final boolean process(final TProtocol in, final TProtocol out)
throws TException {
final TMessage msg = in.readMessageBegin();
final ProcessFunction<LocatorServiceImpl, ?> fn = this.fnMap
.get(msg.name);
if (fn != null) {
fn.process(msg.seqid, in, out, this.inst);
// terminate connection on receiving closeConnection
// direct class comparison should be the fastest way
return fn.getClass() != LocatorService.Processor.closeConnection.class;
}
else {
TProtocolUtil.skip(in, TType.STRUCT);
in.readMessageEnd();
TApplicationException x = new TApplicationException(
TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
+ msg.name + "'");
out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
msg.seqid));
x.write(out);
out.writeMessageEnd();
out.getTransport().flush();
return true;
}
}
示例3: writeException
import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes" })
private void writeException(final TProtocol out, final TMessage msg, final WriterHandler onComplete,
final TApplicationException x, TBase args) {
Throwable cause = null;
try {
onComplete.beforeWrite(msg, args, null);
out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
x.write(out);
out.writeMessageEnd();
out.getTransport().flush();
} catch (Throwable e) {
cause = e;
}
onComplete.afterWrite(msg, cause, TMessageType.EXCEPTION, args, null);
}
示例4: process
import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@Override
public final boolean process(final TProtocol in, final TProtocol out)
throws TException {
final TMessage msg = in.readMessageBegin();
final ProcessFunction<GFXDServiceImpl, ?> fn = this.fnMap.get(msg.name);
if (fn != null) {
fn.process(msg.seqid, in, out, this.inst);
// terminate connection on receiving closeConnection
// direct class comparison should be the fastest way
// TODO: SW: also need to clean up connection artifacts in the case of
// client connection failure (ConnectionListener does get a notification
// but how to tie the socket/connectionNumber to the connectionID?)
return fn.getClass() != GFXDService.Processor.closeConnection.class;
}
else {
TProtocolUtil.skip(in, TType.STRUCT);
in.readMessageEnd();
TApplicationException x = new TApplicationException(
TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"
+ msg.name + "'");
out.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION,
msg.seqid));
x.write(out);
out.writeMessageEnd();
out.getTransport().flush();
return true;
}
}
示例5: writeTApplicationException
import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
private void writeTApplicationException(TApplicationException exception, TProtocol protocol) throws TException {
protocol.writeMessageBegin(new TMessage(this.methodName, TMessageType.EXCEPTION, this.seqid));
exception.write(protocol);
protocol.writeMessageEnd();
}
示例6: testDecodeExceptionResponse
import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@Test
public void testDecodeExceptionResponse() throws Exception {
URL url = URL.valueOf( ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.class.getName() );
Channel channel = new MockedChannel( url );
RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream( 128 );
Request request = createRequest();
DefaultFuture future = new DefaultFuture( channel, request, 10 );
TMessage message = new TMessage( "echoString", TMessageType.EXCEPTION, ThriftCodec.getSeqId() );
TTransport transport = new TIOStreamTransport( bos );
TBinaryProtocol protocol = new TBinaryProtocol( transport );
TApplicationException exception = new TApplicationException();
int messageLength, headerLength;
// prepare
protocol.writeI16( ThriftCodec.MAGIC );
protocol.writeI32( Integer.MAX_VALUE );
protocol.writeI16( Short.MAX_VALUE );
protocol.writeByte( ThriftCodec.VERSION );
protocol.writeString( Demo.class.getName() );
protocol.writeI64( request.getId() );
protocol.getTransport().flush();
headerLength = bos.size();
protocol.writeMessageBegin( message );
exception.write( protocol );
protocol.writeMessageEnd();
protocol.getTransport().flush();
int oldIndex = messageLength = bos.size();
try {
bos.setWriteIndex( ThriftCodec.MESSAGE_LENGTH_INDEX );
protocol.writeI32( messageLength );
bos.setWriteIndex( ThriftCodec.MESSAGE_HEADER_LENGTH_INDEX );
protocol.writeI16( ( short ) ( 0xffff & headerLength ) );
} finally {
bos.setWriteIndex( oldIndex );
}
// prepare
ChannelBuffer bis = ChannelBuffers.wrappedBuffer(encodeFrame(bos.toByteArray()));
Object obj = codec.decode( ( Channel ) null, bis );
Assert.assertNotNull( obj );
Assert.assertTrue( obj instanceof Response );
Response response = ( Response ) obj;
Assert.assertTrue( response.getResult() instanceof RpcResult );
RpcResult result = ( RpcResult ) response.getResult();
Assert.assertTrue( result.hasException() );
Assert.assertTrue( result.getException() instanceof RpcException );
}
示例7: testDecodeExceptionResponse
import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@Test
public void testDecodeExceptionResponse() throws Exception {
URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.class.getName());
Channel channel = new MockedChannel(url);
RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(128);
Request request = createRequest();
DefaultFuture future = new DefaultFuture(channel, request, 10);
TMessage message = new TMessage("echoString", TMessageType.EXCEPTION, ThriftCodec.getSeqId());
TTransport transport = new TIOStreamTransport(bos);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
TApplicationException exception = new TApplicationException();
int messageLength, headerLength;
// prepare
protocol.writeI16(ThriftCodec.MAGIC);
protocol.writeI32(Integer.MAX_VALUE);
protocol.writeI16(Short.MAX_VALUE);
protocol.writeByte(ThriftCodec.VERSION);
protocol.writeString(Demo.class.getName());
protocol.writeI64(request.getId());
protocol.getTransport().flush();
headerLength = bos.size();
protocol.writeMessageBegin(message);
exception.write(protocol);
protocol.writeMessageEnd();
protocol.getTransport().flush();
int oldIndex = messageLength = bos.size();
try {
bos.setWriteIndex(ThriftCodec.MESSAGE_LENGTH_INDEX);
protocol.writeI32(messageLength);
bos.setWriteIndex(ThriftCodec.MESSAGE_HEADER_LENGTH_INDEX);
protocol.writeI16((short) (0xffff & headerLength));
} finally {
bos.setWriteIndex(oldIndex);
}
// prepare
ChannelBuffer bis = ChannelBuffers.wrappedBuffer(encodeFrame(bos.toByteArray()));
Object obj = codec.decode((Channel) null, bis);
Assert.assertNotNull(obj);
Assert.assertTrue(obj instanceof Response);
Response response = (Response) obj;
Assert.assertTrue(response.getResult() instanceof RpcResult);
RpcResult result = (RpcResult) response.getResult();
Assert.assertTrue(result.hasException());
Assert.assertTrue(result.getException() instanceof RpcException);
}