Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Five Stars

Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Dear Community,

currently I am trying to send the output of tStatCatcher to a Graylog server via a REST API call. The data must be transferred to the API as a JSON string.

I have created the following process:
tStatCatcher -> tXMLMap -> tRESTClient

PlannedProcess.png

In the tXMLMap module, the fields are mapped to an XML structure. Finally, the tRESTClient should transmit the data via POST in JSON format. Otherwise, I have not made any other settings.

tXMLMap-Mapping:
Mapping.png

tRESTClient-Config:
RESTClient-Config.png

Unfortunately, when I run the tRESTClient I get an exception that I can't explain:

 

Exception in component tRESTClient_1 (SYNC_PARTY)
javax.ws.rs.ProcessingException: java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String
	at org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1148)
	at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1117)
	at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1042)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:895)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
	at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:426)
	at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:456)
	at trypartysync.sync_vodster_0_1.SYNC_PARTY.tStatCatcher_1Process(SYNC_PARTY.java:12007)
	at trypartysync.sync_vodster_0_1.SYNC_PARTY.runJobInTOS(SYNC_PARTY.java:12769)
	at trypartysync.sync_vodster_0_1.SYNC_PARTY.main(SYNC_PARTY.java:12613)
Caused by: java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String
	at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:394)
	at org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:524)
	at org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1129)
	... 9 more

Here is the relevant code:

 


code_error.png

Do you have an idea how I could solve it or what could be the cause of the problem?

Hopefully you have an idea. Otherwise I would try to make a system call with "curl". But that would just be a stupid workaround. It should only be possible to solve it with Talend.

Thanks in advance for you help.
Volker


Accepted Solutions
Sixteen Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

You do not need to assign a row value to the tRest. Take a look at here (https://help.talend.com/reader/iYcvdknuprDzYycT3WRU8w/_N82Hv0ivAnxD69EWaC5rA). You need to do a bit more work with the tRest, but you can use a tSetGlobalVar to store your computed JSON and add it to the HTTP Body using the globalMap. You can even test by hardcoding some JSON as a String.


All Replies
Sixteen Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

You are sending an XML document instead of a JSON String. The tRestClient can receive a body column (Document) and a string column (String). You need to produce a JSON string and supply it to the string column feeding the tRestClient. Everything else looks like it should be OK so long as you supply the correct content.

Five Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Dear Rhall,


thank you for your answer, but I have also tried that out without success.

The error message that I get is still the same:

 

Exception in component tRESTClient_2 (SYNC_PARTY)
javax.ws.rs.ProcessingException: java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : org.dom4j.Document
	at org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1148)
	at org.apache.cxf.jaxrs.client.WebClient.doResponse(WebClient.java:1117)
	at org.apache.cxf.jaxrs.client.WebClient.doChainedInvocation(WebClient.java:1042)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:895)
	at org.apache.cxf.jaxrs.client.WebClient.doInvoke(WebClient.java:863)
	at org.apache.cxf.jaxrs.client.WebClient.invoke(WebClient.java:426)
	at org.apache.cxf.jaxrs.client.WebClient.post(WebClient.java:456)
	at trypartysync.sync_vodster_0_1.SYNC_PARTY.tWriteJSONField_1_InProcess(SYNC_PARTY.java:10016)
	at trypartysync.sync_vodster_0_1.SYNC_PARTY$1ThreadXMLField_tWriteJSONField_1_Out.run(SYNC_PARTY.java:8925)
Caused by: java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : org.dom4j.Document
	at org.apache.cxf.jaxrs.impl.ResponseImpl.doReadEntity(ResponseImpl.java:394)
	at org.apache.cxf.jaxrs.client.AbstractClient.readBody(AbstractClient.java:524)
	at org.apache.cxf.jaxrs.client.WebClient.handleResponse(WebClient.java:1129)
	... 8 more

That is the process:

 

PlannedProcess_JSON-String.png

tWriteJSONField-Mapping.png

 

tWriteJSONField-Config2.png


Ausgabespalte (GERMAN) == Output Column

tWriteJSONField-Schema.png

