无法创建远程连接[根异常是java.lang.RuntimeException:操作失败,状态为WAITING]

时间:2013-12-25 10:43:10

标签: java ejb jboss7.x

我创建了两个项目:服务器端和客户端。我通过部署服务器端获得了成功,但我无法从客户端连接到它。这是我的代码:

RemoteCalculator.java:

package com.calculator;
import javax.ejb.Remote;

@Remote
public interface RemoteCalculator {
    int add( int op1, int op2 );
}

CalculatorBean.java:

package com.calculator;
import javax.ejb.Stateless;

@Stateless
public class CalculatorBean implements RemoteCalculator {
    @Override
    public int add( int op1, int op2 ) {
        return op1 + op2;
    }
}

我用maven组装了它。在这里,我向您展示调用部分:

EJB_Client.java:

public class EJBClient {
    private static void invokeStatelessBean() throws NamingException {
        RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator();
        int sum = statelessRemoteCalculator.add( 3, 4 );
        System.out.println( "sum = " + sum );
    }

    private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException {
        Security.addProvider( new JBossSaslProvider() );
        final Hashtable<String, String> p = new Hashtable<String, String>();
        p.put( Context.PROVIDER_URL, "remote://127.0.0.1:1099" );
        p.put( Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming" );
        p.put( Context.SECURITY_PRINCIPAL, "admin" );
        p.put( Context.SECURITY_CREDENTIALS, "jboss" );
        final Context context = new InitialContext( p );

        return ( RemoteCalculator ) context
            .lookup( "java:/ejb-remote-stateless-1.0-SNAPSHOT/CalculatorBean!com.calculator.RemoteCalculator" );
}

    public static void main( String... args ) throws NamingException {
        invokeStatelessBean();
    }
}

在运行main方法时,我得到了这个日志:

Exception in thread "main" javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: Operation failed with status WAITING]
    at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
    at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
    at javax.naming.InitialContext.init(InitialContext.java:242)
    at javax.naming.InitialContext.<init>(InitialContext.java:216)
    at Main.lookupRemoteStatelessCalculator(Main.java:31)
    at Main.main(Main.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.lang.RuntimeException: Operation failed with status WAITING
    at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:89)
    at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
    at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)
    at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)
    at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
    ... 11 more

请告诉我,出了什么问题?

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题,为我解决的问题是将用户添加到&#34; application-roles.properties&#34;文件。