Adding a custom HTTP Header in KPSA soaputil::SOAPMessage

Adding a custom HTTP Header in KPSA soaputil::SOAPMessage

book

Article ID: KB0084831

calendar_today

Updated On:

Products Versions
TIBCO KPSA - Mobile -
Not Applicable -

Description

Resolution:
Description:
============
This article explains how to add a custom HTTP header to HTTP request that contains soaputil::SOAPMessage.    

Environment:
===========
KPSA-3.5 application

Resolution:
==========
1). Create httputil::Message request.

2). Add custom HTTP headers using the method addHeader().

3). Create soaputil::SOAPMessage.

4). Add this message to the http request using exportToXML() method.            

Example:
#############  
1). // Create HTTP message
    declare httputil::Message request;
    create request;

    // Set method
    request.setMethod(httputil::G_PostMethod);

    // Set URI type to relative
    request.uriType = kablet::RelativeURI;    

2). //Add custom HTTP header
    request.addHeader("HEADER","this is the value of the added header");    
    
3). // Create SOAPMessage
    // Declare and create SOAPMessage      
    declare soaputil::SOAPMessage soapMessage;
    create soapMessage values (
        SOAPEncoding:"UTF-8",
        SOAPVersion:"1.0");

    // Declare namespace consts
    declare string nsURI = "urn:xmethods-delayed-quotes";
    declare string nsPrefix = "n";

    // Declare and create SOAP message content elements and atributes
    // Elements
    declare xmlutil::Element getQuote;
    create getQuote values(
        localName:"getQuote",
        nsName:nsURI,
        nsPrefix:nsPrefix);

    declare xmlutil::Element symbol;
    create symbol values(
        localName:"symbol",
        value:"SUNW");

    // Connect hierarchy
    getQuote.addElement(symbol);

    // Add NS declaration to the root element
    getQuote.addNamespaceDeclaration(nsURI, nsPrefix);
    // Add body element
    soapMessage.addBodyElement(getQuote);
    
4). // add the message to the request
    //get body of soapMessage          
    declare string body;
    soapMessage.exportToXML(body);     
                    
    //include body of soapMessage in HTTP request
    declare kablet::Part soapBody;
    create soapBody;
    soapBody.content = body;
    request.addPart(soapBody);    
###################

Issue/Introduction

Adding a custom HTTP Header in KPSA soaputil::SOAPMessage