tJava, Error: InputStreamReader cannot be resolved to type

Highlighted
Four Stars

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.

2019 GARTNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now