How to get the Header attributes using Webscript ?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2009 07:56 AM
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.
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.
Labels:
- Labels:
-
Archive
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2009 08:26 AM
What happens when you try to access the headers / headersM objects?
Mike
Mike
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2009 09:46 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2009 10:09 AM
Ok, but…
What happens when you try to access the headers / headersM objects?Mike
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2009 10:16 AM
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.
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2009 10:29 AM
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.
Thanks for your help, I got the values using the below script,
<#list headers?keys as header>
${header}=${headers[header]}
</#list>
Thanks,
Saravanan.
