Skip to content

Commit

Permalink
finished add task method and get-status method
Browse files Browse the repository at this point in the history
  • Loading branch information
duguying committed Feb 14, 2015
1 parent c61854e commit f7ddcbe
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# idea
/.idea/
*.iml

# output
/out/
/target/

# mac
.DS_Store

72 changes: 61 additions & 11 deletions src/main/java/net/duguying/goj/JudgerHTTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public JudgerHTTP(String host, int port, String password) {

this.url = "http://" + host + ":" + port;

this.login = this.Login(this.password);
this.login = this.Login();

}

Expand All @@ -61,10 +61,9 @@ private String Post(String content) throws IOException {
/**
* login
*
* @param password the password
* @return
*/
private boolean Login(String password) {
private boolean Login() {
Map<String, Object> reqObj = new HashMap<String, Object>();
reqObj.put("action", "login");
reqObj.put("password", this.password);
Expand Down Expand Up @@ -111,22 +110,57 @@ public Map<String, Object> Request(Map<String, Object> map) throws IOException,

/**
* add task
*
* @param obj the k-v content
* @param id id
* @param sid session id
* @param language language
* @param code code without htmlencode
* @return the k-v response
*/
public Map<String, Object> AddTask(Map<String, Object> obj) {
return null;
public Map<String, Object> AddTask(int id, String sid, String language, String code) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("action", "task_add");
map.put("password", this.password);
map.put("id", id);
map.put("sid", sid);
map.put("language", language);
code = this.HtmlEncode(code);
map.put("code", code);

try {
return this.Request(map);
}catch (IOException e1){
e1.printStackTrace();
return null;
}catch (JSONException e2){
e2.printStackTrace();
return null;
}

}

/**
* get task status and result
*
* @param obj the k-v request content
* @param id id
* @param sid session id
* @return the k-v response
*/
public Map<String, Object> GetStatus(Map<String, Object> obj) {
return null;
public Map<String, Object> GetStatus(int id, String sid) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("action", "task_info");
map.put("password", this.password);
map.put("id", id);
map.put("sid", sid);

try {
return this.Request(map);
}catch (IOException e1){
e1.printStackTrace();
return null;
}catch (JSONException e2){
e2.printStackTrace();
return null;
}

}

// json to map
Expand Down Expand Up @@ -162,4 +196,20 @@ private static List toList(JSONArray array) throws JSONException {
}
return list;
}

// encode html
private String HtmlEncode(String html){
StringBuffer out = new StringBuffer();
for(int i = 0; i < html.length(); i++){
char c = html.charAt(i);

if (c > 127 || c == '"' || c == '<' || c == '>') {
out.append("&#" + (int)c + ";");
}else {
out.append(c);
}
}

return out.toString();
}
}

0 comments on commit f7ddcbe

Please sign in to comment.