aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suca/SotonCalendarFetcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suca/SotonCalendarFetcher.java')
-rw-r--r--src/net/cbaines/suca/SotonCalendarFetcher.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/net/cbaines/suca/SotonCalendarFetcher.java b/src/net/cbaines/suca/SotonCalendarFetcher.java
index 846faf1..370bf33 100644
--- a/src/net/cbaines/suca/SotonCalendarFetcher.java
+++ b/src/net/cbaines/suca/SotonCalendarFetcher.java
@@ -23,17 +23,23 @@ import org.apache.http.protocol.HTTP;
public class SotonCalendarFetcher {
private String username;
- private String password;
+ private char[] password;
- public SotonCalendarFetcher(String username, String password) {
+ public SotonCalendarFetcher(String username, char[] password) {
this.username = username;
this.password = password;
+ // for (int i = 0; i < password.length; i++) {
+ // password[i] = 0;
+ // }
}
@SuppressWarnings("deprecation")
public String fetchAndParseTimetable() throws IOException, LoginException {
+ if (username == null) {
+ throw new RuntimeException("Username null, or method called more than once.");
+ }
+
DefaultHttpClient httpclient = new DefaultHttpClient();
- Exception exception = null;
try {
HttpGet httpget = new HttpGet("https://www.adminservices.soton.ac.uk/adminweb/servlet/login");
@@ -61,9 +67,13 @@ public class SotonCalendarFetcher {
HttpPost httpost = new HttpPost("https://www.adminservices.soton.ac.uk/adminweb/servlet/login");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+ System.out.println(username + " " + String.valueOf(password));
nvps.add(new BasicNameValuePair("user", username));
- nvps.add(new BasicNameValuePair("pwd", password));
- System.out.println(username + password);
+ nvps.add(new BasicNameValuePair("pwd", String.valueOf(password)));
+ for (int i = 0; i < password.length; i++) {
+ password[i] = 0;
+ }
+ username = null;
httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
@@ -162,22 +172,13 @@ public class SotonCalendarFetcher {
return responseString;
} catch (IOException e) {
- exception = e;
+ httpclient.getConnectionManager().shutdown();
+ throw e;
} catch (LoginException e) {
- exception = e;
+ httpclient.getConnectionManager().shutdown();
+ throw e;
} finally {
- if (exception != null) {
- if (exception instanceof IOException) {
- throw (IOException) exception;
- } else if (exception instanceof IOException) {
- throw (LoginException) exception;
- }
- }
- // When HttpClient instance is no longer needed,
- // shut down the connection manager to ensure
- // immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
- return null;
}
}