Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Parikhharshal
Creator III
Creator III

Http headers print with trest client

Hi there

 

Is there any way I can print Http Headers with trest client? I am trying to do like this:

 

System.out.println(globalMap.get("tRESTClient_1_HEADERS")); 

 

But it is showing me null......

 

0683p000009M0bu.png

 

Is there something I am doing wrong?

 

Labels (4)
6 Replies
Anonymous
Not applicable

Hello,

After calling a Restful service using tRESTClient,  you can get the headers from the response by using tJavaRow component

Add a tJavaRow after tRESTClient, with the following code:

//access to global headers
java.util.Map resp_headers = (java.util.Map<String,java.util.List<String>>)globalMap.get("tRESTClient_1_HEADERS");

//iterate through the list of headers
System.out.println("\nResponse Headers list:");
for(String headerName: (java.util.Set<String>) resp_headers.keySet()) {
    String headerValue = ((java.util.List<String>)resp_headers.get(headerName)).get(0).toString();
    System.out.println("\t" + headerName + ": " +  headerValue);

 

Parikhharshal
Creator III
Creator III
Author

@xdshi: Sabrina, thanks for your answer. I figured this out.

In a similar way how do I read result from rest client using javarow or javaflex component?

Any help would be appreciated. Thanks.
Anonymous
Not applicable

Hello,

Are you referring to the JSON response of a tRESTClient POST request? It is the body column or the string column that contains the string json? If body column, it is a Document type, link tRestClient to a tXMLMap to extract the string Json, and then link the output to a tExtractJSONFields to extract the value from the string Json, the job looks like:
tRestClient--main--tXMLMap--main--tExtractJSONFields--tLogRow
If the string column contains the string json, link tRestClient to tExtractJSONFields and extract the value, the job looks like:
tRestClient--main--tExtractJSONFields--tLogRow

Feel free to let us know if it is what you are looking for.

Best regards

Sabrina

 

Parikhharshal
Creator III
Creator III
Author

@xdshi: Thsnks for your reply. I know this.

I have specific need where I need to get entire response from test client as string or object type and then start manipulating it in java.

If you could tell me how to get that using javarow or java flex, that would be fanatic.
kuwaryogi27
Creator
Creator

This was helpful for me.
pulkit
Contributor
Contributor

Thanks  for the code.

 

//access to global headers
java.util.Map resp_headers = (java.util.Map<String,java.util.List<String>>)globalMap.get("tRESTClient_1_HEADERS");

//iterate through the list of headers
System.out.println("\nResponse Headers list:");
for(String headerName: (java.util.Set<String>) resp_headers.keySet()) {
    String headerValue = ((java.util.List<String>)resp_headers.get(headerName)).get(0).toString();
    System.out.println("\t" + headerName + ": " +  headerValue);

Above code help us in fetching the list of response headers in tRestClient, Is there is any way to fetch the request headers of tRestClient component.

 

Specially I am looking for custom headers that we sent in Advance Setting section of tRestClient. I am looking for code where I could fetch all request headers of tRestClient at once like above code give all response headers list and log them.

 

In attached picture i want to fetch all request headers intJavaRow_1 that I set in HTTP headers section of tRestClient


Screenshot from 2019-11-28 12-16-37.png