简体   繁体   English

将http请求中的keep alive标头设置为false

[英]setting keep alive header in http request to false

I have limit of maximum two concurrent login from a user in application. 我在应用程序中最多只能有两个用户同时登录。 I want to terminate the session after the soap webservice request but my session is not terminating. 我想在Soap Web服务请求后终止会话,但是我的会话没有终止。 I have tried different ways but did not get any success. 我尝试了不同的方法,但是没有成功。

How should I set the keep alive header so that after the web service call the session get end. 我应该如何设置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);
    }   
}

Try adding header like this addHeader("Keep-Alive", "timeout=60000") 尝试添加这样的标头addHeader("Keep-Alive", "timeout=60000")

Refer this post here 在这里参考这篇文章

Also check in documentation the possible standard values of Keep-Alive here 还要在此处检查文档“ Keep-Alive的可能标准值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM