Example usage for org.apache.thrift TApplicationException MISSING_RESULT

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

Introduction

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

Prototype

int MISSING_RESULT

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

Click Source Link

Usage

From source file:com.facebook.swift.service.ThriftMethodHandler.java

License:Apache License

private Object readResponse(TProtocol in) throws Exception {
    TProtocolReader reader = new TProtocolReader(in);
    reader.readStructBegin();//from w ww . j  av  a2  s .c  o  m
    Object results = null;
    Exception exception = null;
    while (reader.nextField()) {
        if (reader.getFieldId() == 0) {
            results = reader.readField(successCodec);
        } else {
            ThriftCodec<Object> exceptionCodec = exceptionCodecs.get(reader.getFieldId());
            if (exceptionCodec != null) {
                exception = (Exception) reader.readField(exceptionCodec);
            } else {
                reader.skipFieldData();
            }
        }
    }
    reader.readStructEnd();
    in.readMessageEnd();

    if (exception != null) {
        throw exception;
    }

    if (successCodec.getType() == ThriftType.VOID) {
        // TODO: check for non-null return from a void function?
        return null;
    }

    if (results == null) {
        throw new TApplicationException(TApplicationException.MISSING_RESULT, name + " failed: unknown result");
    }
    return results;
}

From source file:com.funtl.framework.rpc.thrift.spring.ThriftClientInterceptor.java

License:Apache License

@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {

    Object thriftProxy = ThriftUtil.buildClient(getServiceInterface(),
            protocolFactory.getProtocol(getTransport()));

    ClassLoader originalClassLoader = overrideThreadContextClassLoader();
    try {/*from w w  w  . j  a v  a  2s  .c om*/
        return methodInvocation.getMethod().invoke(thriftProxy, methodInvocation.getArguments());
    } catch (InvocationTargetException e) {
        Throwable targetEx = e.getTargetException();
        if (targetEx instanceof InvocationTargetException) {
            targetEx = ((InvocationTargetException) targetEx).getTargetException();
        }
        if (targetEx instanceof TApplicationException
                && ((TApplicationException) targetEx).getType() == TApplicationException.MISSING_RESULT) {
            return null;
        } else {
            throw targetEx;
        }
    } catch (Throwable ex) {
        throw new RemoteProxyFailureException(
                "Failed to invoke Thrift proxy for remote service [" + getServiceUrl() + "]", ex);
    } finally {
        resetThreadContextClassLoader(originalClassLoader);
    }
}

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

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*w w  w  . java  2s . c  om*/
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 v  a  2 s  .  c  o  m
        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 void handle(ClientRequestContext ctx, DefaultRpcResponse reply, ThriftFunction func, HttpData content)
        throws TException {

    if (func.isOneWay()) {
        handleSuccess(ctx, reply, null, null);
        return;/*w w  w  . j a  va 2  s  .co  m*/
    }

    if (content.isEmpty()) {
        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 header = inputProtocol.readMessageBegin();
    final TApplicationException appEx = readApplicationException(func, inputProtocol, header);
    if (appEx != null) {
        handleException(ctx, reply, new ThriftReply(header, appEx), appEx);
        return;
    }

    TBase<? extends TBase<?, ?>, TFieldIdEnum> result = func.newResult();
    result.read(inputProtocol);
    inputProtocol.readMessageEnd();

    final ThriftReply rawResponseContent = new ThriftReply(header, result);

    for (TFieldIdEnum fieldIdEnum : func.exceptionFields()) {
        if (result.isSet(fieldIdEnum)) {
            final TException cause = (TException) ThriftFieldAccess.get(result, fieldIdEnum);
            handleException(ctx, reply, rawResponseContent, cause);
            return;
        }
    }

    final TFieldIdEnum successField = func.successField();
    if (successField == null) { // void method
        handleSuccess(ctx, reply, null, rawResponseContent);
        return;
    }

    if (result.isSet(successField)) {
        final Object returnValue = ThriftFieldAccess.get(result, successField);
        handleSuccess(ctx, reply, returnValue, rawResponseContent);
        return;
    }

    handleException(ctx, reply, rawResponseContent,
            new TApplicationException(TApplicationException.MISSING_RESULT,
                    result.getClass().getName() + '.' + successField.getFieldName()));
}

From source file:com.linecorp.armeria.internal.thrift.ThriftFunction.java

License:Apache License

/**
 * Converts the specified {@code result} into a Java object.
 *///from   w  w  w. j  a va2s  . co m
public Object getResult(TBase<TBase<?, ?>, TFieldIdEnum> result) throws TException {
    for (TFieldIdEnum fieldIdEnum : exceptionFields()) {
        if (result.isSet(fieldIdEnum)) {
            throw (TException) ThriftFieldAccess.get(result, fieldIdEnum);
        }
    }

    final TFieldIdEnum successField = successField();
    if (successField == null) { //void method
        return null;
    } else if (result.isSet(successField)) {
        return ThriftFieldAccess.get(result, successField);
    } else {
        throw new TApplicationException(TApplicationException.MISSING_RESULT,
                result.getClass().getName() + '.' + successField.getFieldName());
    }
}