如何使EJB3远程接口对客户端可用? [英] How to make EJB3 remote interface available to client?

查看:100
本文介绍了如何使EJB3远程接口对客户端可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从客户端访问远程EJB3 bean,该客户端使用JNDI查找在单独的JVM上运行.以下是我的bean类:

I am trying to access a remote EJB3 bean from a client which runs on a separate JVM using JNDI lookup. Following are my bean classes:

@Path("/payment/")
@Consumes({ "application/xml", "application/json" })
@Produces({ "application/xml", "application/json" })
@Local({ PaymentWebServiceLocal.class })
@Remote({ PaymentWebServiceRemote.class })
@Stateless(mappedName = "ejb/PaymentWebService")
public class PaymentWebServiceImpl implements PaymentWebServiceLocal,PaymentWebServiceRemote {

private static final Logger logger = Logger.getLogger(PaymentWebServiceImpl.class);


@POST
@Path("/processpayment")
public PaymentResponse processPayment(PaymentRequest request) {
   //do something
}

Bean的远程接口如下

The remote interface of the Bean is as follows

@Remote
public interface PaymentWebServiceRemote {
    public PaymentResponse processPayment(PaymentRequest request);
}

现在,我使用JNDI查找EJB,如下所示从远程客户端调用processPayment()方法

Now, I lookup the EJB using JNDI to invoke the processPayment() method from the remote client as follows

    Hashtable env = new Hashtable();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
    env.put(Context.PROVIDER_URL, t3:\\);
    Context ctx = new InitialContext(env);
    return ctx.lookup("ejb.PaymentWebService#test.webservice.payment.service.PaymentWebServiceRemote");

我不了解的是,客户端不了解远程PaymentWebServiceRemote接口.它位于具有EJB Bean代码的另一台服务器中.我是否还必须将此接口的副本复制到客户端代码?还是有某种方法可以创建带有远程接口的客户端EJB jar,以供客户端在EJB3中使用(就像我们在EJB2中一样)?

What I don't understand is that the client do not know about the remote PaymentWebServiceRemote interface. It is in another server with the EJB Bean code. Do I have to take a copy of this interface to client code as well? Or is there some way of creating a client EJB jar with the remote interface for client to use in EJB3 (like we did in EJB2)?

感谢您的帮助.

推荐答案

您必须创建一个客户端jar,其中包含所有必要的接口以及 可能传递给接口方法的参数类.

You have to create a client jar which contains all necessary interfaces and also the parameter classes which might be passed to the methods of the interface.

在您的示例中,您需要输入

In your example you need to put

  • VoidRemittanceService
  • VoidRemittanceServiceRemote
  • PaymentResponse

进入客户端jar.

客户端jar中不需要远程接口的实现类.

The implementing classes of the remote interfaces are not necessary within the client jar.

当然,您也可以复制一个副本并将其放入客户端项目中.但是这个 这不是一个好习惯,因为您必须始终两次更改界面. 另外,您必须确保客户端接口使用与服务器jar相同的JRE版本进行编译.否则可能会有问题.

Of course you can also make a copy and put them into the client project. But this is not good practice since you have to make changes of the interface always twice. Additionally you must be sure that the client interfaces are compiled with the same JRE Version as the server jar. Else there could be problems.

优良作法是创建一个其他项目,其中包含服务器和客户端将使用的共享代码方式.服务器项目和客户端项目可以引用该项目.这样,共享代码的更改将直接影响服务器和客户端.

Good practice is to create an additional project which contains shared code means which will be used by server and client. This project can be referenced by the server project and the client project. In this way changes of the shared code influence directly the server and the client side.

这篇关于如何使EJB3远程接口对客户端可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