本文整理汇总了Scala中org.apache.thrift.TException类的典型用法代码示例。如果您正苦于以下问题:Scala TException类的具体用法?Scala TException怎么用?Scala TException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: UncaughtAppExceptionFilter
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift
import com.twitter.finagle.{Service, SimpleFilter}
import com.twitter.io.Buf
import com.twitter.util.Future
import org.apache.thrift.{TApplicationException, TException}
import org.apache.thrift.protocol.{TMessage, TMessageType, TProtocolFactory}
private[finagle] object UncaughtAppExceptionFilter {
def writeExceptionMessage(
thriftRequest: Buf,
throwable: Throwable,
protocolFactory: TProtocolFactory
): Buf = {
val reqBytes = Buf.ByteArray.Owned.extract(thriftRequest)
// NB! This is technically incorrect for one-way calls,
// but we have no way of knowing it here. We may
// consider simply not supporting one-way calls at all.
val msg = InputBuffer.readMessageBegin(reqBytes, protocolFactory)
val name = msg.name
val buffer = new OutputBuffer(protocolFactory)
buffer().writeMessageBegin(
new TMessage(name, TMessageType.EXCEPTION, msg.seqid))
// Note: The wire contents of the exception message differ from Apache's Thrift in that here,
// e.toString is appended to the error message.
val x = new TApplicationException(
TApplicationException.INTERNAL_ERROR,
s"Internal error processing $name: '$throwable'")
x.write(buffer())
buffer().writeMessageEnd()
Buf.ByteArray.Owned(buffer.toArray)
}
}
private[finagle] class UncaughtAppExceptionFilter(protocolFactory: TProtocolFactory)
extends SimpleFilter[Array[Byte], Array[Byte]]
{
import UncaughtAppExceptionFilter.writeExceptionMessage
def apply(
request: Array[Byte],
service: Service[Array[Byte], Array[Byte]]
): Future[Array[Byte]] =
service(request).handle {
case e if !e.isInstanceOf[TException] =>
val buf = Buf.ByteArray.Owned(request)
val msg = writeExceptionMessage(buf, e, protocolFactory)
Buf.ByteArray.Owned.extract(msg)
}
}
开发者ID:wenkeyang,项目名称:finagle,代码行数:57,代码来源:UncaughtAppExceptionFilter.scala
注:本文中的org.apache.thrift.TException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论