ComposantsComponents › Internet
Ancien client REST, simple : envoie une requête GET, POST, PUT, PATCH ou DELETE à une URL, avec des en-têtes et un corps saisis dans le composant, et rend la réponse sur une ligne : le corps en texte (Body), le code d'erreur (ERROR_CODE) et le code de retour (RETURN_CODE). Une requête par exécution du sous-job : il commence le sous-job, ou suit une itération. Une réponse en erreur n'arrête pas le job. Pour un appel par ligne de données, un corps XML ou JSON construit, les services de Talend ESB, voyez tRESTClient.
Old, simple REST client: sends a GET, POST, PUT, PATCH or DELETE request to a URL, with headers and a body typed in the component, and gives the response on one row: the body as text (Body), the error code (ERROR_CODE) and the return code (RETURN_CODE). One request per run of the subjob: it starts the subjob, or follows an iteration. An error response does not stop the job. For one call per data row, a built XML or JSON body, the services of Talend ESB, see tRESTClient.
EntréeInput
Aucun flux de données. Un lien Iterate, facultatif : une requête par itération.No data flow. One Iterate link, optional: one request per iteration.
SortieOutput
Main une ligne par requête : Body, ERROR_CODE, RETURN_CODE.Main one row per request: Body, ERROR_CODE, RETURN_CODE.
Déclencheurs en sortieOutput triggers
On Subjob Ok On Subjob Error On Component Ok On Component Error Run if
Le tREST commence le sous-job et fait un appel ; le tJava lit ensuite ERROR_MESSAGE. Le corps se découpe ensuite avec tExtractJSONFields ou tExtractXMLField.
The tREST starts the subjob and makes one call; the tJava then reads ERROR_MESSAGE. The body is then split with tExtractJSONFields or tExtractXMLField.
L'URL lit la valeur de l'itération : "http://127.0.0.1:54525/echo?id=" + globalMap.get("tLoop_1_CURRENT_VALUE"). Pour partir d'un flux, passez par un tFlowToIterate.
The URL reads the value of the iteration: "http://127.0.0.1:54525/echo?id=" + globalMap.get("tLoop_1_CURRENT_VALUE"). To start from a flow, go through a tFlowToIterate.
Content-Type dans les En-têtes HTTP.Choose the HTTP Method; for POST, PUT and PATCH, write the HTTP Body and, if it is not JSON, its Content-Type in the HTTP Headers.ERROR_CODE ou RETURN_CODE dans la suite du flux.Connect the Main output and test ERROR_CODE or RETURN_CODE in the rest of the flow.Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Le composant n'a pas de paramètres avancés. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. The component has no advanced settings.
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| SchémaSchemaSCHEMA | Body, ERROR_CODE, RETURN_CODE | ToujoursAlways | En lecture seule : voir Le schéma. Read-only: see The schema. |
| URLURL | "" |
ToujoursAlways |
Adresse complète, expression Java : "http://127.0.0.1:54525/echo?id=1". Vide, le composant s'arrête sur url can't be empty!.
Full address, a Java expression: "http://127.0.0.1:54525/echo?id=1". Empty, the component stops on url can't be empty!.
|
| Méthode HTTPHTTP MethodMETHOD | GET | ToujoursAlways | GET, PATCH, POST, PUT ou DELETE. GET et DELETE partent sans corps. GET, PATCH, POST, PUT or DELETE. GET and DELETE leave with no body. |
| En-têtes HTTPHTTP HeadersHEADERS | videempty | ToujoursAlways |
Table nom / valeur, deux expressions Java : "Authorization" / "Bearer " + context.token. Un nom donné deux fois ne garde que la dernière valeur.
name / value table, two Java expressions: "Authorization" / "Bearer " + context.token. A name given twice only keeps the last value.
|
| Corps HTTPHTTP BodyBODY | "" |
PATCH, POST, PUT |
Corps de la requête, expression Java (chaîne, concaténation, variable) : "{\"name\":\"Ada\"}". Envoyé en UTF-8, avec Content-Type: application/json si les en-têtes n'en donnent pas. Les sauts de ligne du champ sont remplacés par des espaces à la génération : on peut écrire l'expression sur plusieurs lignes.
Body of the request, a Java expression (string, concatenation, variable): "{\"name\":\"Ada\"}". Sent as UTF-8, with Content-Type: application/json if the headers give none. The line breaks of the field are replaced with spaces at generation: the expression can be written over several lines.
|
| ColonneColumn | Type | Description |
|---|---|---|
Body | String | Corps de la réponse en texte, décodé avec le jeu de caractères annoncé par le serveur (UTF-8 s'il n'en annonce pas), décompressé s'il arrive en gzip. Aussi pour une réponse en erreur. Nul pour une réponse 204.Body of the response as text, decoded with the character set announced by the server (UTF-8 if it announces none), decompressed if it arrives in gzip. Also for an error response. Null for a 204 response. |
ERROR_CODE | Integer | Nul pour un succès ; le code de la réponse à partir de 300, et pour 204.Null for a success; the code of the response from 300 on, and for 204. |
RETURN_CODE | Integer | Toujours le code de la réponse. Colonne de Talaxie 9.0.6 : un job dont le schéma n'a que Body et ERROR_CODE s'exécute sans changement.Always the code of the response. Column of Talaxie 9.0.6: a job whose schema only has Body and ERROR_CODE runs unchanged. |
ERROR_CODE suit l'ancien tREST de Talend (bibliothèque Jersey 1), qui levait une erreur à partir de 300, et sur la lecture d'une réponse 204 sans contenu. Pour savoir si l'appel a réussi, RETURN_CODE < 300 est plus simple.
ERROR_CODE follows the old tREST of Talend (Jersey 1 library), which raised an error from 300 on, and on reading a 204 response with no content. To know whether the call succeeded, RETURN_CODE < 300 is simpler.
Ce qu'a donné chaque réponse du serveur d'essai, en ligne de sortie (Body|ERROR_CODE|RETURN_CODE) et dans ERROR_MESSAGE. Le job s'est terminé avec le code 0 dans tous ces cas.
What each response of the test server gave, as an output row (Body|ERROR_CODE|RETURN_CODE) and in ERROR_MESSAGE. The job ended with code 0 in all these cases.
| RéponseResponse | Body | ERROR_CODE | RETURN_CODE | ERROR_MESSAGE |
|---|---|---|---|---|
| 200, 201 | le corpsthe body | nulnull | 200, 201 | inchangéunchanged |
| 204 | nulnull | 204 | 204 | inchangéunchanged |
| 302 à un POST (non suivie)302 to a POST (not followed) | le corpsthe body | 302 | 302 | inchangéunchanged |
| 404, 500 | le corps de l'erreurthe body of the error | 404, 500 | 404, 500 | le corps de l'erreurthe body of the error |
Une réponse 302 à un GET est suivie : la ligne porte la réponse de la nouvelle adresse (200). Le client ne suit pas une redirection pour un POST, un PUT, un PATCH ou un DELETE. A 302 response to a GET is followed: the row carries the response of the new address (200). The client does not follow a redirect for a POST, a PUT, a PATCH or a DELETE.
Sorties copiées de l'exécution de jobs dans Talaxie (Java 21), contre un serveur HTTP d'essai sur 127.0.0.1:54525 ; son adresse /echo renvoie en texte la requête reçue. Le tLogRow affiche Body|ERROR_CODE|RETURN_CODE : le corps reçu finit par un saut de ligne, si bien que la fin de la ligne (||200) passe à la ligne suivante. Le tJava affiche ERROR_MESSAGE.
Outputs copied from runs of jobs in Talaxie (Java 21), against a test HTTP server on 127.0.0.1:54525; its /echo address sends back as text the request received. The tLogRow displays Body|ERROR_CODE|RETURN_CODE: the body received ends with a line break, so the end of the row (||200) moves to the next line. The tJava displays ERROR_MESSAGE.
URL "http://127.0.0.1:54525/hello", le reste par défaut :URL "http://127.0.0.1:54525/hello", the rest by default:
Hello from the test server ||200 ERROR_MESSAGE=null
Journal du serveur :Log of the server:
[http] GET /hello HTTP/1.1 [http] Host: 127.0.0.1:54525 [http] Connection: Keep-Alive [http] User-Agent: Apache-HttpClient/4.5.13 (Java/21.0.12.1) [http] Accept-Encoding: gzip,deflate [http] -> 200 (27 bytes)
URL "…/echo", POST, Corps HTTP "{\"name\":\"Ada\",\"city\":\"Paris\"}", aucun en-tête :URL "…/echo", POST, HTTP Body "{\"name\":\"Ada\",\"city\":\"Paris\"}", no header:
method=POST
path=/echo
content-type=application/json
content-length=29
user-agent=Apache-HttpClient/4.5.13 (Java/21.0.12.1)
body={"name":"Ada","city":"Paris"}
||200
ERROR_MESSAGE=null
Le composant a ajouté Content-Type: application/json ; le corps part avec sa longueur. PATCH, avec "{\"city\":\"Lyon\"}", donne de même method=PATCH et content-type=application/json.
The component added Content-Type: application/json; the body leaves with its length. PATCH, with "{\"city\":\"Lyon\"}", likewise gives method=PATCH and content-type=application/json.
PUT, En-têtes HTTP "Content-Type" / "application/xml" et "X-Job" / "DocIA", Corps HTTP écrit sur trois lignes :PUT, HTTP Headers "Content-Type" / "application/xml" and "X-Job" / "DocIA", HTTP Body written over three lines:
"<client>" +
"<name>Ada</name>" +
"</client>"
method=PUT path=/echo content-type=application/xml content-length=33 user-agent=Apache-HttpClient/4.5.13 (Java/21.0.12.1) x-job=DocIA body=<client><name>Ada</name></client> ||200 ERROR_MESSAGE=null
GET, En-têtes HTTP "Accept" / "application/json" puis "Authorization" / "Bearer my-token". Journal du serveur :GET, HTTP Headers "Accept" / "application/json" then "Authorization" / "Bearer my-token". Log of the server:
[http] GET /echo HTTP/1.1 [http] Authorization: Bearer my-token [http] Accept: application/json [http] Host: 127.0.0.1:54525 [http] Connection: Keep-Alive [http] User-Agent: Apache-HttpClient/4.5.13 (Java/21.0.12.1) [http] Accept-Encoding: gzip,deflate [http] -> 200 (135 bytes)
Les en-têtes ne partent pas dans l'ordre de la table : le composant les range dans une table de hachage. The headers do not leave in the order of the table: the component stores them in a hash table.
URL "…/status/404" :URL "…/status/404":
Status 404 from the test server |404|404 ERROR_MESSAGE=Status 404 from the test server
Le corps de l'erreur arrive dans Body et dans ERROR_MESSAGE ; le job continue et se termine avec le code 0.
The body of the error arrives in Body and in ERROR_MESSAGE; the job goes on and ends with code 0.
URL "…/status/204", DELETE :URL "…/status/204", DELETE:
|204|204 ERROR_MESSAGE=null
Body est nul et ERROR_CODE vaut 204, bien que l'appel ait réussi.
Body is null and ERROR_CODE is 204, although the call succeeded.
tLoop de 1 à 3, URL "http://127.0.0.1:54525/echo?id=" + globalMap.get("tLoop_1_CURRENT_VALUE") :tLoop from 1 to 3, URL "http://127.0.0.1:54525/echo?id=" + globalMap.get("tLoop_1_CURRENT_VALUE"):
method=GET path=/echo?id=1 user-agent=Apache-HttpClient/4.5.13 (Java/21.0.12.1) body= ||200 method=GET path=/echo?id=2 user-agent=Apache-HttpClient/4.5.13 (Java/21.0.12.1) body= ||200 method=GET path=/echo?id=3 user-agent=Apache-HttpClient/4.5.13 (Java/21.0.12.1) body= ||200
POST vers "…/redirect/302?to=/hello", qui répond 302 vers /hello. La redirection n'est pas suivie :POST to "…/redirect/302?to=/hello", which answers 302 to /hello. The redirect is not followed:
Moved to /hello |302|302 ERROR_MESSAGE=null
En GET, la même adresse donne la réponse de /hello : Hello from the test server, ||200.
In GET, the same address gives the response of /hello: Hello from the test server, ||200.
Le composant n'a pas d'option Arrêter en cas d'erreur. Une réponse HTTP, quel que soit son code, n'est jamais une erreur ; une panne (serveur injoignable, certificat refusé, URL vide) en est toujours une : le job s'arrête avec le code 1, sauf si un lien On Component Error la reprend (le job s'est alors terminé avec le code 0). The component has no Die on error option. An HTTP response, whatever its code, is never an error; a failure (unreachable server, rejected certificate, empty URL) always is: the job stops with code 1, unless an On Component Error link takes it over (the job then ended with code 0).
Nom du job remplacé par MyJob, pile abrégée :Job name replaced with MyJob, shortened stack:
Exception in component tREST_1 (MyJob) org.apache.http.conn.HttpHostConnectException: Connect to 127.0.0.1:62110 [/127.0.0.1] failed: Connection refused: connect at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156) … Caused by: java.net.ConnectException: Connection refused: connect … On Component Error: ERROR_MESSAGE=Connect to 127.0.0.1:62110 [/127.0.0.1] failed: Connection refused: connect
Exception in component tREST_1 (MyJob) java.lang.IllegalArgumentException: url can't be empty! …
Levée avant l'appel : ERROR_MESSAGE n'est pas posée.Raised before the call: ERROR_MESSAGE is not set.
Exception in component tREST_1 (MyJob) javax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target …
Serveur HTTPS d'essai au certificat autosigné, sans tSetKeystore. Avec un tSetKeystore qui donne ce certificat, la même requête répond ||200.Test HTTPS server with a self-signed certificate, without tSetKeystore. With a tSetKeystore that gives this certificate, the same request answers ||200.
| VariableVariable | Type | Description |
|---|---|---|
ERROR_MESSAGE | String | Le corps de la dernière réponse 400 et plus, ou le message de l'exception d'une panne. Non déclarée par le composant (absente de la complétion), mais posée par le modèle. Gardée d'un appel à l'autre : une itération réussie ne l'efface pas.The body of the last response 400 and above, or the message of the exception of a failure. Not declared by the component (missing from the completion), but set by the template. Kept from one call to the next: a successful iteration does not clear it. |
((String) globalMap.get("tREST_1_ERROR_MESSAGE"))
Le client est Apache HttpClient 4.5. Il lit à chaque exécution le truststore et le keystore des propriétés javax.net.ssl.*, posées par un tSetKeystore ou par des arguments JVM (fichier et type tous deux). Il vérifie toujours que le certificat porte le nom de l'hôte de l'URL : l'option Vérifier l'identité du serveur du tSetKeystore ne le change pas.The client is Apache HttpClient 4.5. At each run it reads the truststore and the keystore of the javax.net.ssl.* properties, set by a tSetKeystore or by JVM arguments (file and type both). It always checks that the certificate bears the name of the host of the URL: the Check server identity option of the tSetKeystore does not change it.
Le composant n'a pas d'option de proxy et son client ne lit pas les propriétés système : un tSetProxy n'a eu aucun effet, l'appel est parti directement vers le serveur. Derrière un proxy obligatoire, utilisez tRESTClient (options de proxy) ou tHttpRequest.The component has no proxy option and its client does not read the system properties: a tSetProxy had no effect, the call went directly to the server. Behind a mandatory proxy, use tRESTClient (proxy options) or tHttpRequest.
Une réponse 404 ou 500 donne une ligne normale, son corps dans Body, et le job se termine avec le code 0. Filtrez sur RETURN_CODE (par exemple avec un tFilterRow) avant d'exploiter le corps.A 404 or 500 response gives a normal row, its body in Body, and the job ends with code 0. Filter on RETURN_CODE (for instance with a tFilterRow) before using the body.
Héritage de l'ancien composant : une réponse 204 (sans contenu) remplit ERROR_CODE et laisse Body nul. Un test ERROR_CODE == null la compte comme une erreur ; testez RETURN_CODE.Legacy of the old component: a 204 response (no content) fills ERROR_CODE and leaves Body null. An ERROR_CODE == null test counts it as an error; test RETURN_CODE.
Aucun délai de connexion ni de lecture ne se règle : le client garde ses valeurs par défaut, sans limite d'après la bibliothèque. Un serveur qui ne répond pas bloque le job.No connection or read timeout can be set: the client keeps its default values, without limit according to the library. A server that does not answer blocks the job.
Les guillemets d'un JSON s'échappent : "{\"name\":\"" + context.name + "\"}". Une valeur qui contient elle-même des guillemets casse le JSON ; construisez-le plutôt dans un tJava ou un tWriteJSONField, puis passez-le par une variable.The quotes of a JSON are escaped: "{\"name\":\"" + context.name + "\"}". A value that itself contains quotes breaks the JSON; build it rather in a tJava or a tWriteJSONField, then pass it through a variable.
tRESTClient · client REST complet, un appel par lignefull REST client, one call per rowtHttpRequest · GET ou POST, corps lu dans un fichierGET or POST, body read from a filetExtractJSONFields · découper une réponse JSONsplit a JSON responsetSetKeystore · certificats pour HTTPScertificates for HTTPStLoop · répéter l'appelrepeat the calltLogCatcher · capter les pannescatch the failures