0

我正在从一个独立的 Java 程序(使用 jnp 查找)调用部署在我的 jBoss 4.2.3 服务器中的 EJB3 服务。我已将所有数据对象序列化。我已经成功调用了我的 EJB 的方法,但是我正在从客户端的对象中丢失数据。我在 Application Server 中调试了 EJB 端,我可以看到我的对象中有数据。

我正在使用以下代码调用我的 EJB;

public void doStuff () {

    // Component and its JNDI
    ResourceProviderServiceBeanRemote componentEJB;
    String JNDI_NAME_REMOTE = "ResourceProviderService/ResourceProviderServiceBean/remote";

    // Setup Environment
    Hashtable environment = new Hashtable();
    environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
    environment.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099"); // remote machine IP
    Context context = null;
    try {
        context = new InitialContext(environment);
        Object factoryObj = context.lookup(JNDI_NAME_REMOTE); //ejb-name
        componentEJB = (ResourceProviderServiceBeanRemote) factoryObj;

        UserContextCallBack userContext = new UserContextCallBackImpl(new UserDetails("username", "password", ""));
        componentEJB.setUserContextCallBack(userContext);

        QueryDetails query = new QueryDetails();
        query.setName("anything");
        List<String> cols = new ArrayList<String>();
        List<Row> rows = new ArrayList<Row>();
        ResponseDetails responseDetails = new ResponseDetails();
        componentEJB.doQuery(query, cols, rows, responseDetails);
        System.out.println(responseDetails);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

注意:我可以在服务器端看到填充在“cols”、“rows”和“responseDetails”中的数据,但客户端仍然是相同的空初始化对象。

我错过了什么吗?

--

SJunejo

4

1 回答 1

0

这是一个愚蠢的错误,我发现在任何 RMI 接口上调用方法时,所有对象都是按值传递的。我必须有一些返回类型,这就是它所缺少的。所以我将我的代码升级如下;

// Created a new Response Object by combing all the OUT parameters as one object
// and updated the method on EJB to accept only IN paramters
DoQueryResponse response = componentEJB.doQuery(query);

希望这会帮助像我这样的人(愚蠢):)

于 2012-12-20T13:12:15.187 回答