0

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. 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.

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);
    }   
}
doydoy44
  • 5,720
  • 4
  • 29
  • 45
Muhammad Danish
  • 111
  • 1
  • 6
  • 20

1 Answers1

1

Try adding header like this addHeader("Keep-Alive", "timeout=60000")

Refer this post here

Also check in documentation the possible standard values of Keep-Alive here

Community
  • 1
  • 1
Rahul
  • 170
  • 2
  • 14
  • Please have a look on code now. I have post the complete code of service data client. trying to keep-alive value to 1 sec. But its keeping the connection alive. Also I captured the packet but the header has no information of limit the keep-alive to one second. – Muhammad Danish Dec 29 '15 at 10:14
  • I think my code is not adding information in the header.? – Muhammad Danish Dec 29 '15 at 10:19
  • is there no other way to end the session? like [this](http://stackoverflow.com/questions/10036187/java-servlet-session-cleanup-httpservletrequest) using `session.invalidate` – Rahul Dec 30 '15 at 05:48
  • Also Keep-Alive header is i think to keep the request of web service alive here in your scenario as far as i understood you have to terminate user session after web service call.So i think you should end the session after getting the response , and set the request time out to limit the value to the seconds you want to accordingly adjust to your time limit – Rahul Dec 30 '15 at 06:20