从暴露的RESTeasy接口访问@Local Session Bean [英] Accessing @Local Session Bean from an exposed RESTeasy interface

查看:160
本文介绍了从暴露的RESTeasy接口访问@Local Session Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的应该是非常直接的,但到目前为止是不可能的。有人可以告诉我如何从暴露的RESTeasy界面访问@Local Session Bean?我拖网了互联网的长度和广度,我所能找到的就是同一个例子的变体。



我正在试图找出我如何访问会话bean使用RESTeasy的正常方式。这是迄今为止所看到的东西:



使用:


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实现EReport {

@EJB
private ReplyStringLocal replyString; //这是问题所在。

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报告类型);

}

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

这个例子是超简化的,用于展示我的问题。感谢提前获得任何帮助。

解决方案

对于:JBoss 5,RESTeasy 2.1和EJB 3。



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


A。您可以通过提供RESTeasy路径注释和EJB会话Bean annotaion来发布具有RESTful接口的Session Bean。


INTERFACE:

  @Local 
@Path(MessageMaker)
public界面MessageMakerLocal {

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

}

实现:

  @Stateless 
public class MessageMakerImpl实现MessageMakerLocal {

public String getMessage(@QueryParam(message )@DefaultValue()String message){
返回您的消息:+消息;
}
}


B。您不能在RESTeasy中使用@EJB注释,因此使用发布的POJO或已发布的EJB的@Local会话Bean引用是不成问题的。因此,原始帖子中提供的示例无效。



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


INTERFACE:

  @Remote 
public接口MessageMakerRemote {

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

}
}

实现: em>

  @Stateless 
@RemoteBinding(jndiBinding =MessageMakerRemote)
public class MessageMakerImpl实现MessageMakerRemote {

public String getMessage(String 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){

//我使用自定义JNDI远程调用处理程序类,所以我对JARed bean的调用如下所示:
return JNDIRemote.getRemote(com.message.ejb3.MessageMakerRemote.class).getMessage(msg);
}
}

我希望稍后版本的RESTeasy能够提供更好的集成EJB。


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.

解决方案

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.

这篇关于从暴露的RESTeasy接口访问@Local Session Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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