0 Replies Latest reply on Oct 7, 2008 9:51 AM by Markus Schulz

    Share JSESSIONID between multiple services

    Markus Schulz Newbie

      i'm trying to share a session between more then one webservice endpoint for statefull webservices (via seam to use conversations).

      i've tried to get each port via:

      URL wsdlLocation = new URL("...");
      QName serviceName = new QName(..., ...);
      Service service = Service.create(wsdlLocation, serviceName);
      port1 res = (port1)service.getPort(port1.class);
      BindingProvider bp = (BindingProvider)res;
      bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "admin");
      bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "admin");
      bp.getRequestContext().put(StubExt.PROPERTY_AUTH_TYPE, StubExt.PROPERTY_AUTH_TYPE_WSSE);
      URL securityURL = new File("src/test/webservices/META-INF/jboss-wsse-client.xml").toURL();
      ((StubExt)bp).setSecurityConfig(securityURL.toExternalForm());
      ((StubExt)bp).setConfigName("Standard WSSecurity Client");
      bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
      

      all calls from one port are working fine inside the session but now i wan't to take the JSESSIONID from port1 after first call and use them for port2 with the following code:

      final Map responseMap = ((BindingProvider)port1).getResponseContext();
      final Map headerValues = (Map)responseMap.get(MessageContext.HTTP_RESPONSE_HEADERS);
      final List<String> cookieHeaders = (List<String>) headerValues.get("Set-Cookie");
      for(String x : cookieHeaders) {
      if(xl[0].equals("JSESSIONID")) {
       Map<String, List<String>> headers = (Map<String, List<String>>) ((BindingProvider)port2).getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);
       if (headers == null) {
       headers = new HashMap<String, List<String>>();
      ((BindingProvider)port2).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headers);
       } else { System.out.println("headers exists"); }
      
       List<String> cookie = headers.get("Cookie");
       if (cookie == null) {
       cookie = new ArrayList<String>();
       headers.put("Cookie", cookie);
       } else { System.out.println("cookies exists"); }
       cookie.add("JSESSIONID="+xl[1]);
      


      The cookie would be extracted but ignored on first call for port2, therefore a new session starts on port2.
      how can i solve this?