Skip to content

Commit

Permalink
add rpc req timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
xizho10 committed Nov 6, 2019
1 parent 5cfe174 commit 194ef1d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/github/ontio/network/rest/http.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static String delete(String url, Map<String, String> params, Map<String,
}

public static String post(String url, Map<String, String> params, Map<String, Object> body) throws Exception {
//System.out.println(String.format("POST url=%s,%s,%s", url,JSON.toJSONString(params),JSON.toJSONString(body)));
System.out.println(String.format("POST url=%s,%s,%s", url,JSON.toJSONString(params),JSON.toJSONString(body)));
if(url.startsWith("https")){
return post(url+cvtParams(params), JSON.toJSONString(body), true);
}else{
Expand All @@ -146,8 +146,8 @@ public static String post(String url, Map<String, String> params, Map<String, Ob
private static String get(String url ,boolean https) throws Exception {
URL u = new URL(url);
HttpURLConnection http = (HttpURLConnection) u.openConnection();
http.setConnectTimeout(50000);
http.setReadTimeout(50000);
http.setConnectTimeout(20000);
http.setReadTimeout(20000);
http.setRequestMethod("GET");
http.setRequestProperty("Content-Type","application/json");
if(https) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/github/ontio/network/rpc/Interfaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public Object send(Object request) throws IOException {
try {
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setConnectTimeout(10000);
connection.setReadTimeout(10000);
connection.setDoOutput(true);
try (OutputStreamWriter w = new OutputStreamWriter(connection.getOutputStream())) {
w.write(JSON.toJSONString(request));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/github/ontio/sdk/manager/ConnectMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ConnectMgr(String url, String type, Object lock) {
}

public ConnectMgr(String url, String type) {
url = url.replace("://localhost","://127.0.0.1");
if (type.equals("rpc")) {
setConnector(new RpcClient(url));
} else if (type.equals("restful")) {
Expand Down

0 comments on commit 194ef1d

Please sign in to comment.