我是JBoss世界的新手,目前正致力于我的第一个项目。因此,如果我的问题很简单,请提前赦免。但是我仍然不知道答案(已经在JBoss社区和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控制台中,everthying是可以的,它确实运行正常)。但是在将结果返回给客户端期间会发生错误。 如果有人可以提供帮助,将不胜感激。 看过互联网,但我发现的唯一解决方案是关于“Serializable”界面的实现。但AsyncResult是一个提供的类。 包含AsyncResult的jar是ejb31-api-experimental-3.1.4.jar已在Internet上找到。请帮忙。 提前谢谢/
日志:
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)
答案 0 :(得分:0)
好吧,你使用的是旧版本的JBoss AS,其中不支持@Asynchronous(在Java EE 6中添加了@Asynchronous,从JBoss AS 7.x开始支持)。
为了避免将来出现此问题,您可以(在Eclipse中)从本地JBoss向项目构建路径添加jar文件,以便查看支持的内容。