【问题标题】:setting keep alive header in http request to false将http请求中的keep alive标头设置为false
【发布时间】:2016-04-03 00:58:30
【问题描述】:

我的应用程序中的用户最多可以同时登录两次。我想在肥皂网络服务请求后终止会话,但我的会话没有终止。 我尝试了不同的方法,但都没有成功。

我应该如何设置keep alive标头,以便在Web服务调用后会话结束。

public class CallDropIncidentDataClient {
    private static com.hp.schemas.sm._7.CallDropIncidentManagement getPaymentServicePort() {
        URL url = null;
        try {
            url = new URL(AppConfig.getProperty("Wsdl_CDIncidenManagement_Url"));

        } catch (MalformedURLException ex) {
        }
        QName qName = new QName(AppConfig.getProperty("Wsdl_CDIncidenManagement_Namespace"), AppConfig.getProperty("Wsdl_CDIncidenManagement_Name"));
        com.hp.schemas.sm._7.CallDropIncidentManagement_Service service = new com.hp.schemas.sm._7.CallDropIncidentManagement_Service(url, qName);

        com.hp.schemas.sm._7.CallDropIncidentManagement port = service.getCallDropIncidentManagement();


        //  Map<String, Object> req_ctx = ((BindingProvider) port).getRequestContext();
        // req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, AppConfig.getProperty("Wsdl_CDIncidenManagement_Url"));
        //req_ctx.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, false);


        // Map<String, List<String>> headers = new HashMap<String, List<String>>();
        Map<String, List<String>> headers = new HashMap<String, List<String>>();// ((BindingProvider) port).getRequestContext();

        // headers.put("username", "xx");
        // headers.put("password", "xxxx");


        headers.put("Connection", Collections.singletonList("Keep-Alive"));
        headers.put("keep-alive", Collections.singletonList("timeout=1000"));


        // 
        //System.getProperties().put("http.keepalive", "false");

        //String requestTimeout = "1000";
        BindingProvider prov = (BindingProvider)port;
        prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "xx");
        prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "xxx");
        prov.getRequestContext().put(BindingProviderProperties.REQUEST_TIMEOUT, 2000);
        //  prov.getRequestContext().put("com.sun.xml.ws.request.timeout", requestTimeout);
        prov.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
        prov.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.FALSE);
        prov.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, AppConfig.getProperty("Wsdl_CDIncidenManagement_Url"));


        return port;
    }

    public static CloseCallDropIncidentResponse closeCallDropIncident(com.hp.schemas.sm._7.CloseCallDropIncidentRequest closeCallDropIncidentRequest) {
        com.hp.schemas.sm._7.CallDropIncidentManagement port = getPaymentServicePort();
        return port.closeCallDropIncident(closeCallDropIncidentRequest);
    }

    public static CreateCallDropIncidentResponse createCallDropIncident(com.hp.schemas.sm._7.CreateCallDropIncidentRequest createCallDropIncidentRequest) {
        com.hp.schemas.sm._7.CallDropIncidentManagement port = getPaymentServicePort();

        return port.createCallDropIncident(createCallDropIncidentRequest);
    }

    public static RetrieveCallDropIncidentResponse retrieveCallDropIncident(com.hp.schemas.sm._7.RetrieveCallDropIncidentRequest retrieveCallDropIncidentRequest) {
        com.hp.schemas.sm._7.CallDropIncidentManagement port = getPaymentServicePort();
        return port.retrieveCallDropIncident(retrieveCallDropIncidentRequest);
    }

    public static RetrieveCallDropIncidentKeysListResponse retrieveCallDropIncidentKeysList(com.hp.schemas.sm._7.RetrieveCallDropIncidentKeysListRequest retrieveCallDropIncidentKeysListRequest) {
        com.hp.schemas.sm._7.CallDropIncidentManagement port = getPaymentServicePort();
        return port.retrieveCallDropIncidentKeysList(retrieveCallDropIncidentKeysListRequest);
    }

    public static RetrieveCallDropIncidentListResponse retrieveCallDropIncidentList(com.hp.schemas.sm._7.RetrieveCallDropIncidentListRequest retrieveCallDropIncidentListRequest) {
        com.hp.schemas.sm._7.CallDropIncidentManagement port = getPaymentServicePort();
        return port.retrieveCallDropIncidentList(retrieveCallDropIncidentListRequest);
    }

    public static UpdateCallDropIncidentResponse updateCallDropIncident(com.hp.schemas.sm._7.UpdateCallDropIncidentRequest updateCallDropIncidentRequest) {
        com.hp.schemas.sm._7.CallDropIncidentManagement port = getPaymentServicePort();
        return port.updateCallDropIncident(updateCallDropIncidentRequest);
    }   
}

【问题讨论】:

    标签: java http soap


    【解决方案1】:

    尝试添加这样的标题addHeader("Keep-Alive", "timeout=60000")

    参考这篇文章here

    还要在文档中检查Keep-Alive here 的可能标准值

    【讨论】:

    • 现在请看一下代码。我已经发布了服务数据客户端的完整代码。试图保持活动值到 1 秒。但它使连接保持活力。我也捕获了数据包,但标头没有将保持活动限制为一秒的信息。
    • 我认为我的代码没有在标题中添加信息。?
    • 没有其他方法可以结束会话吗?比如this 使用session.invalidate
    • 另外 Keep-Alive 标头是我认为在您的场景中保持 Web 服务的请求在您的场景中,据我了解您必须在 Web 服务调用后终止用户会话。所以我认为您应该结束获得响应后的会话,并设置请求超时以将值限制为您想要相应调整时间限制的秒数
    猜你喜欢
    • 1970-01-01
    • 2012-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    • 2015-11-15
    • 1970-01-01
    相关资源
    最近更新 更多