diff --git a/openvidu-server/pom.xml b/openvidu-server/pom.xml index b44ece16..d35001b3 100644 --- a/openvidu-server/pom.xml +++ b/openvidu-server/pom.xml @@ -281,11 +281,6 @@ commons-lang3 3.7 - - com.maxmind.geoip2 - geoip2 - 2.12.0 - diff --git a/openvidu-server/src/main/java/io/openvidu/server/OpenViduServer.java b/openvidu-server/src/main/java/io/openvidu/server/OpenViduServer.java index 238a2df6..fafdbcfd 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/OpenViduServer.java +++ b/openvidu-server/src/main/java/io/openvidu/server/OpenViduServer.java @@ -61,6 +61,8 @@ import io.openvidu.server.recording.ComposedRecordingService; import io.openvidu.server.rest.NgrokRestController; import io.openvidu.server.rpc.RpcHandler; import io.openvidu.server.rpc.RpcNotificationService; +import io.openvidu.server.utils.GeoLocationByIp; +import io.openvidu.server.utils.GeoLocationByIpDummy; /** * OpenVidu Server application @@ -154,6 +156,12 @@ public class OpenViduServer implements JsonRpcConfigurer { return new CoturnCredentialsServiceFactory(openviduConfig()).getCoturnCredentialsService(); } + @Bean + @ConditionalOnMissingBean + public GeoLocationByIp geoLocationByIp() { + return new GeoLocationByIpDummy(); + } + @Override public void registerJsonRpcHandlers(JsonRpcHandlerRegistry registry) { registry.addHandler(rpcHandler().withPingWatchdog(true), "/openvidu"); diff --git a/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java b/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java index 290eb3b4..93c396b0 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java +++ b/openvidu-server/src/main/java/io/openvidu/server/rpc/RpcHandler.java @@ -37,7 +37,6 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.google.gson.JsonSyntaxException; -import com.maxmind.geoip2.exception.GeoIp2Exception; import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException.Code; @@ -47,7 +46,7 @@ import io.openvidu.server.core.MediaOptions; import io.openvidu.server.core.Participant; import io.openvidu.server.core.SessionManager; import io.openvidu.server.core.Token; -import io.openvidu.server.utils.GeoLocationByIpUtils; +import io.openvidu.server.utils.GeoLocationByIp; public class RpcHandler extends DefaultJsonRpcHandler { @@ -57,7 +56,7 @@ public class RpcHandler extends DefaultJsonRpcHandler { OpenviduConfig openviduConfig; @Autowired - GeoLocationByIpUtils geoLocationByIp; + GeoLocationByIp geoLocationByIp; @Autowired SessionManager sessionManager; @@ -180,11 +179,10 @@ public class RpcHandler extends DefaultJsonRpcHandler { } catch (IOException e) { e.printStackTrace(); location = "error"; - } catch (GeoIp2Exception e) { + } catch (Exception e) { log.warn("Error getting address location: {}", e.getMessage()); location = "unknown"; } - } boolean recorder = false; diff --git a/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIp.java b/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIp.java new file mode 100644 index 00000000..422e55ce --- /dev/null +++ b/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIp.java @@ -0,0 +1,26 @@ +/* + * (C) Copyright 2017-2018 OpenVidu (https://openvidu.io/) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package io.openvidu.server.utils; + +import java.net.InetAddress; + +public interface GeoLocationByIp { + + public String getLocationByIp(InetAddress ipAddress) throws Exception; + +} diff --git a/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIpDummy.java b/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIpDummy.java new file mode 100644 index 00000000..5a890ee8 --- /dev/null +++ b/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIpDummy.java @@ -0,0 +1,14 @@ +package io.openvidu.server.utils; + +import java.net.InetAddress; + +import org.springframework.stereotype.Service; + +@Service +public class GeoLocationByIpDummy implements GeoLocationByIp { + + public String getLocationByIp(InetAddress ipAddress) throws Exception { + return ""; + } + +} diff --git a/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIpUtils.java b/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIpUtils.java deleted file mode 100644 index 07c02764..00000000 --- a/openvidu-server/src/main/java/io/openvidu/server/utils/GeoLocationByIpUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.openvidu.server.utils; - -import java.io.IOException; -import java.io.InputStream; -import java.net.InetAddress; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import javax.inject.Inject; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.io.Resource; -import org.springframework.core.io.ResourceLoader; -import org.springframework.stereotype.Service; - -import com.maxmind.db.Reader; -import com.maxmind.geoip2.DatabaseReader; -import com.maxmind.geoip2.exception.GeoIp2Exception; -import com.maxmind.geoip2.model.CityResponse; - -/** - * This product includes GeoLite2 data created by MaxMind, available from - * http://www.maxmind.com. - */ - -@Service("geolocationservice") -public class GeoLocationByIpUtils { - - private static final Logger log = LoggerFactory.getLogger(GeoLocationByIpUtils.class); - - private static DatabaseReader reader = null; - private ResourceLoader resourceLoader; - - @Inject - public GeoLocationByIpUtils(ResourceLoader resourceLoader) { - this.resourceLoader = resourceLoader; - } - - @PostConstruct - public void init() { - try { - log.info("Trying to load GeoLite2-City database..."); - Resource resource = resourceLoader.getResource("classpath:GeoLite2-City.mmdb"); - InputStream dbAsStream = resource.getInputStream(); - // Initialize the reader - reader = new DatabaseReader.Builder(dbAsStream).fileMode(Reader.FileMode.MEMORY).build(); - log.info("Database was loaded successfully"); - } catch (IOException | NullPointerException e) { - log.error("Database reader cound not be initialized", e); - } - } - - @PreDestroy - public void preDestroy() { - if (reader != null) { - try { - reader.close(); - } catch (IOException e) { - log.error("Failed to close the GeoLocation reader"); - } - } - } - - public String getLocationByIp(InetAddress ipAddress) throws IOException, GeoIp2Exception { - CityResponse response = reader.city(ipAddress); - return response.getCity().getNames().get("en") + ", " + response.getCountry().getNames().get("en"); - } -} diff --git a/openvidu-server/src/main/resources/GeoLite2-City.mmdb b/openvidu-server/src/main/resources/GeoLite2-City.mmdb deleted file mode 100644 index dbaddbdb..00000000 Binary files a/openvidu-server/src/main/resources/GeoLite2-City.mmdb and /dev/null differ