我所要做的应该是非常直截了当的,但到目前为止是不可能的。有人能告诉我如何从公开的RESTeasy接口访问@Local吗?我已经搜索了互联网的长度和宽度,我所能找到的只有同一个例子的变化。
我试图了解如何使用RESTeasy以正常方式访问会话bean。到目前为止,情况就是这样:
使用:
EJB 3
RESTeasy 2.1
已发布的EJB接口:
@Local
@Path("RequestReport")
public interface EReport {
@GET
@Produces({"application/xml"})
@Path("request")
public String requestReport(@QueryParam("reportId") @DefaultValue("") String reportId,
@QueryParam("reportName") @DefaultValue("") String reportName,
@QueryParam("reportType") @DefaultValue("") String reportType);
}
}BEAN 1:
@Stateless
public class EReportRequest implements EReport {
@EJB
private ReplyStringLocal replyString; // THIS IS WHERE THE PROBLEM LIES.
public String requestReport(@QueryParam("reportId") @DefaultValue("") String reportId,
@QueryParam("reportName") @DefaultValue("") String reportName,
@QueryParam("reportType") @DefaultValue("") String reportType) {
return replyString.getReply(reportId, reportName, reportType);
}
}未发布的EJB接口:
@Local
public interface ReplyStringLocal {
public String getReply(String reportId, String reportName, String reportType);
}BEAN 2:
@Stateless
public class ReplyString implements ReplyStringLocal {
public String getReply(String reportId, String reportName, String reportType) {
return "<response><reportId>" + reportId + "</reportId><reportName>" + reportName +
"</reportName><reportType>" + reportType + "</reportType></response>";
}
}为了演示我的问题,这个示例是非常简化的。提前感谢您的帮助。
发布于 2011-04-29 04:26:55
For: JBoss 5、RESTeasy 2.1和EJB3。
好的,我终于得到了关于使用RESTeasy的EJB的全部故事。所以这里是:
A.您可以通过为会话bean提供RESTeasy路径注释和annotation注解来发布具有RESTful接口的会话bean。
接口:
@Local
@Path("MessageMaker")
public interface MessageMakerLocal {
@GET
@Produces({"application/xml"})
@Path("getMessage")
public String getMessage(@QueryParam("message") @DefaultValue("") String message);
}执行情况:
@Stateless
public class MessageMakerImpl implements MessageMakerLocal {
public String getMessage(@QueryParam("message") @DefaultValue("") String message) {
return "Your Message: " + message;
}
}。
B.您不能在RESTeasy中使用@EJB注释,因此不可能使用来自已发布的POJO或已发布的EJB的@Local引用。因此,原始文章中提供的示例无效。
。
C.要从已发布的POJO或已发布的会话Bean访问会话Bean,您可以使用@Remote接口注释并JAR Bean类。在构建EAR文件时,将JAR添加到EAR的根,并在META/application.xml文件中添加对它的引用。
接口:
@Remote
public interface MessageMakerRemote {
public String getMessage(@QueryParam("message") @DefaultValue("") String message);
}
}执行情况:
@Stateless
@RemoteBinding(jndiBinding = "MessageMakerRemote")
public class MessageMakerImpl implements MessageMakerRemote {
public String getMessage(String message) {
return "Your Message: " + message;
}
}在Application.xml中:
<module>
<java>MessageMaker.jar</java>
</module>然后,您可以使用JNDI远程调用jar来引用它:
@Local
@Path("Message")
public class Message {
@GET
@Path("requestMessage")
public String requestMessage(@QueryParam("msg") @DefaultValue("") String msg){
// I use a custom JNDI remote call handler class so my call to the JARed beans looks like this:
return JNDIRemote.getRemote(com.message.ejb3.MessageMakerRemote.class).getMessage(msg);
}
}我希望RESTeasy的后续版本能够提供更好的EJB集成。
https://stackoverflow.com/questions/5813898
复制相似问题