Hi All
I am a peoplesoft developer and I dont understand JSP too well . I have following two questions about the code below .
1) Are we using a POST call to
https://SomeUrl/ssoreq.asp (not a GET
request) ?
2) Are we assigning the content-length and content-type header
variables prior to executing the POST call ? ...
Quick responses would be highly appreciated . Thanks
<HTML>
<HEAD>
<TITLE>Single Signon</TITLE>
</HEAD>
<BODY>
<P STYLE="color: blue; font-family: 'Tahoma', serif; font-size: small">
<%@ page import="java.io.*, java.net.*, java.util.*" %>
<%
// Obtain Employee ID via PeopleSoft Cookie "SignOnDefault"
Cookie []cookiejar = request.getCookies();
String D = "";
for (int i=0 ; i < cookiejar.length ; i++)
{
//out.println(cookiejar[i].getName() + " = " + cookiejar[i].getValue() + " <BR>" );
if ((cookiejar[i].getName()).trim().equals("SignOnDef ault"))
D = cookiejar[i].getValue();
}
String RC = "";
String TARGETSITE = "";
try
{
URL url = new URL("https://SomeUrl/ssoreq.asp");
URLConnection con = url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
String msg = "";
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Content-Length", "" + msg.length()); // Not checked
con.setRequestProperty("A", "A");
con.setRequestProperty("B", "B");
con.setRequestProperty("C", "C");
con.setRequestProperty("D", D);
//System.out.println("Getting an output stream...");
OutputStream os = con.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
osw.write(msg);
/** REMEMBER THIS osw.flush(); **/
osw.flush();
osw.close();
// Get RC and TARGETSITE HTTP Header vars
RC = con.getHeaderField("RC");
TARGETSITE = con.getHeaderField("TARGETSITE");
if (RC == null) RC = "-1";
// cleanup
con = null;
} catch (Throwable t)
{
response.sendRedirect("./errorpage.jsp?JException=" + java.net.URLEncoder.encode(t.toString()));
}
try
{
if ( RC.equals("0") )
{
response.sendRedirect(TARGETSITE);
}
else
response.sendRedirect("./errorpage.jsp?RC=" + RC);
} catch (Throwable t)
{
response.sendRedirect("./errorpage.jsp?JException=" + java.net.URLEncoder.encode(t.toString()));
}
%>
</P>
</BODY></HTML