创建远程连接失败引起:java.lang.RuntimeException:操作失败,状态为WAITING

时间:2016-01-20 06:01:41

标签: java jboss jndi ejb-3.1

无法创建远程连接。请看控制台。  javax.naming.NamingException:无法创建远程连接[根异常是java.lang.RuntimeException:操作失败,状态为WAITING]

package com.as.service;

import javax.ejb.Remote;

@Remote
public interface CalculetteService {
   int add(int a, int b);
}


package com.fpt.service;
import javax.ejb.Stateless;
import org.jboss.logging.Logger;


@Stateless
public class CalculetteServiceImpl implements CalculetteService{

  private Logger log = Logger.getLogger(CalculetteServiceImpl.class);

  @Override
  public int add(int a, int b) {
    return a + b;
  }
}


package com.as.test;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.as.service.CalculetteService;
import com.as.service.CalculetteServiceImpl;

public class Test {


public static void main(String[] args) {

    CalculetteService calculette = null;

    try {

        Properties properties = new Properties();
        properties.setProperty("java.naming.factory.url.pkgs",    "org.jboss.ejb.client.naming");
        properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        properties.setProperty("java.naming.provider.url","remote://localhost:4447");
        properties.setProperty("jboss.naming.client.ejb.context", "true");
        properties.setProperty("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");


        Context context = new InitialContext(properties);


        calculette =  (CalculetteService)context.lookup("calculetteService#com.fpt.service.CalculetteService");
        System.out.println("La somme est:"+calculette.add(10, 10));
    } catch (NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
}

0 个答案:

没有答案