Http response header

How could I set my own key value pair in http response headers

try on these lines

HttpHeader respHeader = Service.getHttpResponseHeader();

respHeader.setValues((Values)pipeline);

u may need to import com.wm.net.HttpHeader class

regards

Thahir

Thank you for the response

This did not add the values to the header
can you give the complete code pls

George

Hi all,

I could not find the java documentation for HttpHeader class. can somebody help me with a working sample code on how to add custom values to response http header pls

Many thanks

George

The com.wm.net.HttpHeader class in the IS Server Java API is undocumented.
Here’s what I know about three methods in that class:


// Set HTTP response code
setResponseCode(ResponseCode_Integer);
// Set HTTP response code with reason phrase
setResponseCode(ResponseCode_Integer, ResponseReasonPhrase_String);
//Add HTTP response field.
addField(HeaderFieldName_String, HeaderFieldValue_String);


Your code should work if you import the class. Eg:


com.wm.net.HttpHeader h = Service.getHttpResponseHeader(null);
h.setResponse(302, “Found”);
h.addField(“Location”, URL);


Similar to setResponse you can also use these

respHeader.setResponseCode(800);
respHeader.setResponseMessage(“New Message goes here”);

and ofcourse the one mentioned above by sonam

respHeader.setResponse(800,“Another Message”);

I am sorry respHeader.setValues((Values)pipeline) did not yeild any results. I did not try it before thought that might do the work. Maybe somebody would be able to say WHAT THEN it is doing

regards

Thahir

Hi,

actually setValues works, but you have to setResponse first.

I created following service to set Http headers (check attached picture for service inputs):

HttpHeader respHeader = Service.getHttpResponseHeader(null);
// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();

    // header
    IData    header = IDataUtil.getIData( pipelineCursor, "header" );

    if ( header != null)
    {

        IDataCursor headerCursor = header.getCursor();

            String status = IDataUtil.getString( headerCursor, "status" );
            String statusMessage = IDataUtil.getString( headerCursor, "statusMessage" );        
            respHeader.setResponse(Integer.parseInt(status), statusMessage);
            respHeader.setValues(Values.use(header));

            /* not needed as we're passing Values type
            // i.lines
            IData    lines = IDataUtil.getIData( headerCursor, "lines" );
            if ( lines != null)
            {
                IDataCursor linesCursor = lines.getCursor();
                    String    Date = IDataUtil.getString( linesCursor, "Date" );
                    String    Server = IDataUtil.getString( linesCursor, "Server" );
                    String    Content_Type = IDataUtil.getString( linesCursor, "Content-Type" );
                    String    Connection = IDataUtil.getString( linesCursor, "Connection" );
                    respHeader.addField("Date", Date);
                    respHeader.addField("Server", Server);
                    respHeader.addField("Content-Type", Content_Type);
                    respHeader.addField("Connection", Connection);
                linesCursor.destroy();
            }
            */
        headerCursor.destroy();
    }

pipelineCursor.destroy();

Don’t forget to put com.wm.net.HttpHeader into imports section.
createHttpHeader.PNG