Forum Discussion

ServiceV's avatar
ServiceV
New Contributor
8 years ago

How to retrieve a value from the request header?

Hi All,

 

I have a service sending below request headers to my virt.

I want to store the value of the oauth_callback present under Authorization header, highlighted in red and store this in a property and then use it in a subsequent response.

 

{

'Connection': 'keep-alive',

'Accept': '*/*',

'Content-Length': '0',

'Accept-Encoding': 'gzip, deflate',

'Authorization': 'OAuth oauth_nonce="123123123123123", oauth_timestamp="12312312123", oauth_version="1.0", oauth_signature_method="HMAC-SHA1", oauth_consumer_key="XXXXXXXXXXX", oauth_callback="http%3A%2F%2Flocalhost%3YYYYYYYYY", oauth_signature="AAAAAAAAAAAA"'

}

 

 

How can i store this value?

Using below, i am able to store the value of authorization header, however, i can't find a way to get the oauth_callback value.

def acceptEncodingHeaderList = mockRequest.getRequestHeaders().get("Authorization")

 

Thank You.

 

 

 

  • ServiceV's avatar
    ServiceV
    New Contributor

    Hi All,

     

    I am able to retrieve oauth_callback value into a variable but i can't find a way to store this in custom property.

    I want to store this value in custom property and pass the value of this custom property in response of other service present in my project.

     

    def acceptEncodingHeaderList = mockRequest.getRequestHeaders().get("Authorization").toString()

    String[] Header = acceptEncodingHeaderList.split(",");

    for (int i = 0; i < Header.length; ++i)
    {
    if(Header[i].contains("oauth_callback"))
    {
    String[] splitHeader = Header[i].split("=");
    String callback = splitHeader[1].getAt(1..-1)
    log.info "callback" + oauth_callback
    }

     

    To elaborate more with an example,

    Suppose , service A sends a request with the authorization header, i want to store the value of oauth_callback from authorization header in custom properties and pass this value in the response of Service B.