Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Write Table now available in Qlik Cloud Analytics: Read Blog
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tJava, Error: InputStreamReader cannot be resolved to type

Hi all,

Two weeks ago I started to work with Talend and this community was very helpful to me. Big thanks to everyone.

I tried everything with problem I have before posting here so this is my last resort.

 

My intention is to send messages from Talend to Slack using Webhook. Webhook is set up and tested with:

curl -X POST -H 'Content-type: application/json' --data '{"text":"Hello, World!"}' <my_Webhook_link>

For sending message to Slack from Talend I used tJava component with code as follows:

String strSlackPayload ="{";
strSlackPayload += "\"text\": \"";
strSlackPayload += "Message from Talend. Test 1,2,3...";
strSlackPayload += "\"}";
String line;
StringBuffer jsonString = new StringBuffer();
String urly = "<my_Webhook_link>";
URL obj = new URL(urly);
//escape the double quotes in json string
String payload=strSlackPayload;
HttpURLConnection connection = (HttpURLConnection) obj.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "UTF-8");
writer.write(payload);
writer.close();
BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((line = br.readLine()) != null) {
    jsonString.append(line);
}
br.close();
connection.disconnect();

I got most of the code from this nice blog post.

 

Problem is that I am getting error InputStreamReader cannot be resolved to type.

People with Java experience suggested me to add

import java.io.InputStreamReader;

to code but it didn't help.

It looks like when executing Java through Talend InputStreamReader function does not exist.

 

Thank you for your feedback.

Labels (3)
2 Replies
Anonymous
Not applicable
Author

Hi @poslanik 

Did you fix the problem ? 

I have exactly the same.

 

 

 

 

Anonymous
Not applicable
Author

Hi @ris.tan ,

As a matter of fact I did solve the problem using tRest Talend component.

In tRest component input values as follows.

 

URL -> put your Webhook link surrounded with double quotes

HTTP Headers -> "Content-type"    "application/json"

                              "Accept"             "application/json"

HTTP Body -> example below

"{
\"text\":\"Talend: Data quality check performed at "+context.vCurrentTimestamp+" on "+context.vSchemaName+"."+context.vStagingObjectName+" object returned *"+((Integer)globalMap.get("glbCntSeverity1"))+"* record(s) with severity Reject :helmet_with_white_cross: and *"+((Integer)globalMap.get("glbCntSeverity2"))+"* record(s) with severity Warning :warning:\"
}"

 

If you have additional questions, I am here.