mirror of https://github.com/OpenVidu/openvidu.git
openvidu-java-client: update deprecations and fix build warnings
parent
8772efaf46
commit
6d438fb61a
|
|
@ -0,0 +1,16 @@
|
|||
package io.openvidu.java.client;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
public final class GsonTypes {
|
||||
|
||||
public static final Type STRING_OBJECT_MAP = new TypeToken<Map<String, Object>>() {
|
||||
}.getType();
|
||||
|
||||
private GsonTypes() {
|
||||
// Utility class
|
||||
}
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ package io.openvidu.java.client;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
|
|
@ -32,7 +32,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
|
|
@ -41,6 +40,7 @@ import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
|
|||
import org.apache.hc.client5.http.classic.methods.HttpDelete;
|
||||
import org.apache.hc.client5.http.classic.methods.HttpGet;
|
||||
import org.apache.hc.client5.http.classic.methods.HttpPost;
|
||||
import org.apache.hc.client5.http.config.ConnectionConfig;
|
||||
import org.apache.hc.client5.http.config.RequestConfig;
|
||||
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
|
||||
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||
|
|
@ -48,9 +48,9 @@ import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
|||
import org.apache.hc.client5.http.impl.classic.HttpClients;
|
||||
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
|
||||
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
|
||||
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
|
||||
import org.apache.hc.client5.http.ssl.HostnameVerificationPolicy;
|
||||
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
|
||||
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
|
||||
import org.apache.hc.core5.http.ClassicHttpResponse;
|
||||
import org.apache.hc.core5.http.HttpEntity;
|
||||
import org.apache.hc.core5.http.HttpException;
|
||||
|
|
@ -63,6 +63,7 @@ import org.apache.hc.core5.http.io.entity.StringEntity;
|
|||
import org.apache.hc.core5.ssl.SSLContextBuilder;
|
||||
import org.apache.hc.core5.ssl.TrustStrategy;
|
||||
import org.apache.hc.core5.util.TimeValue;
|
||||
import org.apache.hc.core5.util.Timeout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -121,14 +122,17 @@ public class OpenVidu {
|
|||
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
|
||||
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE).setSslContext(sslContext).build();
|
||||
final DefaultClientTlsStrategy tlsStrategy = new DefaultClientTlsStrategy(sslContext,
|
||||
HostnameVerificationPolicy.CLIENT, NoopHostnameVerifier.INSTANCE);
|
||||
|
||||
final ConnectionConfig connectionConfig = ConnectionConfig.custom().setConnectTimeout(Timeout.ofSeconds(30))
|
||||
.setTimeToLive(TimeValue.ofSeconds(30)).build();
|
||||
|
||||
final HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
|
||||
.setSSLSocketFactory(sslSocketFactory).setConnectionTimeToLive(TimeValue.ofSeconds(30)).build();
|
||||
.setTlsSocketStrategy(tlsStrategy).setDefaultConnectionConfig(connectionConfig).build();
|
||||
|
||||
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30, TimeUnit.SECONDS)
|
||||
.setConnectionRequestTimeout(30, TimeUnit.SECONDS).setResponseTimeout(30, TimeUnit.SECONDS).build();
|
||||
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(Timeout.ofSeconds(30))
|
||||
.setResponseTimeout(Timeout.ofSeconds(30)).build();
|
||||
|
||||
this.httpClient = HttpClients.custom().setConnectionManager(connectionManager)
|
||||
.setDefaultRequestConfig(requestConfig).setDefaultCredentialsProvider(credentialsProvider).build();
|
||||
|
|
@ -836,8 +840,8 @@ public class OpenVidu {
|
|||
|
||||
private void testHostname(String hostnameStr) {
|
||||
try {
|
||||
new URL(hostnameStr);
|
||||
} catch (MalformedURLException e) {
|
||||
URI.create(hostnameStr).toURL();
|
||||
} catch (IllegalArgumentException | MalformedURLException e) {
|
||||
throw new RuntimeException("The hostname \"" + hostnameStr + "\" is not a valid URL: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ public class Recording {
|
|||
}
|
||||
this.status = Recording.Status.valueOf(json.get("status").getAsString());
|
||||
|
||||
RecordingProperties.Builder builder = RecordingProperties
|
||||
.fromJson(new Gson().fromJson(json.toString(), Map.class), null);
|
||||
Map<String, Object> recordingProps = new Gson().fromJson(json.toString(), GsonTypes.STRING_OBJECT_MAP);
|
||||
RecordingProperties.Builder builder = RecordingProperties.fromJson(recordingProps, null);
|
||||
this.recordingProperties = builder.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -727,8 +727,8 @@ public class Session {
|
|||
.recordingMode(RecordingMode.valueOf(json.get("recordingMode").getAsString()));
|
||||
if (json.has("defaultRecordingProperties")) {
|
||||
String jsonString = json.get("defaultRecordingProperties").getAsJsonObject().toString();
|
||||
RecordingProperties.Builder recBuilder = RecordingProperties
|
||||
.fromJson(new Gson().fromJson(jsonString, Map.class), null);
|
||||
Map<String, Object> recordingProps = new Gson().fromJson(jsonString, GsonTypes.STRING_OBJECT_MAP);
|
||||
RecordingProperties.Builder recBuilder = RecordingProperties.fromJson(recordingProps, null);
|
||||
builder.defaultRecordingProperties(recBuilder.build());
|
||||
}
|
||||
if (json.has("customSessionId")) {
|
||||
|
|
|
|||
|
|
@ -17,14 +17,12 @@
|
|||
|
||||
package io.openvidu.java.client;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* See {@link io.openvidu.java.client.OpenVidu#createSession(SessionProperties)}
|
||||
|
|
@ -376,8 +374,8 @@ public class SessionProperties {
|
|||
JsonObject defaultRecordingPropertiesJson = null;
|
||||
if (params.get("defaultRecordingProperties") != null) {
|
||||
try {
|
||||
defaultRecordingPropertiesJson = new Gson()
|
||||
.toJsonTree(params.get("defaultRecordingProperties"), Map.class).getAsJsonObject();
|
||||
defaultRecordingPropertiesJson = new Gson().toJsonTree(params.get("defaultRecordingProperties"),
|
||||
GsonTypes.STRING_OBJECT_MAP).getAsJsonObject();
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(
|
||||
"Error in parameter 'defaultRecordingProperties'. It is not a valid JSON object");
|
||||
|
|
@ -386,8 +384,9 @@ public class SessionProperties {
|
|||
if (defaultRecordingPropertiesJson != null) {
|
||||
try {
|
||||
String jsonString = defaultRecordingPropertiesJson.toString();
|
||||
RecordingProperties.Builder recBuilder = RecordingProperties
|
||||
.fromJson(new Gson().fromJson(jsonString, Map.class), null);
|
||||
Map<String, Object> recordingProps = new Gson().fromJson(jsonString,
|
||||
GsonTypes.STRING_OBJECT_MAP);
|
||||
RecordingProperties.Builder recBuilder = RecordingProperties.fromJson(recordingProps, null);
|
||||
RecordingProperties defaultRecordingProperties = recBuilder.build();
|
||||
builder = builder.defaultRecordingProperties(defaultRecordingProperties);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -419,9 +418,7 @@ public class SessionProperties {
|
|||
} catch (Exception e) {
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
Type gsonType = new TypeToken<Map>() {
|
||||
}.getType();
|
||||
String gsonString = gson.toJson(params.get("mediaNode"), gsonType);
|
||||
String gsonString = gson.toJson(params.get("mediaNode"), GsonTypes.STRING_OBJECT_MAP);
|
||||
mediaNodeJson = JsonParser.parseString(gsonString).getAsJsonObject();
|
||||
} catch (Exception e2) {
|
||||
throw new IllegalArgumentException("Error in parameter 'mediaNode'. It is not a valid JSON object");
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.JsonObject;
|
||||
|
||||
import io.openvidu.java.client.ConnectionProperties;
|
||||
import io.openvidu.java.client.GsonTypes;
|
||||
|
||||
public class ConnectionPropertiesTest {
|
||||
|
||||
|
|
@ -96,7 +97,7 @@ public class ConnectionPropertiesTest {
|
|||
}
|
||||
|
||||
private Map<String, ?> mapFromJsonString(String json) {
|
||||
return new Gson().fromJson(json, Map.class);
|
||||
return new Gson().fromJson(json, GsonTypes.STRING_OBJECT_MAP);
|
||||
}
|
||||
|
||||
private void assertException(Map<String, ?> params, String containsError) {
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuil
|
|||
import org.apache.hc.client5.http.impl.routing.DefaultProxyRoutePlanner;
|
||||
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
|
||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
|
||||
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
|
||||
import org.apache.hc.client5.http.ssl.HostnameVerificationPolicy;
|
||||
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
|
||||
import org.apache.hc.core5.http.HttpHeaders;
|
||||
import org.apache.hc.core5.http.HttpHost;
|
||||
import org.apache.hc.core5.http.message.BasicHeader;
|
||||
|
|
@ -70,16 +71,17 @@ public class OpenViduConstructorTest {
|
|||
builder.setRoutePlanner(routePlanner);
|
||||
|
||||
// Custom SSLContext
|
||||
SSLContext sslContext = null;
|
||||
SSLContext sslContext;
|
||||
try {
|
||||
sslContext = SSLContext.getInstance("TLSv1.2");
|
||||
sslContext.init(null, null, null);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final SSLConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactoryBuilder.create()
|
||||
.setSslContext(sslContext).build();
|
||||
final DefaultClientTlsStrategy tlsStrategy = new DefaultClientTlsStrategy(sslContext,
|
||||
HostnameVerificationPolicy.CLIENT, NoopHostnameVerifier.INSTANCE);
|
||||
final HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
|
||||
.setSSLSocketFactory(sslSocketFactory).build();
|
||||
.setTlsSocketStrategy(tlsStrategy).build();
|
||||
builder.setConnectionManager(connectionManager);
|
||||
|
||||
// Custom CredentialsProvider
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.google.gson.JsonObject;
|
|||
|
||||
import io.openvidu.java.client.Recording.OutputMode;
|
||||
import io.openvidu.java.client.RecordingProperties;
|
||||
import io.openvidu.java.client.GsonTypes;
|
||||
|
||||
public class RecordingPropertiesTest {
|
||||
|
||||
|
|
@ -137,7 +138,7 @@ public class RecordingPropertiesTest {
|
|||
}
|
||||
|
||||
private Map<String, ?> mapFromJsonString(String json) {
|
||||
return new Gson().fromJson(json, Map.class);
|
||||
return new Gson().fromJson(json, GsonTypes.STRING_OBJECT_MAP);
|
||||
}
|
||||
|
||||
private <T extends Exception> void assertException(Map<String, ?> params, String containsError,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.google.gson.Gson;
|
|||
import com.google.gson.JsonObject;
|
||||
|
||||
import io.openvidu.java.client.SessionProperties;
|
||||
import io.openvidu.java.client.GsonTypes;
|
||||
|
||||
public class SessionPropertiesTest {
|
||||
|
||||
|
|
@ -39,7 +40,7 @@ public class SessionPropertiesTest {
|
|||
}
|
||||
|
||||
private Map<String, ?> mapFromJsonString(String json) {
|
||||
return new Gson().fromJson(json, Map.class);
|
||||
return new Gson().fromJson(json, GsonTypes.STRING_OBJECT_MAP);
|
||||
}
|
||||
|
||||
private void assertException(Map<String, ?> params, String containsError) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue