public static String getSessionIdJSONObject(String userName, String password, HashMap<String, String> lookupData) {
String methodName = "getSessionIdJSONObject";
LOGGER.debug(CLASS_NAME + "/" + methodName + "; userName = " + userName + "; password = " + password);
System.out.println(CLASS_NAME + "/" + methodName + "; userName = " + userName + "; password = " + password);
String WS_URL = null;
URL url = null;
String retVal = "SUCCESS";
StringBuffer response = null;
OutputStream os = null;
BufferedReader in = null;
try {
String webServiceParams = "{\"UserName\":\"" + userName + "\"" + " , \"Password\":\"" + password + "\"}";
System.out.println("webServiceParams : " + webServiceParams);
WS_URL = lookupData.get("SessionIdURL");
System.out.println("WebService URL :" + WS_URL);
url = new URL(WS_URL);
//url = new URL(null, WS_URL, new sun.net.www.protocol.https.Handler());
HttpsURLConnection postConnection = (HttpsURLConnection) url.openConnection();
postConnection.setRequestMethod("POST");
postConnection.setRequestProperty("Content-Type", "application/json");
postConnection.setDoOutput(true);
os = postConnection.getOutputStream();
os.write(webServiceParams.getBytes());
int responseCode = postConnection.getResponseCode();
System.out.println("POST Response Code : " + responseCode);
System.out.println("POST Response Message : " + postConnection.getResponseMessage());
if (responseCode == 200) { // success
in = new BufferedReader(new InputStreamReader(postConnection.getInputStream()));
String inputLine;
response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
// print result
System.out.println("JSON object is : " + response.toString());
LOGGER.debug("JSON object is : " + response.toString());
} else {
retVal = "FAIL";
System.out.println("Return value is : " + retVal);
System.out.println("POST NOT WORKED");
LOGGER.debug("Return value is : " + retVal);
LOGGER.debug("POST NOT WORKED");
}
}
catch (Exception e) {
System.out.println("Exception is : " + e.getMessage());
LOGGER.error("Exception is : " + e.getMessage());
e.printStackTrace();
} // End of Catch block
finally {
closeIOFile(os, in);
}
System.out.println("Return value is : " + retVal);
LOGGER.debug("Return value is : " + retVal);
System.out.println("Exiting from the method : " + methodName);
LOGGER.debug("Exiting from the method : " + methodName);
return response.toString();
}
NOTE :
Ex: SessionIdURL = "https://oimsailpointpedia.blogspot.com/search/label/Java";
No comments:
Post a Comment