wildfly 11抛出异常到远程客户端

时间:2018-05-21 09:35:23

标签: exception wildfly

我写信给maven-projects部署到wildfly 11。 我尝试向远程ejb客户端抛出异常,但我总是得到另一个异常(不是抛出的异常)。 我想在客户端捕获特定的自己编写的异常(例如NotLoggedInException)

以下最小示例只会抛出超类Exception(当我不抛出异常时,一切都按预期工作,因此例如pom中没有丢失的依赖项):

接口:

package de.fhac.ks.ss18;

import javax.ejb.Remote;

@Remote
public interface ExceptionToClientBeanRemote {

    void foo() throws Exception;

}

豆:

package de.fhac.ks.ss18;

import javax.ejb.Stateless;

@Stateless
public class ExceptionToClientBean implements ExceptionToClientBeanRemote {

    @Override
    public void foo() throws Exception {
        System.out.println("foo");
        throw new Exception();
    }


}

客户端:

package de.fhac.ks.ss18;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Client {

    private static <T> T lookup(String uri, Class<T> cl) throws NamingException {
        final Hashtable<String, String> jndiProperties = new Hashtable<>();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
        jndiProperties.put(Context.PROVIDER_URL, "remote+http://localhost:8080");
        final Context context = new InitialContext(jndiProperties);
        return cl.cast(context.lookup(uri));
    }

    public static void main(String[] args) {
        ExceptionToClientBeanRemote exceptionToClientBean = null;
        try {
            String uri = "ejb:/ExceptionToClient-ejb/ExceptionToClientBean!de.fhac.ks.ss18.ExceptionToClientBeanRemote";
            exceptionToClientBean = lookup(uri, ExceptionToClientBeanRemote.class);
        } catch (NamingException e) {
            e.printStackTrace();
        }
        try {
            exceptionToClientBean.foo();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
我得到了Stacktrace:

Mai 21, 2018 11:27:33 AM org.wildfly.naming.client.Version <clinit>
INFO: WildFly Naming version 1.0.1.Final
Mai 21, 2018 11:27:33 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.5.1.Final
Mai 21, 2018 11:27:33 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.5.1.Final
Mai 21, 2018 11:27:33 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 5.0.0.Final
Mai 21, 2018 11:27:33 AM org.wildfly.security.Version <clinit>
INFO: ELY00001: WildFly Elytron version 1.1.1.Final
Mai 21, 2018 11:27:33 AM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 4.0.0.Final
javax.ejb.EJBException: Failed to read response
    at org.jboss.ejb.protocol.remote.EJBClientChannel$MethodInvocation$ExceptionResultProducer.getResult(EJBClientChannel.java:1201)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:570)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:507)
    at org.jboss.ejb.protocol.remote.RemotingEJBClientInterceptor.handleInvocationResult(RemotingEJBClientInterceptor.java:56)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:572)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:507)
    at org.jboss.ejb.client.DiscoveryEJBClientInterceptor.handleInvocationResult(DiscoveryEJBClientInterceptor.java:98)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:572)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:507)
    at org.jboss.ejb.client.NamingEJBClientInterceptor.handleInvocationResult(NamingEJBClientInterceptor.java:49)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:572)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:507)
    at org.jboss.ejb.client.TransactionInterceptor.handleInvocationResult(TransactionInterceptor.java:86)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:572)
    at org.jboss.ejb.client.EJBClientInvocationContext.getResult(EJBClientInvocationContext.java:507)
    at org.jboss.ejb.client.EJBClientInvocationContext.awaitResponse(EJBClientInvocationContext.java:929)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:174)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:107)
    at com.sun.proxy.$Proxy2.foo(Unknown Source)
    at de.fhac.ks.ss18.Client.main(Client.java:28)
Caused by: java.io.InvalidObjectException: ObjectTable org.jboss.ejb.protocol.remote.ProtocolV3ObjectTable cannot find an object for object index 97
    at org.jboss.ejb.protocol.remote.ProtocolV3ObjectTable.readObject(ProtocolV3ObjectTable.java:222)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:353)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:208)
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:76)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:1036)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadArray(RiverUnmarshaller.java:1702)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:328)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:223)
    at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1856)
    at org.jboss.marshalling.river.RiverObjectInputStream.defaultReadObject(RiverObjectInputStream.java:81)
    at java.lang.Throwable.readObject(Throwable.java:914)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.marshalling.reflect.SerializableClass.callReadObject(SerializableClass.java:317)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1748)
    at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1717)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1397)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:275)
    at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:208)
    at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:76)
    at org.jboss.ejb.protocol.remote.EJBClientChannel$MethodInvocation$ExceptionResultProducer.getResult(EJBClientChannel.java:1189)
    ... 19 more
Caused by: an exception which occurred:
    in field java.lang.Throwable.suppressedExceptions
    in object java.lang.Exception@5ad851c9
    in object of type java.lang.Exception

有人可以帮忙吗?

谢谢, 杰戈

0 个答案:

没有答案