1

我是 JBoss 世界的新手,目前正在开发我的第一个程序。因此,如果我的问题是微不足道的,请提前原谅。但是我仍然不知道答案(已经在 J​​Boss 社区和 Coderanch 中询问过),所以如果有人能给我任何建议,我将不胜感激。

挑战在于异步运行 EJB 方法以进一步检索某些信息或停止。

我正在使用 JBoss AS 5.0 版,Eclipse JUNO(插件 3.8.2-4.2.2 )

我正在使用从 ejb31-api-experimental-3.1.4.jar 库中获取的 AsyncResult 类。我在服务器上的业务逻辑似乎工作得很好,但是当结果要返回到客户端应用程序时,我收到一个异常:

我的 EJB 示例代码是:

    package org.braman.apps.demo.ejb;  
    import javax.ejb.Stateless;  
    import java.net.*;  
    import java.io.*;  
    import java.util.*;  
    import java.util.concurrent.Future;  
    import javax.ejb.*;  
    import javax.ejb.Asynchronous;  
    import javax.ejb.AsyncResult;  
    import java.io.Serializable;  

    @Stateless  
    @Remote  
    @Asynchronous  
    public class DemoStatelessBean implements DemoStatelessRemote, Serializable {  

        @Override  
        @Asynchronous  
        public Future<String> tn_mainloop() {  

             // my business logic here  

                 return new AsyncResult<String>("HELLO");               
        }  
    }  


Remote interface is:

       package org.braman.apps.demo.ejb;  
        import javax.ejb.Remote;  
        import java.util.concurrent.Future;  
        import javax.ejb.*;  

        @Remote  
        public interface DemoStatelessRemote {  
             public String getDemoWord();  
             @Asynchronous  
             public Future<String> tn_mainloop();  

        }  

客户端应用程序是

   public class DemoStatelessClient implements Serializable {  
    /** 
     *  
     */  
    private static final long serialVersionUID = 1L;  

    public static void main(String[] args) throws Exception  
    {  

     Context context;  

  Properties properties = new Properties();                              properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");  
    properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");  

        properties.put("java.naming.provider.url","localhost:1099");  
        context = new InitialContext(properties);     

        DemoStatelessRemote simpleSession  
       = (DemoStatelessRemote) context.lookup("DemoStatelessBean/remote");  

        System.out.printf(">> %s\n", DemoStatelessRemote.class.getName());  


    try {  
        //Future<String> fut=simpleSession.tn_mainloop();  

        final Future<String> str = simpleSession.tn_mainloop();  
        str.get();  

        } catch (InterruptedException e) {  

            e.printStackTrace();  
        } catch (ExecutionException e) {  

            e.printStackTrace();  
        } catch (EJBException ejbe) {  
            ejbe.printStackTrace();  
        }  

        }  
    }  

该方法本身运行良好(在 JBoss 控制台中一切正常,并且运行正常)。但是在将结果返回给客户端时发生错误。如果有人可以提供帮助将不胜感激。看过互联网,但我想出的唯一解决方案是关于“可序列化”接口的实现。但是 AsyncResult 是一个提供的类。包含AsyncResult 的jar 是ejb31-api-experimental-3.1.4.jar 已经在网上找到了。请帮忙。提前致谢/

日志:

Caused by: org.jboss.remoting.InvocationFailureException: Unable to perform invocation; nested exception is:   
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: javax.ejb.AsyncResult  
    at org.jboss.remoting.transport.socket.SocketClientInvoker.handleException(SocketClientInvoker.java:139)

    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:886)

    at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:160)

    at org.jboss.remoting.Client.invoke(Client.java:1708)  
    at org.jboss.remoting.Client.invoke(Client.java:612)  
    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:76)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)  
    at $Proxy4.invoke(Unknown Source)  
    at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:125)

    ... 2 more  
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: javax.ejb.AsyncResult  
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)  
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)  
    at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:119)

    at java.io.ObjectInputStream.readExternalData(ObjectInputStream.java:1810)

    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1769)

    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)  
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1964)

    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1888) 

    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)

    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)  
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)  
    at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:238)

    at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:138)

    at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:123)

    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:1215)

    at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:845)

    at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:160)

    at org.jboss.remoting.Client.invoke(Client.java:1708)  
    at org.jboss.remoting.Client.invoke(Client.java:612)  
    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:60)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.ejb3.security.client.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:65)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:76)

    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102)

    at org.jboss.aspects.remoting.PojiProxy.invoke(PojiProxy.java:62)  
    at $Proxy4.invoke(Unknown Source)  
    at org.jboss.ejb3.proxy.handler.session.SessionSpecProxyInvocationHandlerBase.invoke(SessionSpecProxyInvocationHandlerBase.java:125)

    at $Proxy3.tn_mainloop(Unknown Source)  
    at org.braman.apps.demo.ejb.DemoStatelessClient.main(DemoStatelessClient.java:59)

    at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:72)

    ... 12 more  
Caused by: java.io.NotSerializableException: javax.ejb.AsyncResult  
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1173) 

    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)  
    at org.jboss.aop.joinpoint.InvocationResponse.writeExternal(InvocationResponse.java:100)

    at java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1438)

    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1407)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1167) 

    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1526)

    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1491)

    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1409)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1167) 

    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)  
    at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.sendObjectVersion2_2(JavaSerializationManager.java:120)

    at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.sendObject(JavaSerializationManager.java:95)

    at org.jboss.remoting.marshal.serializable.SerializableMarshaller.write(SerializableMarshaller.java:120)

    at org.jboss.remoting.transport.socket.ServerThread.versionedWrite(ServerThread.java:998)

    at org.jboss.remoting.transport.socket.ServerThread.completeInvocation(ServerThread.java:781)

    at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:695)

    at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:522)

    at org.jboss.remoting.transport.socket.ServerThrea

d.run(ServerThread.java:230)

4

1 回答 1

0

好吧,您使用的是非常旧的 JBoss AS 版本,其中不支持 @Asynchronous(@Asynchronous 是在 Java EE 6 中添加的,从 JBoss AS 7.x 开始支持)。

为避免将来出现此问题,您可以(在 Eclipse 中)将来自本地 JBoss 的 jar 文件添加到您的项目构建路径中,以查看支持的内容。

于 2013-09-20T13:56:52.193 回答