Now let’s start with consumption of SharePoint REST service using GET Method
Here we need input as SharePoint accessToken String which can be found from previous blog [Part-1] UDF to Get Access Token
In blow Java UDF example, SharePoint AlertCount List is been fetched by consuming respective SharePoint REST service.
//—————————————————————————————————-
String outputString = "";
try{
//SharePoint url to fetch AlertCount List
String wsURL = "https://<client-Domain>.sharepoint.com/teams/SPdev/AlertsCount/_api/web/Lists/GetByTitle('AlertCount')";
//Create HttpConnection
URL url = new URL(wsURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
//Set Header
//Get accessToken is output of UDF-1 from blog "Call SharePoint REST Service in SAP-PI: [Part-1] UDF to Get Access Token"
String basicAuth = "Bearer " + accessToken;
httpConn.setRequestProperty("Authorization", basicAuth);
httpConn.setRequestMethod("GET");
httpConn.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
// Read the response.
InputStreamReader isr = null;
if (httpConn.getResponseCode() == 200) {
isr = new InputStreamReader(httpConn.getInputStream());
} else {
isr = new InputStreamReader(httpConn.getErrorStream());
}
BufferedReader in = new BufferedReader(isr);
String responseString = "";
// Write response to a String.
while ((responseString = in.readLine()) != null) {
outputString = outputString + responseString;
}
}catch (Exception e) {
e.printStackTrace();
}
return outputString;
//----------------------------------------------------------------------------------------------------