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


Java TApplicationException类代码示例

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


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

示例1: invoke

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {

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

	ClassLoader originalClassLoader = overrideThreadContextClassLoader();
	try {
		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);
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:25,代码来源:ThriftClientInterceptor.java

示例2: 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;
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:27,代码来源:TProtobufProcessor.java

示例3: 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;
  }
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:27,代码来源:LocatorServiceImpl.java

示例4: read

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
/**
 * 读取操作
 */
@Override
public void read(TProtocol iprot) throws TException {
	if (!"org.apache.thrift.scheme.StandardScheme".equals(iprot.getScheme().getName()))
		throw new TApplicationException("Service scheme must be 'org.apache.thrift.scheme.StandardScheme' !");
	TField schemeField;
	iprot.readStructBegin();
	while (Boolean.TRUE) {
		schemeField = iprot.readFieldBegin();
		if (schemeField.type == TType.STOP)
			break;
		if (schemeField.type == TType.STRING)
			str = iprot.readString();
		else
			throw new TApplicationException("field type must be 'String' !");
		iprot.readFieldEnd();
	}
	iprot.readStructEnd();
}
 
开发者ID:venwyhk,项目名称:ikasoa,代码行数:22,代码来源:AbstractThriftBase.java

示例5: handleTApplicationException

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
void handleTApplicationException(Throwable cause,
                                 Optional<StreamOp> op,
                                 SocketAddress addr,
                                 ProxyClient sc) {
    TApplicationException ex = (TApplicationException) cause;
    if (ex.getType() == TApplicationException.UNKNOWN_METHOD) {
        // if we encountered unknown method exception on thrift server, it means this proxy
        // has problem. we should remove it from routing service, clean up ownerships
        routingService.removeHost(addr, cause);
        onServerLeft(addr, sc);
        if (op.isPresent()) {
            ownershipCache.removeOwnerFromStream(op.get().stream, addr, cause.getMessage());
            doSend(op.get(), addr);
        }
    } else {
        handleException(cause, op, addr);
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:19,代码来源:DistributedLogClientImpl.java

示例6: releaseResource

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
@Override
public void releaseResource(String handle, List<Integer> idList)
  throws TException, InvalidSessionHandle, SafeModeException {
  checkSafeMode("releaseResource");
  try {
    LOG.info("Release " + idList.size() + " resources from session: " +
             handle);
    sessionManager.heartbeat(handle);
    Collection<ResourceGrant> canceledGrants =
      sessionManager.releaseResource(handle, idList);

    if (canceledGrants == null) {
      // LOG.info("No canceled grants for session " + handle);
      return;
    }

    for (ResourceGrant grant: canceledGrants) {
      nodeManager.cancelGrant(grant.nodeName, handle, grant.id);
      metrics.releaseResource(grant.type);
    }

    scheduler.notifyScheduler();
  } catch (RuntimeException e) {
    throw new TApplicationException(e.getMessage());
  }
}
 
开发者ID:rhli,项目名称:hadoop-EAR,代码行数:27,代码来源:ClusterManager.java

示例7: createTranslator

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
private MessageTransalator createTranslator(TProtocolFactory protocolFactory) {
    return new MessageTransalator(protocolFactory, new AuthTokenExchanger<AuthToken, UserData>() {
        @Override
        public AuthToken createEmptyAuthToken() {
            return new AuthToken();
        }

        @Override
        public UserData process(AuthToken authToken) throws TException {
            if ("sometoken".equals(authToken.getToken())) {
                return new UserData().setId("user1");
            }

            if ("fataltoken".equals(authToken.getToken())) {
                throw new TApplicationException(TApplicationException.INTERNAL_ERROR, "fatal!!!");
            }

            throw new UnauthorizedException("token is invalid");
        }
    });
}
 
开发者ID:aatarasoff,项目名称:thrift-api-gateway-core,代码行数:22,代码来源:MessageTranslatorTests.java

示例8: readApplicationException

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
private static TApplicationException readApplicationException(int seqId, ThriftFunction func,
                                                              TProtocol inputProtocol,
                                                              TMessage msg) throws TException {
    if (msg.seqid != seqId) {
        throw new TApplicationException(TApplicationException.BAD_SEQUENCE_ID);
    }

    if (!func.name().equals(msg.name)) {
        return new TApplicationException(TApplicationException.WRONG_METHOD_NAME, msg.name);
    }

    if (msg.type == TMessageType.EXCEPTION) {
        final TApplicationException appEx = TApplicationExceptions.read(inputProtocol);
        inputProtocol.readMessageEnd();
        return appEx;
    }

    return null;
}
 
开发者ID:line,项目名称:armeria,代码行数:20,代码来源:THttpClientDelegate.java

示例9: newObjectMapper

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
/**
 * Returns newly created {@link ObjectMapper} which is configured properly to serialize some knows classes
 * in a good way.
 */
public static ObjectMapper newObjectMapper(SimpleModule... userModules) {
    ObjectMapper objectMapper = new ObjectMapper();

    SimpleModule module = new SimpleModule();
    module.addSerializer(TMessage.class, new TMessageSerializer());
    module.addSerializer(TBase.class, new TBaseSerializer());
    module.addSerializer(TApplicationException.class, new TApplicationExceptionSerializer());
    module.addSerializer(ThriftCall.class, new ThriftCallSerializer());
    module.addSerializer(ThriftReply.class, new ThriftReplySerializer());
    objectMapper.registerModule(module);

    for (SimpleModule userModule : userModules) {
        objectMapper.registerModule(userModule);
    }

    return objectMapper;
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:ThriftStructuredLogJsonFormat.java

示例10: getResult

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
/**
 * Converts the specified {@code result} into a Java object.
 */
public Object getResult(TBase<?, ?> result) throws TException {
    for (TFieldIdEnum fieldIdEnum : exceptionFields()) {
        if (ThriftFieldAccess.isSet(result, fieldIdEnum)) {
            throw (TException) ThriftFieldAccess.get(result, fieldIdEnum);
        }
    }

    final TFieldIdEnum successField = successField();
    if (successField == null) { //void method
        return null;
    } else if (ThriftFieldAccess.isSet(result, successField)) {
        return ThriftFieldAccess.get(result, successField);
    } else {
        throw new TApplicationException(
                TApplicationException.MISSING_RESULT,
                result.getClass().getName() + '.' + successField.getFieldName());
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:ThriftFunction.java

示例11: testSync_FileService_create_exception

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
@Test
public void testSync_FileService_create_exception() throws Exception {
    FileService.Client client = new FileService.Client.Factory().getClient(inProto, outProto);
    client.send_create(BAZ);
    assertThat(out.length(), is(greaterThan(0)));

    RuntimeException exception = Exceptions.clearTrace(new RuntimeException());
    THttpService service = THttpService.of((FileService.Iface) path -> {
        throw exception;
    }, defaultSerializationFormat);

    invoke(service);

    try {
        client.recv_create();
        fail(TApplicationException.class.getSimpleName() + " not raised.");
    } catch (TApplicationException e) {
        assertThat(e.getType(), is(TApplicationException.INTERNAL_ERROR));
        assertThat(e.getMessage(), containsString(exception.toString()));
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:ThriftServiceTest.java

示例12: testAsync_FileService_create_exception

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
@Test
public void testAsync_FileService_create_exception() throws Exception {
    FileService.Client client = new FileService.Client.Factory().getClient(inProto, outProto);
    client.send_create(BAZ);
    assertThat(out.length(), is(greaterThan(0)));

    RuntimeException exception = Exceptions.clearTrace(new RuntimeException());
    THttpService service = THttpService.of(
            (FileService.AsyncIface) (path, resultHandler) ->
                    resultHandler.onError(exception), defaultSerializationFormat);

    invoke(service);

    try {
        client.recv_create();
        fail(TApplicationException.class.getSimpleName() + " not raised.");
    } catch (TApplicationException e) {
        assertThat(e.getType(), is(TApplicationException.INTERNAL_ERROR));
        assertThat(e.getMessage(), containsString(exception.toString()));
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:ThriftServiceTest.java

示例13: parse_text

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
public List<ParseTree> parse_text(String text, List<String> outputFormat) throws TApplicationException
{
    List<ParseTree> results = new ArrayList<ParseTree>();

    try
    {
        treePrinter = ParserUtil.setOptions(outputFormat, tlp);

        // assume no tokenization was done; use Stanford's default org.ets.research.nlp.stanford_thrift.tokenizer
        DocumentPreprocessor preprocess = new DocumentPreprocessor(new StringReader(text));
        Iterator<List<HasWord>> foundSentences = preprocess.iterator();
        while (foundSentences.hasNext())
        {
            Tree parseTree = parser.apply(foundSentences.next());
            results.add(new ParseTree(ParserUtil.TreeObjectToString(parseTree, treePrinter), parseTree.score()));
        }
    }
    catch (Exception e)
    {
        // FIXME
        throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.getMessage());
    }

    return results;
}
 
开发者ID:dmnapolitano,项目名称:stanford-thrift,代码行数:26,代码来源:StanfordParserThrift.java

示例14: parse_tokens

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
/**
 * @param tokens One sentence worth of tokens at a time.
 * @return A ParseTree object of the String representation of the tree, plus its probability.
 * @throws TApplicationException
 */
public ParseTree parse_tokens(List<String> tokens, List<String> outputFormat) throws TApplicationException
{
    try
    {
        treePrinter = ParserUtil.setOptions(outputFormat, tlp);

        // a single sentence worth of tokens
        String[] tokenArray = new String[tokens.size()];
        tokens.toArray(tokenArray);
        List<CoreLabel> crazyStanfordFormat = Sentence.toCoreLabelList(tokenArray);
        Tree parseTree = parser.apply(crazyStanfordFormat);
        return new ParseTree(ParserUtil.TreeObjectToString(parseTree, treePrinter), parseTree.score());
    }
    catch (Exception e)
    {
        // FIXME
        throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.getMessage());
    }
}
 
开发者ID:dmnapolitano,项目名称:stanford-thrift,代码行数:25,代码来源:StanfordParserThrift.java

示例15: parse_tagged_sentence

import org.apache.thrift.TApplicationException; //导入依赖的package包/类
public ParseTree parse_tagged_sentence(String taggedSentence, List<String> outputFormat, String divider) throws TApplicationException
{
    try
    {
        treePrinter = ParserUtil.setOptions(outputFormat, tlp);

        // a single sentence worth of tagged text, better be properly tokenized >:D
        Tree parseTree = parser.apply(CoreNLPThriftUtil.getListOfTaggedWordsFromTaggedSentence(taggedSentence, divider));
        return new ParseTree(ParserUtil.TreeObjectToString(parseTree, treePrinter), parseTree.score());
    }
    catch (Exception e)
    {
        // FIXME
        throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.getMessage());
    }
}
 
开发者ID:dmnapolitano,项目名称:stanford-thrift,代码行数:17,代码来源:StanfordParserThrift.java


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