سؤال

I am using Php soap server and java client using jax ws. How can I add the sessionId in the soap header on subsequent request? What is its format?

So far I did this :

String url = "http://localhost:8888/server/soap/server.php";

    // login

MessageFactory mf = MessageFactory.newInstance();
SOAPMessage request = mf.createMessage();
SOAPPart soapPart = request.getSOAPPart();
MimeHeaders headers = request.getMimeHeaders();
headers.addHeader("SOAPAction", url);              

SOAPEnvelope envelope = soapPart.getEnvelope();
envelope.addNamespaceDeclaration("var", url);        

SOAPBody soapBody = envelope.getBody();
SOAPElement soapBodyElem = soapBody.addChildElement("call", "var");

SOAPElement action = soapBodyElem.addChildElement("action", "var");
action.addTextNode("LOGON");        

SOAPElement params = soapBodyElem.addChildElement("params", "var");       


SOAPElement uid = soapBodyElem.addChildElement("uid ", "var");
uid .addTextNode("tester");

SOAPElement password = soapBodyElem.addChildElement("password ", "var");
password .addTextNode("");

params.addChildElement(uid );
params.addChildElement(password);

request.saveChanges();

    /* Print the request message */
    System.out.print("Request SOAP Message:");
    request.writeTo(System.out);
    System.out.println();

    SOAPMessage response = soapConnection.call(request, url);

The request above works since it is on login phase and is about to get the session id. But what about the subsequent requests?

هل كانت مفيدة؟

المحلول

I found the solution :

get the cookie of the response of your login and set it on the next request the cookie content would look like this :

PHPSESSID=sqv184d99ndodebh4te9lmpji5; path=/

and this is the code :

 MimeHeaders session = response.getMimeHeaders();     
 String []cookies = session.getHeader("Set-Cookie");             
 request.getMimeHeaders().addHeader("Cookie", cookies[0]);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top