Sixteen Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

This is very strange. You will notice that your error messages are slightly different. One complains about the lack of a String (in your first error when sending XML), the second complains about the lack of a Document (when you are sending a String). I have quickly knocked up a service with Talend to receive a JSON String and print out to the console. I then created a job like yours. I have not been able to recreate this problem. I would say that your second set up (sending the data to the string column as JSON) is correct given what you have said. 

 

What version of Talend are you using? I tested this with 6.2. Also, is there a public example of the web service you are using so I can see if I can recreate this? 

 

This *could* be a bug with Talend, but it also *could* be something to do with the response from the service you are calling. At the moment I just can't recreate the error message you are getting :-(

Five Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Thank you for confirming that this is a bug or error on my system. I have already spent a few hours with this problem and I was getting frustrated.

 

At the moment I am working with TOS 6.4.1 - but I will also try it with other versions. It could also be the library for the tRESTClient or Java's JRE. No connection with the REST services has been established so far, so I don't think there is a problem.

 

First of all, I'll try another TOS and JRE version to exclude these two possible sources of error.

As soon as I have tried this, I will get back to you.

Five Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

-- Double Post -- See next post

Five Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Well, I've identified the source of the error.


It is not due to Java and only indirectly to TOS. It is rather a chain of unfortunate circumstances :-)

I have published a GELF HTTP service via Graylog to receive JSON queries. There I can simply send any JSON string and it is passed on from the Graylog to Elasticsearch. So far so good.

 

You gave me the idea of taking a closer look. When I send data to the GELF HTTP service, there is an unfortunate problem: The service does not return any response string. The answer is simply empty.

But tRESTclient obviously expects a response from the REST API. The error message or exception does not refer to the input, but to the return value. In this respect, the GELF HTTP Service is not a fully-fledged REST API.

 

I have checked that the tRESTclient should not abort in case of an error. On the console, however, an error is inevitably still thrown out.

 

I don't see any need for action with the Graylog, because the GELF HTTP Service does not really represent a web service. Alternatively, I could of course also address the REST API from Elasticsearch. In addition, I could also ask Talend to issue the feature request that the tRESTclient can ignore the response if necessary.

 

Last alternative:
Is there a component in Talend as an alternative to tRESTclient with which I can send HTTP requests including a string as payload without expecting a response?

Sixteen Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

You could try the tREST component. That *might* work.

Five Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Unfortunately that does not work out as tREST does not accept input from the main flow.

Five Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String


rhall_2_0 wrote:

You are sending an XML document instead of a JSON String. The tRestClient can receive a body column (Document) and a string column (String). You need to produce a JSON string and supply it to the string column feeding the tRestClient.


For those who might be facing a similar challenge as I am, how to get JSON to a REST API service...

I would like to confirm briefly that this post was an important step towards the solution to send the data to a REST API service. You actually have to write the JSON string into the string field and use the tWriteJSONField accordingly. In my initial post I used tXMLMap, which is definitely wrong.

Sixteen Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

You do not need to assign a row value to the tRest. Take a look at here (https://help.talend.com/reader/iYcvdknuprDzYycT3WRU8w/_N82Hv0ivAnxD69EWaC5rA). You need to do a bit more work with the tRest, but you can use a tSetGlobalVar to store your computed JSON and add it to the HTTP Body using the globalMap. You can even test by hardcoding some JSON as a String.

Five Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Thanks to Rhall's last post, I've got it working like a charm now. Finally :-)
The statistics are protocolled to my Graylog Server with the help of the HTTP GELF input.

Here is the overview of the working configuration:

WorkingProcess.PNG

The OnComponentOk trigger starts tREST.

tWriteJSONField_Config.png

tWriteJSONField_Mapping.png


tWriteJSONField_Schema.png

tSetGlobalVar_Config.png

tREST_config.png

Thanks again, Rhall, for your help.

Sixteen Stars

Re: Getting tStatCatcher to Graylog with tRESTClient - java.lang.IllegalStateException: The entity is not backed by an input stream, entity class is : java.lang.String

Good work and thanks for doing the write up for others to use in the future