【问题标题】:How to identify application that calls web service如何识别调用 Web 服务的应用程序
【发布时间】:2014-10-17 10:54:56
【问题描述】:

我有一个带有 6 个 Web 服务的 Java servlet 应用程序,我必须确定其中一个 Web 请求是调用 Web 服务的 Live 还是 Test 实例。我相信我可以从 URL 中确定这一点,即

 https://localhost:8443/projectname/etc 

https://localhost:8443/projectnameTEST/etc 

我正在尝试使用 HttpServletRequest 来获取它,并且我知道我必须从名为“getDocument”的 Web 服务内部调用类似下面的过程但是如何在 getDocument 中初始化 HttpServletRequest?那就是如何在getDocument web服务中创建参数“request”,并将其初始化为请求信息?

public void doGet(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
     ...
     StringBuffer url = request.getRequestURL();
     ...
} 

【问题讨论】:

    标签: java web-services servlets


    【解决方案1】:

    您可以检索客户信息,例如:

    @WebService()
    public class SomeWebService {
        ...
        @Resource private WebServiceContext wsc;
        ...
        @WebMethod 
        public void methodOfWebService() {      
            MessageContext mc = wsc.getMessageContext();
    
            // retrieve the client information
            HttpServletRequest httpServletRequest = 
                (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST);    
            System.out.println(httpServletRequest.getServletContext().getContextPath());
            ...
        }
    }
    

    【讨论】:

    • 谢谢。当我通过 SoapUI 拨打电话时,这似乎有效。我尚未在 Web 界面上对其进行测试,但相信它会起作用。会及时更新
    猜你喜欢
    • 1970-01-01
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多