mirror of https://github.com/OpenVidu/openvidu.git
openvidu-test-browsers: CustomHttpClient fixes
parent
638176a6d4
commit
9cd389eb61
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package io.openvidu.test.browsers.utils;
|
package io.openvidu.test.browsers.utils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -71,13 +72,12 @@ public class CustomHttpClient {
|
||||||
.setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
.setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
||||||
Unirest.setHttpClient(unsafeHttpClient);
|
Unirest.setHttpClient(unsafeHttpClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getAndReturnStatus(String path, String credentials) throws Exception {
|
public int getAndReturnStatus(String path, String credentials) throws Exception {
|
||||||
path = openviduUrl + (path.startsWith("/") ? path : ("/" + path));
|
path = openviduUrl + (path.startsWith("/") ? path : ("/" + path));
|
||||||
return Unirest.get(path).header("Authorization", credentials).asJson().getStatus();
|
return Unirest.get(path).header("Authorization", credentials).asJson().getStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public JSONObject rest(HttpMethod method, String path, int status) throws Exception {
|
public JSONObject rest(HttpMethod method, String path, int status) throws Exception {
|
||||||
return this.commonRest(method, path, null, status);
|
return this.commonRest(method, path, null, status);
|
||||||
}
|
}
|
||||||
|
@ -179,8 +179,12 @@ public class CustomHttpClient {
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void shutdown() throws IOException {
|
||||||
|
Unirest.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
private org.json.JSONObject commonRest(HttpMethod method, String path, String body, int status) throws Exception {
|
private org.json.JSONObject commonRest(HttpMethod method, String path, String body, int status) throws Exception {
|
||||||
HttpResponse<JsonNode> jsonResponse = null;
|
HttpResponse<?> jsonResponse = null;
|
||||||
org.json.JSONObject json = null;
|
org.json.JSONObject json = null;
|
||||||
path = openviduUrl + (path.startsWith("/") ? path : ("/" + path));
|
path = openviduUrl + (path.startsWith("/") ? path : ("/" + path));
|
||||||
|
|
||||||
|
@ -201,27 +205,42 @@ public class CustomHttpClient {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
case GET:
|
case GET:
|
||||||
request = Unirest.get(path);
|
request = Unirest.get(path);
|
||||||
|
request.header("Content-Type", "application/x-www-form-urlencoded");
|
||||||
break;
|
break;
|
||||||
case POST:
|
case POST:
|
||||||
request = Unirest.post(path);
|
request = Unirest.post(path);
|
||||||
break;
|
break;
|
||||||
case DELETE:
|
case DELETE:
|
||||||
request = Unirest.delete(path);
|
request = Unirest.delete(path);
|
||||||
|
request.header("Content-Type", "application/x-www-form-urlencoded");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
request.header("Content-Type", "application/x-www-form-urlencoded");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request = request.header("Authorization", this.headerAuth);
|
||||||
try {
|
try {
|
||||||
jsonResponse = request.header("Authorization", this.headerAuth).asJson();
|
jsonResponse = request.asJson();
|
||||||
if (jsonResponse.getBody() != null) {
|
if (jsonResponse.getBody() != null) {
|
||||||
json = jsonResponse.getBody().getObject();
|
json = ((JsonNode) jsonResponse.getBody()).getObject();
|
||||||
}
|
}
|
||||||
} catch (UnirestException e) {
|
} catch (UnirestException e) {
|
||||||
log.error(e.getMessage());
|
try {
|
||||||
throw new Exception("Error sending request to " + path + ": " + e.getMessage());
|
if (e.getCause().getCause().getCause() instanceof org.json.JSONException) {
|
||||||
|
try {
|
||||||
|
jsonResponse = request.asString();
|
||||||
|
} catch (UnirestException e1) {
|
||||||
|
throw new Exception("Error sending request to " + path + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Exception("Error sending request to " + path + ": " + e.getMessage());
|
||||||
|
}
|
||||||
|
} catch (NullPointerException e2) {
|
||||||
|
throw new Exception("Error sending request to " + path + ": " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jsonResponse.getStatus() == 500) {
|
if (jsonResponse.getStatus() == 500) {
|
||||||
log.error("Internal Server Error: {}", jsonResponse.getBody().toString());
|
log.error("Internal Server Error: {}", jsonResponse.getBody().toString());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue