List of usage examples for org.apache.thrift TApplicationException INTERNAL_ERROR
int INTERNAL_ERROR
To view the source code for org.apache.thrift TApplicationException INTERNAL_ERROR.
Click Source Link
From source file:com.linecorp.armeria.it.client.retry.RetryingRpcClientTest.java
License:Apache License
@Test public void execute_reachedMaxAttempts() throws Exception { final HelloService.Iface client = helloClient(retryAlways, 2); when(serviceHandler.hello(anyString())).thenThrow(new IllegalArgumentException()); final Throwable thrown = catchThrowable(() -> client.hello("hello")); assertThat(thrown).isInstanceOf(TApplicationException.class); assertThat(((TApplicationException) thrown).getType()).isEqualTo(TApplicationException.INTERNAL_ERROR); verify(serviceHandler, times(2)).hello("hello"); }
From source file:com.linecorp.armeria.it.client.retry.RetryingRpcClientTest.java
License:Apache License
@Test public void propagateLastResponseWhenNextRetryIsAfterTimeout() throws Exception { final RetryStrategy<RpcRequest, RpcResponse> strategy = (request, response) -> { final CompletableFuture<Backoff> future = new CompletableFuture<>(); response.whenComplete((unused1, unused2) -> future.complete(Backoff.fixed(10000000))); return future; };/*from ww w.jav a 2s . c om*/ final HelloService.Iface client = helloClient(strategy, 100); when(serviceHandler.hello(anyString())).thenThrow(new IllegalArgumentException()); final Throwable thrown = catchThrowable(() -> client.hello("hello")); assertThat(thrown).isInstanceOf(TApplicationException.class); assertThat(((TApplicationException) thrown).getType()).isEqualTo(TApplicationException.INTERNAL_ERROR); verify(serviceHandler, only()).hello("hello"); }
From source file:com.linecorp.armeria.server.thrift.ThriftServiceCodec.java
License:Apache License
private ByteBuf encodeException(ThriftServiceInvocationContext ctx, Throwable t) { if (t instanceof TApplicationException) { return encodeException(ctx.alloc(), ctx.method(), ctx.seqId, (TApplicationException) t); } else {//from w w w .j a v a2 s. co m return encodeException(ctx.alloc(), ctx.method(), ctx.seqId, new TApplicationException(TApplicationException.INTERNAL_ERROR, t.toString())); } }
From source file:com.linecorp.armeria.server.thrift.ThriftServiceTest.java
License:Apache License
@Test public void testSync_FileService_create_exception() throws Exception { FileService.Client client = new FileService.Client.Factory().getClient(inProto, outProto); client.send_create(BAZ);// w ww . ja v a 2s . co m 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())); } }
From source file:com.linecorp.armeria.server.thrift.ThriftServiceTest.java
License:Apache License
@Test public void testAsync_FileService_create_exception() throws Exception { FileService.Client client = new FileService.Client.Factory().getClient(inProto, outProto); client.send_create(BAZ);//from ww w. j a v a 2 s . c o m 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())); } }
From source file:com.linecorp.armeria.server.thrift.THttpService.java
License:Apache License
private static HttpData encodeException(ServiceRequestContext ctx, RpcResponse reply, SerializationFormat serializationFormat, int seqId, String methodName, Throwable cause) { final TApplicationException appException; if (cause instanceof TApplicationException) { appException = (TApplicationException) cause; } else {/*from ww w .jav a2 s . co m*/ appException = new TApplicationException(TApplicationException.INTERNAL_ERROR, "internal server error:" + System.lineSeparator() + "---- BEGIN server-side trace ----" + System.lineSeparator() + Throwables.getStackTraceAsString(cause) + "---- END server-side trace ----"); } final TMemoryBuffer buf = new TMemoryBuffer(128); final TProtocol outProto = ThriftProtocolFactories.get(serializationFormat).getProtocol(buf); try { final TMessage header = new TMessage(methodName, TMessageType.EXCEPTION, seqId); outProto.writeMessageBegin(header); appException.write(outProto); outProto.writeMessageEnd(); ctx.logBuilder().responseContent(reply, new ThriftReply(header, appException)); } catch (TException e) { throw new Error(e); // Should never reach here. } return HttpData.of(buf.getArray(), 0, buf.length()); }
From source file:org.ets.research.nlp.stanford_thrift.parser.StanfordParserThrift.java
License:Open Source License
public List<ParseTree> parse_text(String text, List<String> outputFormat) throws TApplicationException { List<ParseTree> results = new ArrayList<ParseTree>(); try {/* ww w .ja v a 2 s . c om*/ 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; }
From source file:org.ets.research.nlp.stanford_thrift.parser.StanfordParserThrift.java
License:Open Source License
/** * @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// www. j a va 2 s . co m */ 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()); } }
From source file:org.ets.research.nlp.stanford_thrift.parser.StanfordParserThrift.java
License:Open Source License
public ParseTree parse_tagged_sentence(String taggedSentence, List<String> outputFormat, String divider) throws TApplicationException { try {/*from w w w . j a va 2 s. c om*/ 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()); } }
From source file:org.ets.research.nlp.stanford_thrift.parser.StanfordParserThrift.java
License:Open Source License
/** If one were to call any of these other methods to get a parse tree for some input sentence * with the -outputFormatOptions flag of "lexicalize", they would receive their parse tree, * in the -outputFormat of their choice, with every leaf marked with it's head word. * This function does exactly that on an existing parse tree. * NOTE that this WILL re-lexicalize a pre-lexicalized tree, so don't pass in a tree that * has been lexicalized and expect to get back the same thing as what you passed in. *///from ww w. java 2 s . c o m public String lexicalize_parse_tree(String tree) throws TApplicationException { try { Tree parseTree = Tree.valueOf(tree); Tree lexicalizedTree = Trees.lexicalize(parseTree, tlp.headFinder()); treePrinter = ParserUtil.setOptions(null, tlp); // use defaults Function<Tree, Tree> a = TreeFunctions.getLabeledToDescriptiveCoreLabelTreeFunction(); lexicalizedTree = a.apply(lexicalizedTree); return ParserUtil.TreeObjectToString(lexicalizedTree, treePrinter); } catch (Exception e) { // FIXME throw new TApplicationException(TApplicationException.INTERNAL_ERROR, e.getMessage()); } }