2013-04-11 85 views
1
@WebService(endpointInterface = "login") 
public class LoginService{ 
loginCredentials.login(); 
} 

公共類LoginCredentials {從CXF Web服務訪問一個託管bean

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

回答

0

我不相信你想要做的最好,最好的設計是什麼。甚至合法:)。您可以從鏈訪問ServletContext開始與WebServiceContext

  1. 注入到WebServiceContext引用到您的SIB

    @Resource 
    WebServiceContext ctxt; 
    
  2. WebServiceContext,檢索MessageContext(這是更接近SOAP web服務的有效負載處理結構比以前的上下文)。從此,你將得到ServletContext

    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 
    

這是一個推薦的做法?不,你有依賴切換。 webapp應該依賴web服務而不是其他方式。國際海事組織,網絡應用程序更容易改變,並且是堆棧中的第一層。我會建議你堅持兩層之間的鬆耦合