Kotlin EJB with Java Interface throw UndeclaredThrowableExce



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 类:

public class FailUpdateUserSettingException extensions 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

我没有看到任何远程方法调用或任何序列化,这是此类问题的常见原因,但这可能是类加载器问题吗?当由 Kotlin 代码实例化时,类是从不同的类加载器加载的,而不是 JBoss 检查的类,因此它被视为无法识别的可抛掷对象?

我不知道如何检查。EJB 容器中的类加载器策略也许 - 父级优先与父级最后?

如果您将 Kotlin 代码替换为 Java 版本,该版本总是从私有 validate(( 方法中抛出该异常,只是为了看看这是否有区别,那会是什么行为?

你使用什么 JDK 版本、什么 Kotlin 版本和什么 JBoss 版本?

最新更新