Task request
Allows Ant scripts to make one or more HTTP requests to PageSeeder and write the responses to a file or multiple files.
Definition
<ps:request path="[request path]" method="[method]" output="[output]" failonerror="[true|false]" pollinginterval="[milliseconds]" config="[config name]"> <parameter name="[param name]" value="[param value]"/> or <fileset dir="[requests directory]" includes="[request.xml]" /> </ps:request>
Attributes
Attribute | Description | Required | Default |
---|---|---|---|
path | The path for the request after the /ps site prefix (e.g. /service/groups/mygroup ) | Yes, unless specified in request XML files | |
output | Specifies the path of the file to write the response to (e.g. output.xml ) | Yes | |
method | Specifies the HTTP method for the request | No | GET |
failonerror | If true , stop ANT build script on error | No | true |
pollinginterval | The number of milliseconds between each check to see if an Asynchronous process is complete (must not be more than 60000 ). | No | 2000 |
config | Universal PS config name | No | default |
Elements
Element <parameter>
If specified set the parameters for the request.
Attribute | Description | Required |
---|---|---|
name | The parameter name | Yes |
value | The parameter value | Yes |
Element <body>
If specified set the request body for method="PUT"
.
Attribute | Description | Required |
---|---|---|
value | The body value | Yes |
Element <fileset>
The standard ANT fileset element can be used to specify one or more request XML files that contain details of the requests.
Request XML files
Request XML files can be used to override any path
, method
, output
or <parameter>
defined by the <ps:request>
and perform multiple requests—one for each file.
A Request File is a UTF-8-encoded XML document that expresses the parameters for a single request in the following syntax where <parameter>
, <body>
and the attributes are optional:
<request [path="[request path]"] [method="[method]"] [output="[output]"] > <parameter name="x" [type="[text|xml]"]>a</parameter> <parameter name="y" [type="[text|xml]"]>b</parameter> <body [type="[text|xml]"]>c</body> </request>
type="text"
: means unescape content when sending (e.g. “x > 1” is sent as “x > 1”)—this is the default iftype
is not specified.type="xml"
: means send content as XML (for example, “<para>x > 1</para>” is sent as is).
Processed in alphabetical path order, each Request that does not specify an output
has a response written to the main output file as follows:
<responses> <response filepath="z/d.xml"> ... </response> <response filepath="z/e.xml"> ... </response> </responses>
Environment
This task uses the following ps:config environment properties:
- scheme – scheme for connecting to PageSeeder.
- host – host for connecting to PageSeeder.
- port – port for connecting to PageSeeder.
- site.prefix – site prefix for connecting to PageSeeder – default /ps.
- user.token or jsessionid or username/password – access token or jsessionid or username/password for connecting to PageSeeder.
Example scripts
Validate all documents in a folder
This script starts a validation thread on a folder and waits until it finishes, then downloads the validation report. It includes properties for running inside PageSeeder and the /api prefix requires v6.
<property name="working" value="${ps.config.default.working}" /> <property name="member" value="${ps.config.default.user.id}" /> <property name="group" value="${ps.config.default.group.name}" /> <property name="folder" value="${ps.config.default.uri.id}" /> <ps:request output="${working}/output.xml" path="/api/members/${member}/groups/${group}/uris/${folder}/foldervalidate" method="POST"> <parameter name="schema" value="default.sch"/> </ps:request> <ps:request output="${working}/validation.xml" path="/validation-report/" method="GET"> <parameter name="group" value="${group}"/> </ps:request>
The 8
in /uris/8
is the URI ID of the folder.
Create multiple comments
<ps:request output="output.xml" path="/service/members/jsmith/comments/forurl" method="POST"> <fileset dir="c:\input\comments"> <include name="*.*"/> </fileset> </ps:request>
Files in c:\input\comments
:
request1.xml
<?xml version="1.0" encoding="utf-8" ?> <request> <parameter name="url">http://www.weborganic.com/</parameter> <parameter name="title">My Comment</parameter> <parameter name="groups">test-mygroup</parameter> <parameter name="content">Hello world!</parameter> <parameter name="authorname">John Jones</parameter> </request>
request2.xml
<?xml version="1.0" encoding="utf-8" ?> <request> <parameter name="url">http://www.mysite.com/</parameter> <parameter name="title">My Comment 2</parameter> <parameter name="groups">test-mygroup</parameter> <parameter name="content">Hello again world!</parameter> <parameter name="authorname">John Jones</parameter> </request>
Get edit history for multiple documents
<ps:request output="output.xml"> <fileset dir="c:\input\history"> <include name="*.*"/> </fileset> </ps:request>
Files in c:\input\history
:
The 123
in /uris/123
is the URI ID of the document.
request1.xml
<?xml version="1.0" encoding="utf-8" ?> <request path="/service/groups/test-mygroup/uris/123/history"> <parameter name="events">edit</parameter> </request>
request2.xml
<?xml version="1.0" encoding="utf-8" ?> <request path="/service/groups/test-mygroup/uris/456/history"> <parameter name="events">edit</parameter> </request>