从公开的 RESTeasy 接口访问 @Local Session Bean

发布于 2024-11-03 15:04:23 字数 1962 浏览 3 评论 0原文

我想做的事情应该是非常直接的,但到目前为止是不可能的。有人可以告诉我如何从公开的 RESTeasy 接口访问 @Local Session Bean 吗?我已经搜索了互联网的长度和广度,我所能找到的只是同一示例的变体,

我试图找出如何使用 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>";
      } 
}

为了演示我的问题,该示例经过了超级简化。预先感谢您的任何帮助。

What I am trying to do should be very straight forward BUT thus far has been impossible. Can someone tell me how to access a @Local Session Bean from an exposed RESTeasy interface? I have trawled the length and breadth of the internet and all I can find is variations of the same example

I am trying to find out how I can access a session bean in the normal way using RESTeasy. This is what things look like so far:

USING:

EJB 3

RESTeasy 2.1

PUBLISHED EJB INTERFACE:

@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);        
 
    }
}

UNPUBLISHED EJB INTERFACE:

@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>";
      } 
}

This example is super simplified for the purposes of demonstrating my issue. Thanks in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月流歌 2024-11-10 15:04:23

适用于:JBoss 5、RESTeasy 2.1 和 EJB 3。

好的,我终于了解了有关 RESTeasy 的 EJB 的完整故事。所以这里是:

A.您可以通过为其提供 RESTeasy 路径注释和 EJB 会话 bean 注释来发布具有 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 Session bean 引用。因此,原始帖子中提供的示例无效。

C.要从已发布的 POJO 或已发布的会话 Bean 访问会话 Bean,您可以使用 @Remote 接口注释并 JAR 您的 Bean 类。当您构建 EAR 文件时,将 JAR 添加到 EAR 的根目录,并在 META-INF/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>

然后您可以使用对 jar 的 JNDI 远程调用来引用它:

@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 集成。

For: JBoss 5, RESTeasy 2.1 and EJB 3.

Ok so I finally got the full story on EJBs with RESTeasy. So here it is:

A. You can publish a Session bean with a RESTful interface by giving it RESTeasy path annotation and EJB Session bean annotaion.

INTERFACE:

@Local
@Path("MessageMaker")
public interface MessageMakerLocal {

    @GET
    @Produces({"application/xml"})
    @Path("getMessage")
    public String getMessage(@QueryParam("message") @DefaultValue("") String message);

}

IMPLEMENTATION:

@Stateless
public class MessageMakerImpl implements MessageMakerLocal {

    public String getMessage(@QueryParam("message") @DefaultValue("") String message) {
        return "Your Message: " + message;
    }
}

.

B. You cannot use @EJB annotation in RESTeasy so using a @Local Session bean reference from a published POJO or published EJB is out of the question. So the example provided in the original post is not valid.

.

C. To access a Session Bean from published POJOs or published Session Bean, you can use the @Remote interface annotation and JAR your Bean classes. When you are building your EAR file add the JAR to the root of your EAR and add a reference to it in your META-INF/application.xml file.

INTERFACE:

@Remote
public interface MessageMakerRemote {

    public String getMessage(@QueryParam("message") @DefaultValue("") String message);

    }
}

IMPLEMENTATION:

@Stateless
@RemoteBinding(jndiBinding = "MessageMakerRemote")
public class MessageMakerImpl implements MessageMakerRemote {

    public String getMessage(String message) {
        return "Your Message: " + message;
    }
}

In Application.xml:

<module>
    <java>MessageMaker.jar</java>
</module>

You can then make reference to it using a JNDI remote call to your 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);
    }
}

I am hoping that later versions of RESTeasy will provide better integration of EJBs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文