Example usage for org.apache.thrift TApplicationException WRONG_METHOD_NAME

List of usage examples for org.apache.thrift TApplicationException WRONG_METHOD_NAME

Introduction

In this page you can find the example usage for org.apache.thrift TApplicationException WRONG_METHOD_NAME.

Prototype

int WRONG_METHOD_NAME

To view the source code for org.apache.thrift TApplicationException WRONG_METHOD_NAME.

Click Source Link

Usage

From source file:com.linecorp.armeria.client.thrift.ThriftClientCodec.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override//from  ww  w.j  ava2s . c  o m
public <T> T decodeResponse(ServiceInvocationContext ctx, ByteBuf content, Object originalResponse)
        throws Exception {
    if (content == null) {
        return null;
    }

    if (!content.isReadable()) {
        ThriftMethod thriftMethod = getThriftMethod(ctx);
        if (thriftMethod != null && thriftMethod.isOneWay()) {
            return null;
        }
        throw new TApplicationException(TApplicationException.MISSING_RESULT, ctx.toString());
    }

    TByteBufInputTransport inputTransport = new TByteBufInputTransport(content);
    TProtocol inputProtocol = protocolFactory.getProtocol(inputTransport);
    TMessage msg = inputProtocol.readMessageBegin();
    if (msg.type == TMessageType.EXCEPTION) {
        TApplicationException ex = TApplicationException.read(inputProtocol);
        inputProtocol.readMessageEnd();
        throw ex;
    }
    ThriftMethod method = methodMap.get(msg.name);
    if (method == null) {
        throw new TApplicationException(TApplicationException.WRONG_METHOD_NAME, msg.name);
    }
    TBase<? extends TBase, TFieldIdEnum> result = method.createResult();
    result.read(inputProtocol);
    inputProtocol.readMessageEnd();

    for (TFieldIdEnum fieldIdEnum : method.getExceptionFields()) {
        if (result.isSet(fieldIdEnum)) {
            throw (TException) result.getFieldValue(fieldIdEnum);
        }
    }

    TFieldIdEnum successField = method.successField();
    if (successField == null) { //void method
        return null;
    }
    if (result.isSet(successField)) {
        return (T) result.getFieldValue(successField);
    }

    throw new TApplicationException(TApplicationException.MISSING_RESULT,
            result.getClass().getName() + '.' + successField.getFieldName());
}

From source file:com.linecorp.armeria.client.thrift.ThriftClientDelegate.java

License:Apache License

private Object decodeResponse(ThriftFunction method, HttpData content) throws TException {
    if (content.isEmpty()) {
        if (method.isOneway()) {
            return null;
        }//  w w w.j  a va 2 s .c om
        throw new TApplicationException(TApplicationException.MISSING_RESULT);
    }

    final TMemoryInputTransport inputTransport = new TMemoryInputTransport(content.array(), content.offset(),
            content.length());
    final TProtocol inputProtocol = protocolFactory.getProtocol(inputTransport);

    final TMessage msg = inputProtocol.readMessageBegin();
    if (msg.type == TMessageType.EXCEPTION) {
        TApplicationException ex = TApplicationException.read(inputProtocol);
        inputProtocol.readMessageEnd();
        throw ex;
    }

    if (!method.name().equals(msg.name)) {
        throw new TApplicationException(TApplicationException.WRONG_METHOD_NAME, msg.name);
    }
    TBase<? extends TBase<?, ?>, TFieldIdEnum> result = method.newResult();
    result.read(inputProtocol);
    inputProtocol.readMessageEnd();

    for (TFieldIdEnum fieldIdEnum : method.exceptionFields()) {
        if (result.isSet(fieldIdEnum)) {
            throw (TException) result.getFieldValue(fieldIdEnum);
        }
    }

    TFieldIdEnum successField = method.successField();
    if (successField == null) { // void method
        return null;
    }
    if (result.isSet(successField)) {
        return result.getFieldValue(successField);
    }

    throw new TApplicationException(TApplicationException.MISSING_RESULT,
            result.getClass().getName() + '.' + successField.getFieldName());
}

From source file:com.linecorp.armeria.client.thrift.THttpClientDelegate.java

License:Apache License

private static TApplicationException readApplicationException(ThriftFunction func, TProtocol inputProtocol,
        TMessage msg) throws TException {
    final TApplicationException appEx;
    if (msg.type == TMessageType.EXCEPTION) {
        appEx = TApplicationException.read(inputProtocol);
        inputProtocol.readMessageEnd();// w  w  w . j  av  a 2 s. c  o m
    } else if (!func.name().equals(msg.name)) {
        appEx = new TApplicationException(TApplicationException.WRONG_METHOD_NAME, msg.name);
    } else {
        appEx = null;
    }
    return appEx;
}

From source file:org.apache.hadoop.hive.metastore.HiveMetaStoreClientPreCatalog.java

License:Apache License

@Override
public boolean listPartitionsByExpr(String db_name, String tbl_name, byte[] expr, String default_partition_name,
        short max_parts, List<Partition> result) throws TException {
    assert result != null;
    PartitionsByExprRequest req = new PartitionsByExprRequest(db_name, tbl_name, ByteBuffer.wrap(expr));
    if (default_partition_name != null) {
        req.setDefaultPartitionName(default_partition_name);
    }/*www . ja va  2  s .co  m*/
    if (max_parts >= 0) {
        req.setMaxParts(max_parts);
    }
    PartitionsByExprResult r;
    try {
        r = client.get_partitions_by_expr(req);
    } catch (TApplicationException te) {
        // TODO: backward compat for Hive <= 0.12. Can be removed later.
        if (te.getType() != TApplicationException.UNKNOWN_METHOD
                && te.getType() != TApplicationException.WRONG_METHOD_NAME) {
            throw te;
        }
        throw new IncompatibleMetastoreException(
                "Metastore doesn't support listPartitionsByExpr: " + te.getMessage());
    }
    if (fastpath) {
        result.addAll(r.getPartitions());
    } else {
        r.setPartitions(filterHook.filterPartitions(r.getPartitions()));
        // TODO: in these methods, do we really need to deepcopy?
        deepCopyPartitions(r.getPartitions(), result);
    }
    return !r.isSetHasUnknownPartitions() || r.isHasUnknownPartitions(); // Assume the worst.
}