RestDataSink
The RestDataSink
is used to interact with REST-full web services. It uses HTTP as a transport layer and can issue GET, HEAD, POST, PUT and DELETE requests. All requests can carry data in the form of query and matrix parameters. In addition, POST and PUT requests can carry content that is transferred to the service. Two different message formats are supported: XML and JSON. Regarding the statistics, each REST call counts as one processed entity.
Configuration
Name | Type, usage constraints, defaults | Description |
---|---|---|
connectionPool | required: paraVal default: none type: HttpConnectionPool | The HTTP connection pool to be used. |
url | required: paraVal default: none type: URL | The URL of the service resource. |
command | optional: paraVal default: GET type: GET, HEAD, PATCH, POST, PUT, DELETE | The HTTP method or command to request on the resource. |
queryParameters | optional: paraMap default: none type: string/string | Defines the query parameters that are encoded in the URL.Query parameters are parameters that are encoded in the URL after a "?" and that are concatenated with "&". Example: <http://url>?param1=value1¶m2=value2 . |
matrixParameters | optional: paraMap default: none type: string/string | Defines the matrix parameters that are encoded in the URL.Matrix parameters are parameters that are encoded in the URL after a ";" and that are concatenated with ";". Example: <http://url>;param1=value1;param2=value2 . |
messageFormat | optional: paraVal default: XMLtype: XML or JSON | Defines the format of the messages transported and received through HTTP. The Content-type and Accept HTTP headers are automatically set to the correct values: XML : application/xml; JSON : application/json. The headers can be overwritten using the headers parameter. |
content | optional: paraList default: none type: list of strings | The content that is sent in the body of the HTTP protocol. The content should reflect what was specified as message format. The values of the list are concatenated to form the content.Only the PATCH, POST and PUT methods can carry content in the HTTP body. Therefore, this parameter is only available for PATCH, POST and PUT requests. |
headers | optional: paraMap default: none type: string/string | Additional headers for the HTTP request. |
expectedStatus | optional: paraVal default: 200 type: int | The expected status code of the HTTP response."200" (OK) is used as default. If the response's status code does not match the expected code, an error occurs. |
encoding | optional: paraVal default: default encoding type: string | The name of the character set that should be used to encode the request. The available values depend on the version and vendor of the JVM. Examples: UTF-8, ISO-8859-1, UTF-16LE |
Example
The principles of function are the same for the RestDataSink
and the RestDataSource
plug-ins. Therefore, see RestDataSource for more examples.
Delete a resource identified by the id
query parameter:
<dataSink type="RestDataSink">
<dp:paraVal name="connectionPool" value="${inst.httpConnection}"/>
<dp:paraVal name="url" value="http://localhost:44432/nevisdp/resttest/person"/>
<dp:paraMap name="queryParameters">
<value name="id" value="#{in.user.id}" />
</dp:paraMap>
<dp:paraVal name="command" value="DELETE" />
</dataSink>
Call a service using JSON and the PUT method:
<dataSink type="RestDataSink">
<dp:paraVal name="connectionPool" value="${inst.httpConnection}"/>
<dp:paraVal name="url" value="http://localhost:44432/nevisdp/resttest/person"/>
<dp:paraVal name="command" value="PUT" />
<dp:paraVal name="messageFormat" value="json"/>
<dp:paraList name="content"><value><![CDATA[{
"firstName":"#{in.user.firstname}",
"id":"#{in.user.id}",
"lastName":"#{in.opa.lastname}"}]]></value>
</dp:paraList>
</dataSink>
Debug
To get more detailed information about the sent requests, set the following log setting:
<category name="ch.adnovum.dataporter.util.RestHelper"> <priority value="DEBUG"/></category>