Captain
Captain
193 views

How to use multiple headers in REST Driver

Jump to solution

Hi all. Today's inquiry is about REST Driver.

I need to send two dynamic headers in my request but i believe i'm not achieving it.

I cannot access the platform to check how my request is being received. I apologize in advance because my knowledge of Rest Driver is quite limited but i was searching through the documentation and found no examples regarding to what i want to achieve.

I know i have to send the headers in the driver-operation-data XML, so i'm doing it like this:

<driver-operation-data class-name="User" command="query" event-id="0" src-dn="">
<request>
<url-token/>
<header cookie="JSESSIONID=XXXXX"/>
<header cookie="iamlb=XXXX"/>
<value>XXXXXXX</value>
</request>
/driver-operation-data>

 

But when i see the log, seems like the second cookie is not being sent:

Rest_Driver: sub-execute
Rest_Driver: queryHandler
Rest_Driver: queryHandler: class-name == 'User'
Rest_Driver: Query: preparing POST to https://xxxxx.xxxx:xxx/xxx/xxx
Rest_Driver: Setting the following HTTP request properties:

Rest_Driver: Content-type:application/x-www-form-urlencoded
Rest_Driver: cookie:XXXXXXXX
Rest_Driver: Did a HTTP POST with 0 bytes of data to https://xxxxx.xxxx:xxx/xxx/xxx
Rest_Driver: Response code and message: 200 OK
SubscriptionShim.execute() returned:

 

Content type is defined at the resource for query.

This is the code that adds the headers:

<do-append-xml-element expression="../driver-operation-data[last()]/request[last()]" name="header"/>

<do-set-xml-attr expression="../driver-operation-data[last()]/request[last()]/header" name="cookie">
<arg-string>
<token-text xml:space="preserve">JSESSIONID=</token-text>
<token-local-variable name="JSESSIONID"/>
</arg-string>
</do-set-xml-attr>

<do-append-xml-element expression="../driver-operation-data[last()]/request[last()]" name="header"/>

<do-set-xml-attr expression="../driver-operation-data[last()]/request[last()]/header[last()]" name="cookie">
<arg-string>
<token-global-variable name="iamlb-cookie"/>
<token-text xml:space="preserve">=</token-text>
<token-local-variable name="iamlb"/>
</arg-string>
</do-set-xml-attr>

My question overall is, am i doing it right or do i have to add the second header in another way?

Thank you so much in advance.

 

0 Likes
1 Solution

Accepted Solutions
Knowledge Partner Knowledge Partner
Knowledge Partner

I think you should have only one cookie xml attribute, but multiple cookies should be delimited by semi-colon (";")

So something like that (writing from top of my mind):

<do-set-xml-attr expression="../driver-operation-data[last()]/request[last()]/header[last()]" name="cookie">
	<arg-string>
		<token-text xml:space="preserve">JSESSIONID=</token-text>
		<token-local-variable name="JSESSIONID"/>
		<token-text xml:space="preserve">;</token-text>
		<token-global-variable name="iamlb-cookie"/>
		<token-text xml:space="preserve">=</token-text>
		<token-local-variable name="iamlb"/>
	</arg-string>
</do-set-xml-attr>

 

View solution in original post

4 Replies
Knowledge Partner Knowledge Partner
Knowledge Partner
You should write it like this.

<driver-operation-data class-name="User" command="query" event-id="0" src-dn="">
<request>
<url-token/>
<header cookie="JSESSIONID=XXXXX" cookie="iamlb=XXXX"/>
<value>XXXXXXX</value>
</request>
/driver-operation-data>

Just disable the second append of header element. That should do the trick.

<do-append-xml-element expression="../driver-operation-data[last()]/request[last()]" name="header"/>
Alex McHugh - Knowledge Partner - Stavanger, Norway
Who are the Knowledge Partners
If you appreciate my comments, please click the Like button.
If I have resolved your issue, please click the Accept as Solution button.
Captain
Captain

Hi Alex, thank you so much for your answer.

What i'm not acheiving is to get the second header beside the first one. 

When disabling the Do Append XML Element Action, the second header overwrites the first one.

I know this is an XML question rather than a Rest Driver one, but still any help would be welcome.

0 Likes
Knowledge Partner Knowledge Partner
Knowledge Partner

I think you should have only one cookie xml attribute, but multiple cookies should be delimited by semi-colon (";")

So something like that (writing from top of my mind):

<do-set-xml-attr expression="../driver-operation-data[last()]/request[last()]/header[last()]" name="cookie">
	<arg-string>
		<token-text xml:space="preserve">JSESSIONID=</token-text>
		<token-local-variable name="JSESSIONID"/>
		<token-text xml:space="preserve">;</token-text>
		<token-global-variable name="iamlb-cookie"/>
		<token-text xml:space="preserve">=</token-text>
		<token-local-variable name="iamlb"/>
	</arg-string>
</do-set-xml-attr>

 

View solution in original post

Captain
Captain

Following your suggestion did the trick! then i realized it was already defined in the RFC.

Greetings

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.