2014-01-15 64 views
1

我使用的是使用jax ws的Php soap服務器和java客戶端。 如何在隨後的請求中添加soap頭中的sessionId? 它的格式是什麼?使用saaj在肥皂標題中添加會話標識

到目前爲止,我這樣做:

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); 

上述要求的作品,因爲它是在登錄階段,並即將獲得的會話ID。但接下來的請求呢?

回答

0

我找到了解決辦法:

讓你登錄的響應的Cookie,並把它放在下一個請求 cookie的內容是這樣的:

PHPSESSID=sqv184d99ndodebh4te9lmpji5; path=/ 

,這是代碼:

MimeHeaders session = response.getMimeHeaders();  
String []cookies = session.getHeader("Set-Cookie");    
request.getMimeHeaders().addHeader("Cookie", cookies[0]);