Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web services 从cxf web服务访问托管bean_Web Services_Jsf 2_Cxf - Fatal编程技术网

Web services 从cxf web服务访问托管bean

Web services 从cxf web服务访问托管bean,web-services,jsf-2,cxf,Web Services,Jsf 2,Cxf,公共类LoginCredentials{ @WebService(endpointInterface = "login") public class LoginService{ loginCredentials.login(); } 我不相信你想做的是明智的、最好的设计,甚至是合法的:。你可以从一个从WebServiceContext开始的链访问ServletContext 将对WebServiceContext的引用注入SIB @ManagedProperty(name = "appli

公共类LoginCredentials{

@WebService(endpointInterface = "login")
public class LoginService{
 loginCredentials.login();
 }

我不相信你想做的是明智的、最好的设计,甚至是合法的:。你可以从一个从WebServiceContext开始的链访问ServletContext

将对WebServiceContext的引用注入SIB

@ManagedProperty(name = "applicationBD", value = "#{applicationBD}")
private IApplication applicationBD; //This class is application scoped

    How to access applicationBD in this layer?  

     //facescontext is null while calling this service from SOAP UI
    ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    servletContext.getAttribute("applicationStartupBD");
}
从WebServiceContext检索MessageContext,它比上一个上下文更接近webservices的SOAP负载处理结构

这是一种推荐的方法吗?不。您已经切换了依赖关系。webapp应该依赖于webservice,而不是相反。在我看来,webapp更容易更改,是堆栈中的第一层。我建议您在这两层之间保持松散耦合

@Resource
WebServiceContext ctxt;
MessageContext msgContext = ctxt.getMessageContext();
ServletContext servletContext = (ServletContext)msgContext.get(MessageContext.SERVLET_CONTEXT);
IApplication app = (IApplication)  servletContext.getAttribute("applicationStartupBD"); //You can do whatever you please at this point