当前位置: 首页>>代码示例>>Java>>正文


Java TApplicationException.read方法代码示例

本文整理汇总了Java中org.apache.thrift.TApplicationException.read方法的典型用法代码示例。如果您正苦于以下问题:Java TApplicationException.read方法的具体用法?Java TApplicationException.read怎么用?Java TApplicationException.read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.thrift.TApplicationException的用法示例。


在下文中一共展示了TApplicationException.read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEncodeExceptionResponse

import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@Test
public void testEncodeExceptionResponse() throws Exception {

    URL url = URL.valueOf( ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName() );

    Channel channel = new MockedChannel( url );

    Request request = createRequest();

    RpcResult rpcResult = new RpcResult();
    String exceptionMessage = "failed";
    rpcResult.setException( new RuntimeException( exceptionMessage ) );

    Response response = new Response();
    response.setResult( rpcResult );
    response.setId( request.getId() );
    ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

    ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
            ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
    ThriftCodec.cachedRequest.put( request.getId(), rd );
    codec.encode( channel, bos, response );

    byte[] buf = new byte[bos.writerIndex() - 4];
    System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 );
    ByteArrayInputStream bis = new ByteArrayInputStream( buf);

    if ( bis.markSupported() ) {
        bis.mark( 0 );
    }

    TIOStreamTransport transport = new TIOStreamTransport( bis );
    TBinaryProtocol protocol = new TBinaryProtocol( transport );

    Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );
    Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() );
    int headerLength = protocol.readI16();

    Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
    Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
    Assert.assertEquals( request.getId(), protocol.readI64() );

    if ( bis.markSupported() ) {
        bis.reset();
        bis.skip( headerLength );
    }

    TMessage message = protocol.readMessageBegin();
    Assert.assertEquals( "echoString", message.name );
    Assert.assertEquals( TMessageType.EXCEPTION, message.type );
    Assert.assertEquals( ThriftCodec.getSeqId(), message.seqid );
    TApplicationException exception = TApplicationException.read( protocol );
    protocol.readMessageEnd();

    Assert.assertEquals( exceptionMessage, exception.getMessage() );

}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:58,代码来源:ThriftCodecTest.java

示例2: recv

import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
Object recv(TProtocol protocol, int seqid) throws Exception {
    TMessage msg = protocol.readMessageBegin();
    if (msg.type == TMessageType.EXCEPTION) {
        TApplicationException applicationException = TApplicationException.read(protocol);
        protocol.readMessageEnd();
        throw applicationException;
    }
    if (msg.seqid != seqid) {
        throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID, methodName + " failed: out of sequence response");
    }
    protocol.readStructBegin();
    Object success = null;
    Exception exception = null;
    while (true) {
        TField tField = protocol.readFieldBegin();
        if (tField.type == TType.STOP) {
            break;
        }
        FieldSpec fieldSpec = null;
        if (tField.id == 0) {
            fieldSpec = responseSuccessType;
        } else {
            fieldSpec = responseExceptionTypeMap.get(tField.id);
        }
        if (fieldSpec == null || fieldSpec.typeAdapter.getTType() != tField.type) {
            TProtocolUtil.skip(protocol, tField.type);
        } else {
            Object value = fieldSpec.typeAdapter.read(protocol);
            if (tField.id == 0) {
                success = value;
            } else {
                exception = (Exception) value;
            }
        }
        protocol.readFieldEnd();
    }
    protocol.readStructEnd();
    protocol.readMessageEnd();
    if (exception != null) {
        throw exception;
    }
    if (success != null) {
        return success;
    }
    if (isVoid) {
        return null;
    }
    throw new TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, methodName + " failed: unknown result");
}
 
开发者ID:meituan,项目名称:Firefly,代码行数:50,代码来源:FunctionCall.java

示例3: testEncodeExceptionResponse

import org.apache.thrift.TApplicationException; //导入方法依赖的package包/类
@Test
public void testEncodeExceptionResponse() throws Exception {

    URL url = URL.valueOf(ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName());

    Channel channel = new MockedChannel(url);

    Request request = createRequest();

    RpcResult rpcResult = new RpcResult();
    String exceptionMessage = "failed";
    rpcResult.setException(new RuntimeException(exceptionMessage));

    Response response = new Response();
    response.setResult(rpcResult);
    response.setId(request.getId());
    ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

    ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
            ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString");
    ThriftCodec.cachedRequest.put(request.getId(), rd);
    codec.encode(channel, bos, response);

    byte[] buf = new byte[bos.writerIndex() - 4];
    System.arraycopy(bos.array(), 4, buf, 0, bos.writerIndex() - 4);
    ByteArrayInputStream bis = new ByteArrayInputStream(buf);

    if (bis.markSupported()) {
        bis.mark(0);
    }

    TIOStreamTransport transport = new TIOStreamTransport(bis);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);

    Assert.assertEquals(ThriftCodec.MAGIC, protocol.readI16());
    Assert.assertEquals(protocol.readI32() + 4, bos.writerIndex());
    int headerLength = protocol.readI16();

    Assert.assertEquals(ThriftCodec.VERSION, protocol.readByte());
    Assert.assertEquals(Demo.Iface.class.getName(), protocol.readString());
    Assert.assertEquals(request.getId(), protocol.readI64());

    if (bis.markSupported()) {
        bis.reset();
        bis.skip(headerLength);
    }

    TMessage message = protocol.readMessageBegin();
    Assert.assertEquals("echoString", message.name);
    Assert.assertEquals(TMessageType.EXCEPTION, message.type);
    Assert.assertEquals(ThriftCodec.getSeqId(), message.seqid);
    TApplicationException exception = TApplicationException.read(protocol);
    protocol.readMessageEnd();

    Assert.assertEquals(exceptionMessage, exception.getMessage());

}
 
开发者ID:hufeng,项目名称:dubbo2.js,代码行数:58,代码来源:ThriftCodecTest.java


注:本文中的org.apache.thrift.TApplicationException.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。