Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello community,
I would like to create a REST request with the following parameters int Talend. Which component should I use and how to pass parameters to this component (body)? I have all necessary metadata on an input edge, need to transform somehow to body/string parameter and add definition for file to upload (path on the edge).
I have used tRestClient :
and I used tRest :
Any Help please
@
@richard Hall
Thank you.
OK, this is going to take some trial and error I'm afraid. First of all, the repository_id and type_id are both form properties, so do not go in the header. They are also both of type integer and not String. We'll ignore the metadata until we get rid of the repository_id error. Can set the repository_id and type_id params to be integers (remove the double quotes) and see what that returns please?
I've already tried that, but the param mehode doesn't allow integer as a values.
I've just noticed something that makes me think part of your problem is caused by something else in your job failing. This image here......
Shows a nullpointerexception that is not necessarily linked to your tRestClient. The URL at the top of the sys out suggests that you have a tRestRequest in this job somewhere. Can you show the whole job and show the whole of the error messages you get in text please?
here the job,
First I've used tRequest to get file and params,
as you see here, I've got the file in my local repo through Postman Request:
And then i get the NullPointerException in tRestClient .
For me it's the first time that i handle a Post file through an API that why i didn't catch exactly the prob 😟
" Démarrage du job WS_GED_POST_TEST a 11:23 30/11/2021.
Endpoint deployed at: http://127.0.0.1:8040/api/v1/documents
[statistics] connecting to socket on port 3394
[statistics] connected
Exception in component tRESTClient_2 (WS_GED_POST_TEST)
java.lang.NullPointerException
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTClient_2Process(WS_GED_POST_TEST.java:3057)
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTRequest_1_LoopProcess(WS_GED_POST_TEST.java:4721)
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.processRequest(WS_GED_POST_TEST.java:714)
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.Request(WS_GED_POST_TEST.java:813)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:193)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:103)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:247)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:79)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:205)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:505)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)
at java.lang.Thread.run(Thread.java:748)
[FATAL]: inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST - tRESTClient_2 null
java.lang.NullPointerException
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTClient_2Process(WS_GED_POST_TEST.java:3057)
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST.tRESTRequest_1_LoopProcess(WS_GED_POST_TEST.java:4721)
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.processRequest(WS_GED_POST_TEST.java:714)
at inter_application.ws_ged_post_test_0_1.WS_GED_POST_TEST$RestServiceProviderImpl4TalendJob.Request(WS_GED_POST_TEST.java:813)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:193)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:103)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:267)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:247)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:79)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1345)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:205)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1247)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:220)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:505)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:370)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:267)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:698)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:804)
at java.lang.Thread.run(Thread.java:748)"
Can you remove all of the other components (maybe create another job) and just add the tRestClient with a tLogRow. Without access to your Job I can't identify what is causing the NullPointerException. You may be able to find this by looking at the code line numbers in the error and looking at the Java. If you can understand Java, this may be quite easy.
But to remove any other possible causes for the nullpointerexception, we need to get back to just the tRestClient and the tLogRow (on both response and error outputs).
Here we have only the component in another Job:
and as mentionned here the prob in ligne 1338 which refers to our params in multipart accepter type:
I've changed the Accepter-type to All and as you see it detect the repository_id and the file is as always missing 😞
I've even tried to integrate the File in the header and i didn't work either.
I think that with tRest and tRestClient we couldn't pass file as a param .
have you another point of view or proposition please ?
Thanks 🙂
Right, so it appears that you are just missing the file now. This is good. I suspected that the file name would not work. Unfortunately, since I do not have access to this API I cannot try anything out myself. When working with APIs it usually takes a few attempts to get the calls correct.
Move the file param back to the parameters and wrap the path to the file in this routine method.....
package routines;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.apache.commons.codec.binary.Base64;
public class Base64File {
public static String encodeFileToBase64Binary(String filePath) throws IOException {
byte[] encoded = Base64.encodeBase64(Files.readAllBytes(filePath));
return new String(encoded, StandardCharsets.UTF_8);
}
}
.....this is to provide the contents of the file in Base64 which could be what your API is expecting.
What is the name of the software providing the API you are using? Is it something that I might be able to get a copy of so that I can try somethings out? It would make it much easier to be able to examine the errors ad tweak the config for myself.
I don't think that, but i give it a try :
I tried it also through Postman but it didn't work:
As I mentionned before the API get a FILE as params
What software is exposing the API you are trying to send the file to?
Hello @Richard Hall @Xiaodi Shi
I have finally make this API.
I have used tFileFetch :
Here is my notes to close this case :
Thank you for your collaboration.
zied