pfx-rest Component
This component is used for REST API manipulation with authentication handling.
URI format | pfx-rest:method |
Â
In this section:
Available methods:
Compatible connections:
Unknown Properties
Unknown properties are handled as query parameters. For details see the section below.
An exception is when using the method system
– in this case, unknown properties are handled as properties.
Limitations
Supported authentication methods: OAuth2, JWT, Basic, no auth. Newly, there is support for authentication over the Pricefx connection against Pricefx system calls (defined Pricefx connection is transformed to Basic authentication).
The connection must be defined in the application if a protected resource is accessed. For public resources, the connection is not required.
The component deals mainly with accessing the resource and providing raw data without any transformations. If e.g. the resource API uses pagination, you must handle that by yourself.
The component itself is the producer, thus must be used in to routes.
Changelog
1.8.0
Added support for authentication over Pricefx connection against Pricefx system calls (defined Pricefx connection is transformed to Basic authentication) https://pricefx.atlassian.net/browse/PFIMCORE-766
1.5.0
Added support for SSL certificates https://pricefx.atlassian.net/browse/PFIMCORE-638
1.4.0
Added support for streaming content into a file. Useful for large requests. https://pricefx.atlassian.net/browse/PFIMCORE-619
Added support for uploading files via Multipart upload.  https://pricefx.atlassian.net/browse/PFIMCORE-652
Implemented methodÂ
system
. https://pricefx.atlassian.net/browse/PFIMCORE-712
1.2.0
authRequestTemplate
for JWT and OAuth2 is independent of the order of parameters / parameters themselves. https://pricefx.atlassian.net/browse/PFIMCORE-492Added theÂ
authRequestHeader
 param to JWT and OAuth2 connections. The parameter defines the name of the header parameter bearing the token information. https://pricefx.atlassian.net/browse/PFIMCORE-492Added theÂ
authRequestHeaderBearer
param to JWT, OAuth2 and Basic connections. The parameter defines the authorization header value prefix. https://pricefx.atlassian.net/browse/PFIMCORE-492ParameterÂ
connectionName
was renamed toÂid
. https://pricefx.atlassian.net/browse/PFIMCORE-511AddedÂ
autoDecode
parameter. The parameter defines whether encoded content should be automatically decoded. https://pricefx.atlassian.net/browse/PFIMCORE-527
1.1.18.5
Response code of the HTTP response is now set to the CamelHttpResponseCode header of the exchange message. https://pricefx.atlassian.net/browse/PFIMCORE-543
1.1.18.4
Token is cached and refreshed in JWT and OAuth connections based on the expiration time independently from the call rest service. This is managed by theÂ
authResponseExpirationKey
andauthExpirationMultiplier
params on the connection. https://pricefx.atlassian.net/browse/PFIMCORE-491Range of accepted HTTP response codes is set as it is in the http component query parameter, for example: okStatusCodeRange=200,202,404 https://pricefx.atlassian.net/browse/PFIMCORE-489
1.1.18.1
Issue with sharing context fixed
Query parameters simplified
1.1.18
Component introduced
Component Usage
The component can be used in a wide range of use cases. The most common ones are listed here.
Headers
There are two ways to add custom headers to the final request.Â
Headers from Connection
If you want to use headers from the connection, specify them in the connection definition.
Example with an XML bean configuration:
Example input
<bean id="myConnection" class="net.pricefx.integration.component.rest.domain.connection.BasicConnection">
<property name="headers" ref="headersMap"/>
</bean>
<util:map id="headersMap" map-class="java.util.HashMap" key-type="java.lang.String" value-type="java.lang.String">
<entry key="accept" value="application/json"/>
<entry key="myHeader" value="myValue"/>
</util:map>
The above configuration will yield into a request with the following headers:
Example input
accept = 'application/json'
myHeader = 'myValue'
Headers from Exchange
If you want headers from the exchange to be sent into HTTP endpoints, prefix them with pfx-rest.
. Headers without pfx.rest.
will be ignored.
Example input
pfx-rest.accept = 'application/json'
pfx-rest.myHeader = 'myValue'
These exchange parameters will be transferred into the following headers:
Example input
The request will then be sent with the above headers (plus also other generated headers – authorization etc.).
 Headers from the exchange have precedence over headers from the connection.
Content Decoding
It is possible to have encoded responses automatically decoded. To do so, set the parameter autoDecode
 to true
(which is the default).
The encoded response has a header parameter content-encoding
set to some value.Â
If you want to get a raw encoded response, set autoDecode
to false
. You will get a base64 representation of the encoded data.
Multipart File Upload
It is possible to upload a file from a resource using the Multipart upload. It has two features:
Exchange body must be of the type
java.nio.file.Path
 and must have a path to the resource.Query parameters provided to
pfx-rest
will be put into the body instead of the URL.
Example
Lets assume we have the following cURL request:
This request could be transformed into the following pfx-rest
definition in a route (omitting authorization):
With body definition:
Then pfx-rest
will create an adequate request as with cURL.
Using Component with URI Parameters
As mentioned earlier, unknown parameters are taken as query parameters. These query parameters are appended to the final request made to the server.
Example with an unknown parameters set:
Example input
Parameters $top
and $expand
are not defined parameters of this component and will be treated as query parameters.
Final request:
Example input
Note:
Order of query parameters is not guaranteed.
You must encode such parameters according to the Camel requirements. Encoding to URL is made automatically by the component.
 When uploading a file using the Multipart file upload, query parameters are treated as form parameters and will be present in the body instead of the URL.
IntegrationManager version 5.8.0