Skip to content

Commit

Permalink
Fix symbol password failure via OkHTTP.
Browse files Browse the repository at this point in the history
Fix close warning by OkHTTP.
  • Loading branch information
zhehuaz committed Mar 1, 2016
1 parent 814968c commit 22eb846
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
40 changes: 25 additions & 15 deletions app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,56 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/debug" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/cardview-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/palette-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/preference-v14/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/preference-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/io.reactivex/rxandroid/1.0.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="rxandroid-1.0.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="design-23.1.1" level="project" />
<orderEntry type="library" exported="" name="eventbus-3.0.0-beta1" level="project" />
<orderEntry type="library" exported="" name="rxjava-1.0.14" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="palette-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="preference-v14-23.1.1" level="project" />
<orderEntry type="library" exported="" name="okio-1.6.0" level="project" />
<orderEntry type="library" exported="" name="eventbus-annotation-processor-3.0.0-beta1" level="project" />
<orderEntry type="library" exported="" name="gson-2.4" level="project" />
<orderEntry type="library" exported="" name="jsoup-1.8.3" level="project" />
<orderEntry type="library" exported="" name="okhttp-2.7.1" level="project" />
<orderEntry type="library" exported="" name="eventbus-annotation-processor-3.0.0-beta1" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="eventbus-3.0.0" level="project" />
<orderEntry type="library" exported="" name="gson-2.4" level="project" />
<orderEntry type="library" exported="" name="eventbus-3.0.0-beta1" level="project" />
<orderEntry type="library" exported="" name="preference-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="rxandroid-1.0.1" level="project" />
<orderEntry type="library" exported="" name="preference-v14-23.1.1" level="project" />
<orderEntry type="library" exported="" name="okhttp-2.7.1" level="project" />
<orderEntry type="library" exported="" name="eventbus-3.0.0" level="project" />
<orderEntry type="library" exported="" name="design-23.1.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="rxjava-1.0.14" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="module" module-name="uilibrary" exported="" />
</component>
</module>
17 changes: 12 additions & 5 deletions app/src/main/java/me/zchang/onchart/session/BitJwcSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.greenrobot.eventbus.EventBus;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void run() {
RequestBody formBody = new FormEncodingBuilder()
.add("__VIEWSTATE", "dDwtMjEzNzcwMzMxNTs7Pj9pP88cTsuxYpAH69XV04GPpkse")
.add("TextBox1", stuNum)
.add("TextBox2", pswToUnicode(psw))
.add("TextBox2", psw)
.add("RadioButtonList1", "%D1%A7%C9%FA")
.add("Button1", "+%B5%C7+%C2%BC+")
.build();
Expand All @@ -91,6 +92,7 @@ public void run() {
homeRequest = homeRequest.newBuilder().addHeader("Referer", loginUrl).build();
Response homePage = httpClient.newCall(homeRequest).execute();
startResponse = homePage.body().string();
homePage.body().close();
stuName = fetchName();
if (stuName != null) {// name detected, as good as account validation.
isStarted = true;
Expand Down Expand Up @@ -130,6 +132,7 @@ public void run() {
EventBus.getDefault().post(
new ScheduleFetchOverEvent(StudentInfoParser.parseCourses(scheduleResponse.body().string()), "default")
);
scheduleResponse.body().close();
Log.i(MainActivity.TAG, "post schedule fetch over");
}
} catch (IOException e) {
Expand Down Expand Up @@ -177,6 +180,7 @@ public void call(Subscriber<? super Map<String, String>> subscriber) {
subscriber.onNext(
StudentInfoParser.parseParamsInCoursePage(scheduleResponse.body().string())
);
scheduleResponse.body().close();
}
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -211,6 +215,7 @@ public void call(Subscriber<? super String> subscriber) {
Log.i(TAG, "fetch schedule request sent");
Response response = httpClient.newCall(scheduleRequest).execute();
subscriber.onNext(response.body().string());
response.body().close();
subscriber.onCompleted();
} catch (IOException e) {
e.printStackTrace();
Expand Down Expand Up @@ -264,6 +269,7 @@ public void run() {
weekResponse = httpClient.newCall(request).execute();
if (weekResponse.isSuccessful()) {
EventBus.getDefault().post(new HomepageFetchOverEvent(StudentInfoParser.parseWeek(weekResponse.body().string())));
weekResponse.body().close();
}
} catch (IOException e) {
EventBus.getDefault().post(new SessionErrorEvent(ErrorCode.SESSION_EC_FETCH_WEEK));
Expand Down Expand Up @@ -298,6 +304,7 @@ public List<Exam> fetchExams() throws IOException {
Response examResponse = httpClient.newCall(request).execute();
if (examResponse.isSuccessful()) {
String htmlRes = examResponse.body().string();
examResponse.body().close();
return StudentInfoParser.parseExams(htmlRes);
}
return new ArrayList<>();
Expand All @@ -309,20 +316,20 @@ public List<Exam> fetchExams() throws IOException {
* @return coverted password
*/
public String pswToUnicode(String psw) {
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
int length = psw.length();
char c;
int temp;
for (int i = 0;i < length;i ++) {
c = psw.charAt(i);
if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c <= 'a' && c >= 'z')) {
if((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c <= 'a' && c >= 'z')
|| c == '*' || c == '_' || c == '-' || c == '.') {
sb.append(c);
} else {
temp = c;
sb.append("%" + String.format("%x", temp));
sb.append("%").append(String.format("%x", temp).toUpperCase());
}
}

return sb.toString();
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/me/zchang/onchart/session/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public enum ErrorCode {
SESSION_EC_INVALID_ACCOUNT,
SESSION_EC_FETCH_SCHEDULE,
SESSION_EC_FETCH_EXAM,
SESSION_EC_FETCH_WEEK
SESSION_EC_FETCH_WEEK,
SESSION_EC_SOCKET_TIMEOUT
}

public String getStuNum() {
Expand Down

0 comments on commit 22eb846

Please sign in to comment.