我正在使用Java EE 6,这是第一次使用jax-rs,我有这个资源类,但我不知道为什么我的会话在访问服务时没有检索。登录工作正常,可以在应用程序的其他部分检索主体。加载Jax-rs资源时SessionContext丢失
@Path("/countries")
@Stateless
public class CountryResource {
@Resource
SessionContext ctx;
@EJB
private CityBean cityBean;
@Path("/countryid/{countryid}")
@GET
@Produces("application/xml")
public String getCountryByPk(@PathParam("countryid") Long tlCountryId){
if(ctx != null){
System.out.println(ctx.getCallerPrincipal());
}
String country;
...
return country;
}
此输出为匿名,但我已成功登录。在我尝试使用SessionContext之前,我试图让@RolesAllowed工作,但并没有取得进展。我也有JaxRsActivator类。我需要知道关于与会话相关的jax-rs?
@ApplicationPath("/rest")
public class JaxRsActivator extends Application {
}