Java界面:
public interface IUserSettingManager {
UserSettingApi updateSetting(Long userId, UserSetting userSettingNew) throws FailUpdateUserSettingException;
}
Kotlin ejb:
@Stateless
@Local(IUserSettingManager::class)
open class UserSettingManager : DataManager(), IUserSettingManager {
private companion object {
private val LOG = LoggerFactory.getLogger(UserSettingManager::class.java)
}
@Throws(FailUpdateUserSettingException::class)
private fun validate(userSetting: UserSetting) {
if (userSetting.avatar?.length ?: 0 > DBConstant.UUID_VARCHAR_SIZE) {
throw FailUpdateUserSettingException("avatar length")
}
}
@Throws(FailUpdateUserSettingException::class)
override fun updateSetting(userId: Long, userSettingNew: UserSetting): UserSettingApi {
val logger = LOG.silentEnter("updateSetting")
try {
validate(userSettingNew)
.....
} catch (ex: Exception) {
val msg = "userId:$userId, user setting:$userSettingNew"
when (ex) {
is FailUpdateUserSettingException -> {
logger.debug("$msg, ex:$ex")
throw ex
}
else -> {
logger.error(msg, ex)
throw FailUpdateUserSettingException(ex.toString())
}
}
}
}
}
带有例外的Java类:
公共类FailUpdateUserSettingException扩展Exception {
public FailUpdateUserSettingException() {
this(error);
}
}
当尝试使用不正确的数据调用ejb时,获取异常UndeclaredThrowableException,并结果事务已滚动
Caused by: java.lang.reflect.UndeclaredThrowableException
at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:34)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:52)
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.component.interceptors.NonPooledEJBComponentInstanceAssociatingInterceptor.processInvocation(NonPooledEJBComponentInstanceAssociatingInterceptor.java:59) [wildfly-ejb3-10.0.0.Final.jar:10.0.0.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:254) [wildfly-ejb3-10.0.0.Final.jar:10.0.0.Final]
... 137 more
Caused by: com.pay.utils.shared.exception.user.FailUpdateUserSettingException: Fail update user setting. avatar length
at com.pay.manager.UserSettingManager.validate(UserSettingManager.kt:xx)
at com.pay.manager.UserSettingManager.updateSetting(UserSettingManager.kt:xx)
at com.pay.manager.UserSettingManager.updateSetting(UserSettingManager.kt:xx)
.....
结果
javax.ejb.EJBTransactionRolledbackException
答案 0 :(得分:0)
我没有看到任何远程方法调用或任何序列化,这是这类问题的常见原因,但它可能是类加载器问题吗? Kotlin代码实例化的类是从不同的类加载器加载的,而不是JBoss检查的类,因此它被视为无法识别的throwable?
我不确定如何检查。 EJB容器中的类加载器策略也许 - 父对象与父对等?
如果将Kotlin代码替换为始终只是从私有validate()方法抛出该异常的Java版本,那么行为是什么,只是为了看看是否会产生影响?
您使用什么JDK版本,Kotlin版本以及JBoss版本?