public class APIClient {
public static String getDataFromAPI(String apiUrl) throws Exception {
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}
}
```
在Kettle中,可以通过"User Defined Java Class"步骤来调用上述Java代码,并将获取的数据传递给后续的转换步骤进行处理。