One Star

[resolved] tRestRequest - parameters are not passed

Hello,
I have a Talend Job that begins with a tRestRequest component. I am having problems with the parameters because they cannot be set, meaning 0 rows are sent to it whenever I try to run it (image1). The job has multiple contexts (image2) and when I tried testing it on a default-context job with only the beginning context (image3), it was able to pass the parameters (image4). Is there something I am missing? I am testing the Rest with Postman and Google Chrome if that helps.
Please see screenshots below.
image1 - original job with 0 parameters row passed when tested

image2 - original job contexts

image3 - test job with 1 parameter row passed when tested

image4 - test job contexts

Best Regards,
12 REPLIES
One Star

Re: [resolved] tRestRequest - parameters are not passed

UPDATE: I have tried deactivating all components and activating them one at a time, I found out that once I activa the tOracelSP component, the job is not able to pass a row from the REST request. Is this because of its connection to the database? Screenshot below:
Fifteen Stars

Re: [resolved] tRestRequest - parameters are not passed

Hi Junmilsso,
You need to give us more information I am afraid. Is there an error stack in the output? Can you tell us how you are calling the service? Can you show us how the tRestRequest is configured?
One thing I have immediately spotted is that you are using a prejob component to start your connection. This is a service and as such will be "always on". Leaving the connection on from the beginning like this could cause you problems because it will only be used when you first switch the service on. The service could be running for months and the connection will not be renewed during that time. A better way is to have the connection instantiated for every call, an even better way is to use connection pooling with the "specify a data source alias" option in the connection component. That requires configuration inside Apache Karaf however.
You will also likely experience problems if the service is not closed with a tRestResponse component.
But before you look into that, can you give us the info I mentioned at the top?
 
Rilhia Solutions
One Star

Re: [resolved] tRestRequest - parameters are not passed

Hello rhall_2.0,
Thanks for your feedback, here are some more information regarding my problem:
Yes there is an error stacks, it mentions a NullPointerException since the parameters werent passed, thus showing 0 rows in the connection when I run it, causing no values to be usable by the tOracleSP component. Please see error stack below:
Starting job MUP_CreateSIDB003_job at 13:58 26/11/2015.
connecting to socket on port 3555
connected
: org.apache.cxf.endpoint.ServerImpl - Setting the server's publish address to be http://127.0.0.1:8090/REST/inv/sidb003_mupro
: org.eclipse.jetty.server.Server - jetty-8.1.14.v20131031
: org.eclipse.jetty.server.AbstractConnector - Started SelectChannelConnector@127.0.0.1:8090
Exception in component tOracleSP_1
java.lang.NullPointerException
at avemor_demo.mup_createsidb003_job_0_1.MUP_CreateSIDB003_job.tRESTRequest_1_LoopProcess(MUP_CreateSIDB003_job.java:1589)
at avemor_demo.mup_createsidb003_job_0_1.MUP_CreateSIDB003_job$RestServiceProviderImpl4TalendJob.processRequest(MUP_CreateSIDB003_job.java:582)
at avemor_demo.mup_createsidb003_job_0_1.MUP_CreateSIDB003_job$RestServiceProviderImpl4TalendJob.mupro(MUP_CreateSIDB003_job.java:688)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:188)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:104)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:204)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:101)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:94)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:355)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:319)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:65)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1088)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1024)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:255)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:370)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)
at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:667)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)
at java.lang.Thread.run(Unknown Source)
Job MUP_CreateSIDB003_job ended at 13:58 26/11/2015.


I have tested calling the service through Google Chrome and Postman, with this syntax:
    
         127.0.0.1:8090/REST/inv/sidb003_mupro?messageid=3000153933&uuid=666034
My tRESTRequest has been configured as follows:
          
What could be the reason why the parameters were not passed? When I deactivated the tOracleSP and the succeeding components, the parameter was passed and I could do anything with it in the tJavaRow component (assign to a variable, print out, etc.).
Fifteen Stars

Re: [resolved] tRestRequest - parameters are not passed

OK, you need to configure your "URI Pattern" to something like this.....
"/{messageid}/{uuid}"


....and you need to call the service like this.....
"http://127.0.0.1:8090/REST/inv/sidb003_mupro/3000153933/666034"

The URI Pattern needs to show how and where your parameters will sit in the URI. They parameter names you use in your  flow schema must be surrounded by curly brackets in the URI Pattern. 
Rilhia Solutions
One Star

Re: [resolved] tRestRequest - parameters are not passed

Thanks for the suggestion,
I have already set it but it shows the same error. Also, my previous settings were able to pass the parameters whenever I deactivate the tOracleSP component, was that the reason?
The problem is not how I passed the parameters. The problem is that whenever the tOracleSP component after the tJavaRow is activated, 0 rows are passed to the job from the REST call. If I deactivate it, the row and parameters get passed.
Fifteen Stars

Re: [resolved] tRestRequest - parameters are not passed

I'm curious, have you actually seen evidence that the parameters have been passed into the service? Can you print them out to the execution output using a tLogRow? 
Also, can you post your tOracleSP settings? 
Rilhia Solutions
One Star

Re: [resolved] tRestRequest - parameters are not passed

Yes there is a 1 row in x seconds if I deactivate the tOracleSP, and I can print it using the "input_row.variable":

If I activate the tOracleSP, 0 rows in x seconds get passed:

Lastly, here are my tOracleSP settings:
Fifteen Stars

Re: [resolved] tRestRequest - parameters are not passed

I've just had a thought, how are you passing the data on in the tJavaFlex component? This could be as simple as the data simply not being passed to the tOracleSP component. 
Rilhia Solutions
One Star

Re: [resolved] tRestRequest - parameters are not passed

Here's my code:
row3.messageid = mupro.messageid;
row3.uuid = mupro.uuid;
System.out.println("messageid = " + row3.messageid);
System.out.println("uuid = " + row3.uuid);
One Star

Re: [resolved] tRestRequest - parameters are not passed

PROBLEM HAS BEEN SOLVED

I found out that I had to remove the tOracleConnection in the tPreJob, removing the whole prejob chain completely. Each tOracle component had to make its own connection. Now the job works.
Thanks so much for your help, your mentioning of the oracle connection led me to try making the components connect themselves.
Fifteen Stars

Re: [resolved] tRestRequest - parameters are not passed

This is a bit tricky without actually having the service here, so sorry about not having a definite answer. This is the sort of problem where I would have to hack around trying a few things.
I'm now thinking that this could be connected to the connection connected to the tPreJob. Can you try and configure the tOracleSP component to have its own connection? By that I mean, remove the connection component and allow the tOracleSP to connect itself. 
The reason I think this is that the connection component's connection is stored in a globalMap variable. I believe the tRestRequest component creates another globalMap for each service request. This allows concurrent requests to be processed individually without overlap. I *think* that what is happening is that the connection is being cleared and since it is not created for every service call, when you get the first call it is wiped and the tOracleSP cannot make a connection.
This might be completely wrong, but it is worth trying. As I said in an earlier post, tPreJob and tPostJob components are really meant for batch jobs rather than services.
Edit: After posting this, I noticed you had come to the same conclusion. Note to self, refresh pages before responding to the last message, d'oh!! Glad you sorted it. 
Rilhia Solutions
One Star

Re: [resolved] tRestRequest - parameters are not passed

I was a bit confused when I started reading your reply, glad I saw that "Edit:" section afterwards.
Yep I got it sorted out, thanks for all the help and it was a good idea to have tried the individual connections instead of a prejob connection.