2015-04-19 1 views
0

Il est nécessaire d'ajouter une nouvelle paire de valeurs de clé d'en-tête http dans une demande de savon. Quelque chose comme ci-dessous.Comment ajouter ou manipuler l'en-tête http dans un appel de service Web dans Java

HTTP/1.1 200 OK 
Cache-Control: no-cache 
Pragma: no-cache 
Content-Type: text/xml; charset=utf-8 
New-Key: Some dynamic value 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Body> 

Comment puis-je ajouter une nouvelle paire de valeurs clés (Nouvelle-clé: une valeur dynamique) en-tête http tout en faisant une demande de savon? La valeur sera ensuite extraite par le serveur de l'en-tête http. Comme exigence, un nouveau champ ne doit pas être ajouté dans le collecteur de savon ni dans le corps du savon.

Nous utilisons l'outil IBM wsdl2java, qui implémente la spécification IBM JAX-RPC pour générer les clients Java et appeler les appels de service Web SOAP.

+0

des suggestions pls – Sunny

Répondre

0

à Ans
https://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.base.doc/ae/rwbs_transportheaderproperty.html

public class MyApplicationClass { 
// Inject an instance of the service's port-type. 
@WebServiceRef(EchoService.class) 
private EchoPortType port; 

// This method will invoke the web service operation and send and receive transport headers. 
public void invokeService() { 

    // Set up the Map that will contain the request headers. 
    Map<String, Object>requestHeaders = new HashMap<String, Object>(); 
    requestHeaders.put(“Cookie”, “ClientAuthenticationToken=FFEEBBCC”); 
    requestHeaders.put(“MyHeaderFlag”, new Boolean(true)); 

    // Set the Map as a property on the RequestContext. 
    BindingProvider bp = (BindingProvider) port; 
    bp.getRequestContext().put(com.ibm.websphere.webservices.Constants.REQUEST_TRANSPORT_PROPERTIES, requestHeaders); 

    // Set up the Map to retrieve transport headers from the response message. 
    Map<String, Object>responseHeaders = new HashMap<String, Object>(); 
    responseHeaders.put(“Set-Cookie”, null); 
    responseHeaders.put(“MyHeaderFlag, null); 

    // Invoke the web services operation. 
    String result = port.echoString(“Hello, world!”); 

    // Retrieve the headers from the response. 
    String cookieValue = responseHeaders.get(“Set-Cookie”); 
    String headerFlag = responseHeaders.get(“MyHeaderFlag”); 
} 

}