import java.net.*; import java.io.*; import java.util.Map; import java.util.Set; import java.util.Iterator; import java.util.StringTokenizer; /** * The TranscriptReciever class obtains HTTPS access to Dowling College's * Banner Database when given a student's user id and password, subsequently * providing streamed access to the transcript HTML. */ public class TranscriptReciever { /* private static final String LOGIN_ADDR = "https://ban4web.dowling.edu/prod/plsql/twgkwbis.P_WWWLogin"; private static final String VALDN_ADDR = "https://ban4web.dowling.edu/prod/plsql/twgkwbis.P_ValLogin"; private static final String TRANS_ADDR = "https://ban4web.dowling.edu/prod/plsql/hwskotrn.P_ViewTran"; */ private static final String LOGIN_ADDR = "https://bannerweb.dowling.edu/pls/PPOD/twgkwbis.P_WWWLogin"; private static final String VALDN_ADDR = "https://bannerweb.dowling.edu/pls/PPOD/twgkwbis.P_ValLogin"; private static final String TRANS_ADDR = "https://bannerweb.dowling.edu/pls/PPOD/hwskotrn.P_ViewTran"; private static final String LOGIN_COOK = "SESSID=; TESTID=set"; private static final String TRANS_POST = "levl=&tprt=STDT"; private URL url; private HttpURLConnection urlConn; private String cookie; /** * Constructs a TranscriptReciever object. */ public TranscriptReciever() { } // Some methods used in developing this class... /* private void printHeaderFields() { Map map = urlConn.getHeaderFields(); Set keySet = map.keySet(); Iterator iter = keySet.iterator(); while(iter.hasNext()) { Object key = iter.next(); System.out.println(key + " = " + map.get(key)); } } private void printContent() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader( urlConn.getInputStream())); String str; while((str=in.readLine()) != null) System.out.println(str); } */ private void parseCookie() { cookie = urlConn.getHeaderField("Set-Cookie"); /* cookie = ""; String allCookies = urlConn.getHeaderField("Set-Cookie"); int index = allCookies.indexOf(";"); System.out.println(allCookies); if(index >= 0) cookie = allCookies.substring(0, index); */ } private void login(String userId, String password) throws MalformedURLException, IOException { url = new URL(VALDN_ADDR); urlConn = (HttpURLConnection) url.openConnection(); urlConn.setRequestMethod("POST"); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(true); urlConn.setRequestProperty("Cookie", LOGIN_COOK); urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); DataOutputStream out = new DataOutputStream(urlConn.getOutputStream()); String content = "sid=" + URLEncoder.encode(userId, "UTF-8") + "&pin=" + URLEncoder.encode(password, "UTF-8"); out.writeBytes(content); out.flush(); out.close(); parseCookie(); } private InputStream getTranscriptHTML() throws MalformedURLException, IOException { url = new URL(TRANS_ADDR); urlConn = (HttpURLConnection) url.openConnection(); urlConn.setRequestMethod("POST"); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(true); urlConn.setRequestProperty("Cookie", cookie); urlConn.setRequestProperty("Content-Type", "text/html"); DataOutputStream out = new DataOutputStream(urlConn.getOutputStream()); out.writeBytes(TRANS_POST); out.flush(); out.close(); return urlConn.getInputStream(); } /** * Retrieves an InputStream to the student's transcript. The * InputStream simply returns the raw HTML without any sort of * preprocessing. * @param userId The student's userId for Banner. * @param password The student's password for Banner. * @return An InputStream to the transcript HTML * @exception IOException If a connection to Banner cannot be obtained. * @exception TranscriptException If the username and password was invalid. * @exception MalformedURLException If the addresses used internally to access Banner are malformed. */ public InputStream getTranscriptStream(String userId, String password) throws IOException, TranscriptException, MalformedURLException { login(userId, password); if(cookie == null) return null; InputStream in = getTranscriptHTML(); return in; } }