cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the Header attributes using Webscript ?

vesuinfo
Champ in-the-making
Champ in-the-making
I have seen in AlfrescoWiki that using headers, headersM in web script, we can get the Header Attributes,

headers
    an associative array of all request headers.

headersM
    an associative array of all request headers (where each key is an header name and each value is an array containing all respective header values, even if only one is supplied). See example.

but headerM example refering to the args, argsM example to "http://wiki.alfresco.com/wiki/Web_Scripts_Examples#URL_Argument_Handling" ,

please help me in getting the header Attributes using the headers, headersM ?

Note: I have tried the args, argsM sample it just print the value which i pass in the url.


Thanks,
Saravanan.
5 REPLIES 5

mikeh
Star Contributor
Star Contributor
What happens when you try to access the headers / headersM objects?

Mike

vesuinfo
Champ in-the-making
Champ in-the-making
I have tried with args & argM as specified in this link : http://wiki.alfresco.com/wiki/Web_Scripts_Examples#URL_Argument_Handling,

if i sent the request through the url - http://localhost:8080/alfresco/service/sample/args?a=2&b=3
i am getting the arguments as the output - a=2 b=3 a=2 b=3

respecitve code for arg, argM:
<webscript>
<shortname>Argument Handling Sample</shortname>
<description>Demonstrate access to single and multi-valued arguments</description>
<url>/sample/args</url>
<authentication>user</authentication>
</webscript>

// log each argument (assuming only one value has been provided for each)
for (arg in args)
{
  logger.log(arg + "=" + args[arg]);
}
// log each argument (assuming one or more values have been provided for each)
for (arg in argsM)
{
  for each (val in argsM[arg])
  {
     logger.log(arg + "=" + val);
  }
}

<#list args?keys as arg>
  ${arg}=${args[arg]}
</#list>

<#list argsM?keys as arg>
<#list argsM[arg] as val>
  ${arg}=${val}
</#list>
</#list>

and for Header, I just replaced args with headers across all the places in 3 files,

please help me, if i am doing some thing wrong, Actually i am looking for Header Attribute value "UserAgent" value.

Thanks,
Saravanan

mikeh
Star Contributor
Star Contributor
Ok, but…
What happens when you try to access the headers / headersM objects?
Mike

vesuinfo
Champ in-the-making
Champ in-the-making
Hi Mike,

I have tried like this   ${arg}=${args["useragent"]} & ${header}=${headers["useragent"]} to access the header attribute but i am getting an error saying,

   06300112 Wrapped Exception (with status template): 06300111 Error during processing of the template 'Expression args["useragent"] is undefined on line 8, column 12 in org/alfresco/sample/args.get.html.ftl.'. Please contact your system administrator.

but i am not very sure whether i am doing it in the right way,

Thanks,
Saravanan.

vesuinfo
Champ in-the-making
Champ in-the-making
Hi Mike,

Thanks for your help, I got the values using the below script,

<#list headers?keys as header>
  ${header}=${headers[header]}
</#list>

Thanks,
Saravanan.