From 591f5f5e9a4dfe0aa717be1ff4d011835907f14a Mon Sep 17 00:00:00 2001 From: crusader Date: Tue, 24 Apr 2018 21:57:05 +0900 Subject: [PATCH] ing --- pom.xml | 14 +- .../service/CentralDiscoveryService.java | 122 +++++------ .../generator/service/InfraHostGenerator.java | 126 ++++++----- .../service/InfraHostWMIGenerator.java | 11 +- .../service/InfraServiceGenerator.java | 13 +- .../service/InfraServiceJMXGenerator.java | 11 +- .../service/InfraServiceMysqlGenerator.java | 12 +- .../service/SensorConfigGenerator.java | 2 - .../service/CentralNoAuthProbeService.java | 17 +- .../central/proxy/ServiceInvoker.java | 31 +-- .../redis/service/RedisMessagePublisher.java | 207 +++++++++--------- .../overflow/central/spring/AppConfig.java | 69 +++--- .../central/spring/JdbcConfiguration.java | 1 - .../infra/service/InfraHostServiceTest.java | 8 +- .../service/InfraMachineServiceTest.java | 10 +- .../InfraOSApplicationServiceTest.java | 9 +- .../service/InfraOSDaemonServiceTest.java | 8 +- .../infra/service/InfraOSPortServiceTest.java | 3 + .../infra/service/InfraOSServiceTest.java | 7 +- .../service/InfraServiceServiceTest.java | 3 + .../central/spring/AppConfigTest.java | 15 +- 21 files changed, 330 insertions(+), 369 deletions(-) diff --git a/pom.xml b/pom.xml index b128e98..4a71052 100644 --- a/pom.xml +++ b/pom.xml @@ -25,10 +25,10 @@ 1.11.4.RELEASE 1.8.7.RELEASE 4.2.3.RELEASE + 2.8.2 5.2.10.Final 1.4.7 1.6.0 - 1.9.13 1.7 docker.loafle.net/overflow 1.1.2 @@ -97,12 +97,6 @@ 9.4-1200-jdbc41 - - org.codehaus.jackson - jackson-mapper-asl - ${jackson.mapper.version} - - @@ -124,6 +118,12 @@ ${spring.crypto.version} + + com.google.code.gson + gson + ${gson.version} + + diff --git a/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java b/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java index 9047087..1eb5781 100644 --- a/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java +++ b/src/main/java/com/loafle/overflow/central/module/discovery/service/CentralDiscoveryService.java @@ -1,7 +1,5 @@ package com.loafle.overflow.central.module.discovery.service; - - import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.utils.SessionMetadata; import com.loafle.overflow.core.annotation.ProbeAPI; @@ -10,11 +8,9 @@ import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.discovery.*; import com.loafle.overflow.service.central.discovery.DiscoveryService; -import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.Date; /** @@ -23,76 +19,68 @@ import java.util.Date; @Service("DiscoveryService") public class CentralDiscoveryService implements DiscoveryService { - @Autowired - private MessagePublisher messagePublisher; + @Autowired + private MessagePublisher messagePublisher; - public void startDiscovery(DiscoveryStartInfo startInfo) throws OverflowException,IOException { + @WebappAPI + public void discoverZone(String probeID, DiscoverZone discoveryZone) throws OverflowException { + String requesterSessionID = SessionMetadata.getSessionID(); - ObjectMapper objectMapper = new ObjectMapper(); + messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverZone", requesterSessionID, discoveryZone); + } - String json = objectMapper.writeValueAsString(startInfo); + @WebappAPI + public void discoverHost(String probeID, Zone zone, DiscoverHost discoveryHost) throws OverflowException { + String requesterSessionID = SessionMetadata.getSessionID(); - System.out.println("Start Discovery"); - System.out.println(json); -// this.messagePublisher.publishToProbe("/auth", noAuthProbe.getTempProbeKey(), "NoAuthProbeService.acceptNoAuthProbe", probe.getProbeKey()); - } + messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverHost", requesterSessionID, zone, discoveryHost); + } - @WebappAPI - public void discoverZone(String probeID, DiscoverZone discoveryZone) throws OverflowException { - String requesterSessionID = SessionMetadata.getSessionID(); - - messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverZone", requesterSessionID, discoveryZone); - } + @WebappAPI + public void discoverPort(String probeID, Host host, DiscoverPort discoveryPort) throws OverflowException { + String requesterSessionID = SessionMetadata.getSessionID(); - @WebappAPI - public void discoverHost(String probeID, Zone zone, DiscoverHost discoveryHost) throws OverflowException { - String requesterSessionID = SessionMetadata.getSessionID(); - - messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverHost", requesterSessionID, zone, discoveryHost); - } - - @WebappAPI - public void discoverPort(String probeID, Host host, DiscoverPort discoveryPort) throws OverflowException { - String requesterSessionID = SessionMetadata.getSessionID(); - - messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverPort", requesterSessionID, host, discoveryPort); - } + messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverPort", requesterSessionID, host, discoveryPort); + } - @WebappAPI - public void discoverService(String probeID, Port port, com.loafle.overflow.model.discovery.DiscoverService discoveryService) throws OverflowException { - String requesterSessionID = SessionMetadata.getSessionID(); - - messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverService", requesterSessionID, port, discoveryService); - } + @WebappAPI + public void discoverService(String probeID, Port port, + com.loafle.overflow.model.discovery.DiscoverService discoveryService) throws OverflowException { + String requesterSessionID = SessionMetadata.getSessionID(); - @ProbeAPI - public void discoverStart(String requesterSessionID, Date startDate) throws OverflowException { - messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStart", startDate); - } - - @ProbeAPI - public void discoverStop(String requesterSessionID, Date stopDate) throws OverflowException { - messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStop", stopDate); - } - - @ProbeAPI - public void discoveredZone(String requesterSessionID, Zone zone) throws OverflowException { - messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredZone", zone); - } - - @ProbeAPI - public void discoveredHost(String requesterSessionID, Host host) throws OverflowException { - messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredHost", host); - } - - @ProbeAPI - public void discoveredPort(String requesterSessionID, Port port) throws OverflowException { - messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredPort", port); - } + messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverService", requesterSessionID, port, + discoveryService); + } + + @ProbeAPI + public void discoverStart(String requesterSessionID, Date startDate) throws OverflowException { + messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStart", startDate); + } + + @ProbeAPI + public void discoverStop(String requesterSessionID, Date stopDate) throws OverflowException { + messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveryStop", stopDate); + } + + @ProbeAPI + public void discoveredZone(String requesterSessionID, Zone zone) throws OverflowException { + messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredZone", zone); + } + + @ProbeAPI + public void discoveredHost(String requesterSessionID, Host host) throws OverflowException { + messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredHost", host); + } + + @ProbeAPI + public void discoveredPort(String requesterSessionID, Port port) throws OverflowException { + messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredPort", port); + } + + @ProbeAPI + public void discoveredService(String requesterSessionID, com.loafle.overflow.model.discovery.Service service) + throws OverflowException { + messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredService", service); + } - @ProbeAPI - public void discoveredService(String requesterSessionID, com.loafle.overflow.model.discovery.Service service) throws OverflowException { - messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredService", service); - } - } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java index 12980f6..b8082b3 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostGenerator.java @@ -1,5 +1,7 @@ package com.loafle.overflow.central.module.generator.service; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.loafle.overflow.central.commons.utils.StringConvertor; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.type.PortType; @@ -17,8 +19,6 @@ import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.Target; import com.loafle.overflow.service.central.auth.AuthCrawlerService; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -32,81 +32,79 @@ import java.util.Map; @Service("InfraHostGenerator") public class InfraHostGenerator { - @Autowired - private GenerateUtil generateUtil; + @Autowired + private GenerateUtil generateUtil; - @Autowired - private InfraHostWMIGenerator infraHostWMIGenerator; + @Autowired + private InfraHostWMIGenerator infraHostWMIGenerator; - @Autowired - private AuthCrawlerService authCrawlerService; + @Autowired + private AuthCrawlerService authCrawlerService; - public String process(Sensor dbSensor, List sensorItems, Infra infra) throws Exception { + @Autowired + private Gson gson; - InfraHost infraHost = (InfraHost) infra; + public String process(Sensor dbSensor, List sensorItems, Infra infra) throws Exception { - SensorConfig sensorConfig = new SensorConfig(); - sensorConfig.setConfigID(String.valueOf(dbSensor.getId())); + InfraHost infraHost = (InfraHost) infra; - Target target = this.createTarget(infraHost, dbSensor); + SensorConfig sensorConfig = new SensorConfig(); + sensorConfig.setConfigID(String.valueOf(dbSensor.getId())); - if (target == null) { - return null; - } + Target target = this.createTarget(infraHost, dbSensor); - sensorConfig.setTarget(target); - - // FIXME: Interval - Schedule schedule = new Schedule(); - schedule.setInterval("5"); - sensorConfig.setSchedule(schedule); - - Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler()); - sensorConfig.setCrawler(crawler); - - Map keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler()); - - if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { - this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); - } - - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.writeValueAsString(sensorConfig); + if (target == null) { + return null; } - private Target createTarget(InfraHost infraHost, Sensor dbSensor) - throws Exception { + sensorConfig.setTarget(target); - AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget()); + // FIXME: Interval + Schedule schedule = new Schedule(); + schedule.setInterval("5"); + sensorConfig.setSchedule(schedule); - if (authCrawler == null) { - return null; - } + Crawler crawler = this.generateUtil.getCrawler(dbSensor.getCrawler()); + sensorConfig.setCrawler(crawler); - Target target = new Target(); - Connection connection = new Connection(); - connection.setIp(StringConvertor.intToIp(infraHost.getIp())); + Map keyMap = this.generateUtil.initMappingMap(dbSensor.getCrawler()); - HashMap optionMap; - optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(), - new TypeReference>() { - }); - - if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { - connection.setPort(135); - connection.setPortType(PortType.TCP); - connection.setSsl(false); - - target.setConnection(connection); - - Map auth = new HashMap<>(); - auth.put("id", optionMap.get("ID")); - auth.put("pw", optionMap.get("PassWord")); - - target.setAuth(auth); - - } - - return target; + if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { + this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); } + + return gson.toJson(sensorConfig); + } + + private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception { + + AuthCrawler authCrawler = this.authCrawlerService.readAuth(dbSensor.getCrawler(), dbSensor.getTarget()); + + if (authCrawler == null) { + return null; + } + + Target target = new Target(); + Connection connection = new Connection(); + connection.setIp(StringConvertor.intToIp(infraHost.getIp())); + + HashMap optionMap = this.gson.fromJson(authCrawler.getAuthJson(), TypeToken.getParameterized(HashMap.class, String.class, String.class).getType()); + + if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) { + connection.setPort(135); + connection.setPortType(PortType.TCP); + connection.setSsl(false); + + target.setConnection(connection); + + Map auth = new HashMap<>(); + auth.put("id", optionMap.get("ID")); + auth.put("pw", optionMap.get("PassWord")); + + target.setAuth(auth); + + } + + return target; + } } diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java index d4d9d48..dd178cb 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraHostWMIGenerator.java @@ -1,5 +1,7 @@ package com.loafle.overflow.central.module.generator.service; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.SensorItem; @@ -9,8 +11,6 @@ import com.loafle.overflow.model.sensorconfig.MappingInfo; import com.loafle.overflow.model.sensorconfig.QueryInfo; import com.loafle.overflow.model.sensorconfig.SensorConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +29,9 @@ public class InfraHostWMIGenerator { @Autowired private GenerateUtil generateUtil; + @Autowired + private Gson gson; + public void process(List sensorItems, Map keyMap, Sensor dbSensor, SensorConfig sensorConfig) throws Exception { @@ -84,9 +87,7 @@ public class InfraHostWMIGenerator { String json = tempItemKey.getOption(); if (json != null && json.length() > 0) { - HashMap optionMap; - optionMap = new ObjectMapper().readValue(json, new TypeReference>() { - }); + HashMap optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType()); Object obj = null; obj = optionMap.get("appends"); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java index 76da03c..af97307 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceGenerator.java @@ -1,5 +1,7 @@ package com.loafle.overflow.central.module.generator.service; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.loafle.overflow.central.commons.utils.StringConvertor; import com.loafle.overflow.core.type.PortType; import com.loafle.overflow.model.auth.AuthCrawler; @@ -16,8 +18,6 @@ import com.loafle.overflow.model.sensorconfig.SensorConfig; import com.loafle.overflow.model.sensorconfig.Target; import com.loafle.overflow.service.central.auth.AuthCrawlerService; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -44,6 +44,9 @@ public class InfraServiceGenerator { @Autowired private AuthCrawlerService authCrawlerService; + @Autowired + private Gson gson; + public String process(Sensor dbSensor, List sensorItems, Infra infra) throws Exception { com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra; @@ -75,8 +78,7 @@ public class InfraServiceGenerator { this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig); } - ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.writeValueAsString(sensorConfig); + return gson.toJson(sensorConfig); } private Target createTarget(InfraService infraService, Sensor sensor) throws Exception { @@ -96,8 +98,7 @@ public class InfraServiceGenerator { target.setConnection(connection); - HashMap optionMap; - optionMap = new ObjectMapper().readValue(authCrawler.getAuthJson(), new TypeReference>() {}); + HashMap optionMap = this.gson.fromJson(authCrawler.getAuthJson(), TypeToken.getParameterized(HashMap.class, String.class, String.class).getType()); Map auth = new HashMap<>(); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java index dd6beae..355f947 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceJMXGenerator.java @@ -1,5 +1,7 @@ package com.loafle.overflow.central.module.generator.service; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.sensor.Sensor; import com.loafle.overflow.model.sensor.SensorItem; @@ -9,8 +11,6 @@ import com.loafle.overflow.model.sensorconfig.MappingInfo; import com.loafle.overflow.model.sensorconfig.QueryInfo; import com.loafle.overflow.model.sensorconfig.SensorConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -28,6 +28,9 @@ public class InfraServiceJMXGenerator { @Autowired private GenerateUtil generateUtil; + @Autowired + private Gson gson; + public void process(List sensorItems, Map keyMap, Sensor dbSensor, SensorConfig sensorConfig) throws Exception { Map> metricMap = null; @@ -70,9 +73,7 @@ public class InfraServiceJMXGenerator { List arrayCol = null; if (json != null && json.length() > 0) { - HashMap optionMap; - optionMap = new ObjectMapper().readValue(json, new TypeReference>() { - }); + HashMap optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType()); Object obj = null; obj = optionMap.get("aliases"); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java index 220ac1b..6ddd27f 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/InfraServiceMysqlGenerator.java @@ -1,5 +1,7 @@ package com.loafle.overflow.central.module.generator.service; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.meta.MetaSensorItemKey; import com.loafle.overflow.model.sensor.Sensor; @@ -10,10 +12,6 @@ import com.loafle.overflow.model.sensorconfig.MappingInfo; import com.loafle.overflow.model.sensorconfig.QueryInfo; import com.loafle.overflow.model.sensorconfig.SensorConfig; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,6 +29,8 @@ public class InfraServiceMysqlGenerator { @Autowired private GenerateUtil generateUtil; + @Autowired + private Gson gson; public void process(List sensorItems, Map keyMap, Sensor dbSensor, SensorConfig sensorConfig) throws Exception { @@ -83,9 +83,7 @@ public class InfraServiceMysqlGenerator { String json = tempItemKey.getOption(); if (json != null && json.length() > 0) { - HashMap optionMap; - optionMap = new ObjectMapper().readValue(json, new TypeReference>() { - }); + HashMap optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType()); Object obj = null; obj = optionMap.get("valueColumn"); diff --git a/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java b/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java index 1a21c17..ed96d32 100644 --- a/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java +++ b/src/main/java/com/loafle/overflow/central/module/generator/service/SensorConfigGenerator.java @@ -4,10 +4,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.stereotype.Service; -import java.io.IOException; import java.util.List; -import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PageParams; import com.loafle.overflow.model.infra.Infra; import com.loafle.overflow.model.sensor.Sensor; diff --git a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java index a41e911..838130d 100644 --- a/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/central/module/noauthprobe/service/CentralNoAuthProbeService.java @@ -1,5 +1,7 @@ package com.loafle.overflow.central.module.noauthprobe.service; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.central.commons.stereotype.ProbeAPI; import com.loafle.overflow.central.commons.stereotype.WebappAPI; @@ -20,8 +22,6 @@ import com.loafle.overflow.service.central.domain.DomainMemberService; import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService; import com.loafle.overflow.service.central.probe.ProbeService; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; @@ -46,15 +46,15 @@ public class CentralNoAuthProbeService implements NoAuthProbeService{ @Autowired private ProbeService probeService; - @Autowired - private ObjectMapper objectMapper; - @Autowired private MessagePublisher messagePublisher; @Autowired private DomainMemberService domainMemberService; + @Autowired + private Gson gson; + @ProbeAPI public NoAuthProbe regist(NoAuthProbe noAuthProbe) throws OverflowException{ @@ -99,12 +99,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService{ probe.setAuthorizeMember(new Member(domainMember.getMember().getId())); probe.setStatus(new MetaProbeStatus((short)1)); - Map objMap = null; - try { - objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference>() {}); - } catch (Exception e) { - e.printStackTrace(); - } + HashMap objMap = this.gson.fromJson(noAuthProbe.getDescription(), TypeToken.getParameterized(HashMap.class, String.class, Object.class).getType()); Map hostMap = (Map) objMap.get("host"); Map netMap = (Map) objMap.get("network"); diff --git a/src/main/java/com/loafle/overflow/central/proxy/ServiceInvoker.java b/src/main/java/com/loafle/overflow/central/proxy/ServiceInvoker.java index 0d1b771..1fe80f8 100644 --- a/src/main/java/com/loafle/overflow/central/proxy/ServiceInvoker.java +++ b/src/main/java/com/loafle/overflow/central/proxy/ServiceInvoker.java @@ -1,18 +1,15 @@ package com.loafle.overflow.central.proxy; -import com.google.gson.internal.Primitives; +import com.google.gson.Gson; import com.google.protobuf.ByteString; import com.loafle.overflow.core.exception.OverflowException; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.JavaType; import org.springframework.aop.support.AopUtils; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; -import java.io.IOException; import java.lang.reflect.*; import java.util.HashMap; import java.util.List; @@ -26,15 +23,13 @@ public class ServiceInvoker { // @Autowired private ApplicationContext context; - private ObjectMapper objectMapper; - private Map serviceCacheMap; + @Autowired + private Gson gson; + public ServiceInvoker(ApplicationContext context) { this.context = context; - objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); - serviceCacheMap = new HashMap<>(); } @@ -122,15 +117,7 @@ public class ServiceInvoker { } private Object getValue(Type parameterType, String json) throws IllegalArgumentException { - JavaType targetType = objectMapper.getTypeFactory().constructType(parameterType); - if (!Primitives.isPrimitive(parameterType) && !parameterType.getTypeName().equals(String.class.getName())) { - try { - return objectMapper.readValue(json, targetType); - } catch (IOException e) { - throw new IllegalArgumentException(""); - } - } - return objectMapper.convertValue(json, targetType); + return this.gson.fromJson(json, parameterType); } private Object[] getParameters(Type[] parameterTypes, List params) throws IllegalArgumentException { @@ -187,11 +174,7 @@ public class ServiceInvoker { throw new OverflowException("internal error", e); } - try { - jsonInString = objectMapper.writeValueAsString(result); - } catch (IOException e) { - throw new OverflowException("internal error", e); - } + jsonInString = this.gson.toJson(result); return jsonInString; } diff --git a/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java b/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java index 3633b22..3b2a2fb 100644 --- a/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java +++ b/src/main/java/com/loafle/overflow/central/redis/service/RedisMessagePublisher.java @@ -1,12 +1,12 @@ package com.loafle.overflow.central.redis.service; +import com.google.gson.Gson; import com.loafle.overflow.central.commons.service.MessagePublisher; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.core.model.PublishMessage; import com.loafle.overflow.model.member.Member; import com.loafle.overflow.service.central.member.MemberService; -import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.redis.core.RedisTemplate; @@ -20,114 +20,113 @@ import java.util.Map; @Service public class RedisMessagePublisher implements MessagePublisher { - private static final String CHANNEL_WEBAPP = "/webapp"; - private static final String CHANNEL_NOAUTH_PROBE = "/auth"; - private static final String CHANNEL_PROBE = "/probe"; + private static final String CHANNEL_WEBAPP = "/webapp"; + private static final String CHANNEL_NOAUTH_PROBE = "/auth"; + private static final String CHANNEL_PROBE = "/probe"; - @Autowired - private RedisTemplate redisTemplate; - @Autowired - private ObjectMapper objectMapper; - @Autowired - private MemberService memberService; + @Autowired + private RedisTemplate redisTemplate; + @Autowired + private Gson gson; + @Autowired + private MemberService memberService; - private Map topics; + private Map topics; - public RedisMessagePublisher() { + public RedisMessagePublisher() { + } + + public RedisMessagePublisher(final RedisTemplate redisTemplate, + final Map topics) { + this.redisTemplate = redisTemplate; + this.topics = topics; + } + + public void publishToDomainMembers(final long domainID, final String method, final Object... params) + throws OverflowException { + PublishMessage message = new PublishMessage(); + message.setTargetType(PublishMessage.TargetType.MEMBER); + message.setTargets(getMemberListByDomainID(domainID)); + this.publish(CHANNEL_WEBAPP, message, method, params); + } + + public void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) + throws OverflowException { + PublishMessage message = new PublishMessage(); + message.setTargetType(PublishMessage.TargetType.MEMBER); + message.setTargets(getMemberListByProbeKey(probeKey)); + this.publish(CHANNEL_WEBAPP, message, method, params); + } + + public void publishToMember(final String memberID, final String method, final Object... params) + throws OverflowException { + PublishMessage message = new PublishMessage(); + message.setTargetType(PublishMessage.TargetType.MEMBER); + message.addTarget(memberID); + this.publish(CHANNEL_WEBAPP, message, method, params); + } + + public void publishToMemberSession(final String memberSessionID, final String method, final Object... params) + throws OverflowException { + PublishMessage message = new PublishMessage(); + message.setTargetType(PublishMessage.TargetType.MEMBER_SESSION); + message.addTarget(memberSessionID); + this.publish(CHANNEL_WEBAPP, message, method, params); + } + + public void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params) + throws OverflowException { + PublishMessage message = new PublishMessage(); + message.setTargetType(PublishMessage.TargetType.PROBE); + message.addTarget(tempProbeKey); + this.publish(CHANNEL_NOAUTH_PROBE, message, method, params); + } + + public void publishToProbe(final String probeKey, final String method, final Object... params) + throws OverflowException { + PublishMessage message = new PublishMessage(); + message.setTargetType(PublishMessage.TargetType.PROBE); + message.addTarget(probeKey); + this.publish(CHANNEL_PROBE, message, method, params); + } + + @Cacheable("memberListByDomain") + protected List getMemberListByDomainID(final long domainID) throws OverflowException { + return this.getMemberList(memberService.readAllByDomainID(domainID)); + } + + @Cacheable("memberListByProbeKey") + protected List getMemberListByProbeKey(final String probeKey) throws OverflowException { + return this.getMemberList(memberService.readAllByProbeKey(probeKey)); + } + + protected List getMemberList(final List members) { + List results = new ArrayList<>(members.size()); + for (Member member : members) { + results.add(member.getEmail()); } - public RedisMessagePublisher(final RedisTemplate redisTemplate, final Map topics) { - this.redisTemplate = redisTemplate; - this.topics = topics; - } - - public void publishToDomainMembers(final long domainID, final String method, final Object... params) throws OverflowException { - PublishMessage message = new PublishMessage(); - message.setTargetType(PublishMessage.TargetType.MEMBER); - message.setTargets(getMemberListByDomainID(domainID)); - this.publish(CHANNEL_WEBAPP, message, method, params); - } - public void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) throws OverflowException { - PublishMessage message = new PublishMessage(); - message.setTargetType(PublishMessage.TargetType.MEMBER); - message.setTargets(getMemberListByProbeKey(probeKey)); - this.publish(CHANNEL_WEBAPP, message, method, params); - } - - public void publishToMember(final String memberID, final String method, final Object... params) throws OverflowException { - PublishMessage message = new PublishMessage(); - message.setTargetType(PublishMessage.TargetType.MEMBER); - message.addTarget(memberID); - this.publish(CHANNEL_WEBAPP, message, method, params); - } - public void publishToMemberSession(final String memberSessionID, final String method, final Object... params) throws OverflowException { - PublishMessage message = new PublishMessage(); - message.setTargetType(PublishMessage.TargetType.MEMBER_SESSION); - message.addTarget(memberSessionID); - this.publish(CHANNEL_WEBAPP, message, method, params); - } - - public void publishToNoAuthProbe(final String tempProbeKey, final String method, final Object... params) throws OverflowException { - PublishMessage message = new PublishMessage(); - message.setTargetType(PublishMessage.TargetType.PROBE); - message.addTarget(tempProbeKey); - this.publish(CHANNEL_NOAUTH_PROBE, message, method, params); - } - - public void publishToProbe(final String probeKey, final String method, final Object... params) throws OverflowException { - PublishMessage message = new PublishMessage(); - message.setTargetType(PublishMessage.TargetType.PROBE); - message.addTarget(probeKey); - this.publish(CHANNEL_PROBE, message, method, params); - } - - - @Cacheable("memberListByDomain") - protected List getMemberListByDomainID(final long domainID) throws OverflowException { - return this.getMemberList(memberService.readAllByDomainID(domainID)); - } - - @Cacheable("memberListByProbeKey") - protected List getMemberListByProbeKey(final String probeKey) throws OverflowException { - return this.getMemberList(memberService.readAllByProbeKey(probeKey)); - } - - protected List getMemberList(final List members) { - List results = new ArrayList<>(members.size()); - for (Member member: members) { - results.add(member.getEmail()); - } - - return results; - } - - protected void publish(final String channel, PublishMessage message, final String method, Object... params) { - ChannelTopic topic = this.topics.get(channel); - message.setMessage(new PublishMessage.PublishMessageBody(method, this.getMessageBody(params))); - - try { - String json = this.objectMapper.writeValueAsString(message); - redisTemplate.convertAndSend(topic.getTopic(), json); - } catch (IOException e) { - e.printStackTrace(); - } - - } - - protected List getMessageBody(final Object... params) { - List results = new ArrayList<>(params.length); - try { - for (Object param : params) { - if (param.getClass().equals(String.class)) { - results.add((String)param); - } else { - results.add(objectMapper.writeValueAsString(param)); - } - } - } catch (IOException e) { - e.printStackTrace(); - } - return results; + return results; + } + + protected void publish(final String channel, PublishMessage message, final String method, Object... params) { + ChannelTopic topic = this.topics.get(channel); + message.setMessage(new PublishMessage.PublishMessageBody(method, this.getMessageBody(params))); + + String json = this.gson.toJson(message); + redisTemplate.convertAndSend(topic.getTopic(), json); + } + + protected List getMessageBody(final Object... params) { + List results = new ArrayList<>(params.length); + for (Object param : params) { + if (param.getClass().equals(String.class)) { + results.add((String) param); + } else { + results.add(this.gson.toJson(param)); + } } + return results; + } } diff --git a/src/main/java/com/loafle/overflow/central/spring/AppConfig.java b/src/main/java/com/loafle/overflow/central/spring/AppConfig.java index ccf4505..1459a96 100644 --- a/src/main/java/com/loafle/overflow/central/spring/AppConfig.java +++ b/src/main/java/com/loafle/overflow/central/spring/AppConfig.java @@ -1,7 +1,7 @@ package com.loafle.overflow.central.spring; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; +import com.google.gson.Gson; + import org.springframework.context.annotation.*; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @@ -9,45 +9,34 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; * Created by insanity on 17. 6. 13. */ @Configuration -@ComponentScan(basePackages = {"com.loafle.overflow"}, excludeFilters = @ComponentScan.Filter({Configuration.class})) -@Import({ - JdbcConfiguration.class, - MailConfiguration.class, - RedisConfiguration.class, - CacheConfiguration.class -}) -@PropertySource({ - "classpath:database.properties", - "classpath:mail.properties", - "classpath:redis.properties", - "classpath:cache.properties" -}) +@ComponentScan(basePackages = { + "com.loafle.overflow" }, excludeFilters = @ComponentScan.Filter({ Configuration.class })) +@Import({ JdbcConfiguration.class, MailConfiguration.class, RedisConfiguration.class, CacheConfiguration.class }) +@PropertySource({ "classpath:database.properties", "classpath:mail.properties", "classpath:redis.properties", + "classpath:cache.properties" }) public class AppConfig { -// @Bean -// public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { -// PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); -//// ppc.setLocation(new ClassPathResource("database.properties")); -// ppc.setLocations(new Resource[] { -// new ClassPathResource("database.properties"), -// new ClassPathResource("mail.properties"), -// new ClassPathResource("redis.properties") -// }); -// ppc.setIgnoreUnresolvablePlaceholders(true); -// -// return ppc; -// } - @Bean - public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { - return new PropertySourcesPlaceholderConfigurer(); - } + // @Bean + // public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() { + // PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer(); + //// ppc.setLocation(new ClassPathResource("database.properties")); + // ppc.setLocations(new Resource[] { + // new ClassPathResource("database.properties"), + // new ClassPathResource("mail.properties"), + // new ClassPathResource("redis.properties") + // }); + // ppc.setIgnoreUnresolvablePlaceholders(true); + // + // return ppc; + // } + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } - @Bean - public ObjectMapper getObjectMapper() { + @Bean + public Gson gson() { + Gson gson = new Gson(); - ObjectMapper objectMapper = new ObjectMapper(); - - objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - return objectMapper; - } + return gson; + } } diff --git a/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java b/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java index 6e4b54a..a7740a5 100644 --- a/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java +++ b/src/main/java/com/loafle/overflow/central/spring/JdbcConfiguration.java @@ -1,6 +1,5 @@ package com.loafle.overflow.central.spring; -import org.codehaus.jackson.map.ObjectMapper; import org.hibernate.cfg.Environment; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java index 5c3c7dd..0a07a0b 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraHostServiceTest.java @@ -1,5 +1,6 @@ package com.loafle.overflow.central.module.infra.service; +import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.infra.InfraHost; @@ -7,7 +8,6 @@ import com.loafle.overflow.model.infra.InfraOS; import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.service.central.infra.InfraHostService; -import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -26,6 +26,9 @@ public class InfraHostServiceTest { @Autowired private InfraHostService infraHostService; + @Autowired + private Gson gson; + @Test // @Ignore public void regist() throws Exception { @@ -55,8 +58,7 @@ public class InfraHostServiceTest { InfraHost infraHost = this.infraHostService.read(1); - ObjectMapper objectMapper = new ObjectMapper(); - String json = objectMapper.writeValueAsString(infraHost); + String json = gson.toJson(infraHost); System.out.println(json); diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraMachineServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraMachineServiceTest.java index 3496e53..95ce3ab 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraMachineServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraMachineServiceTest.java @@ -1,11 +1,11 @@ package com.loafle.overflow.central.module.infra.service; +import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.model.infra.InfraMachine; import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.service.central.infra.InfraMachineService; -import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -24,7 +24,10 @@ public class InfraMachineServiceTest { @Autowired private InfraMachineService infraMachineService; -// @Ignore + @Autowired + private Gson gson; + + // @Ignore @Test public void regist() throws Exception { @@ -49,8 +52,7 @@ public class InfraMachineServiceTest { InfraMachine infraMachine = this.infraMachineService.read(1); - ObjectMapper objectMapper = new ObjectMapper(); - String json = objectMapper.writeValueAsString(infraMachine); + String json = gson.toJson(infraMachine); System.out.println(json); } diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSApplicationServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSApplicationServiceTest.java index f72cb68..4d48a81 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSApplicationServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSApplicationServiceTest.java @@ -1,12 +1,12 @@ package com.loafle.overflow.central.module.infra.service; +import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.model.infra.InfraOS; import com.loafle.overflow.model.infra.InfraOSApplication; import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.service.central.infra.InfraOSApplicationService; -import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -24,6 +24,9 @@ public class InfraOSApplicationServiceTest { @Autowired private InfraOSApplicationService infraOSApplicationService; + @Autowired + private Gson gson; + // @Ignore @Test public void regist() throws Exception { @@ -53,9 +56,7 @@ public class InfraOSApplicationServiceTest { Assert.assertNotNull(infraOSApplication); - ObjectMapper objectMapper = new ObjectMapper(); - - String json = objectMapper.writeValueAsString(infraOSApplication); + String json = gson.toJson(infraOSApplication); System.out.println(json); } diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSDaemonServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSDaemonServiceTest.java index 37a4628..6fd0036 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSDaemonServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSDaemonServiceTest.java @@ -1,12 +1,12 @@ package com.loafle.overflow.central.module.infra.service; +import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.model.infra.InfraOS; import com.loafle.overflow.model.infra.InfraOSDaemon; import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.service.central.infra.InfraOSDaemonService; -import org.codehaus.jackson.map.ObjectMapper; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; @@ -24,6 +24,9 @@ public class InfraOSDaemonServiceTest { @Autowired private InfraOSDaemonService infraOSDaemonService; + @Autowired + private Gson gson; + // @Ignore @Test public void regist() throws Exception { @@ -52,8 +55,7 @@ public class InfraOSDaemonServiceTest { InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(1); Assert.assertNotNull(infraOSDaemon); - ObjectMapper objectMapper = new ObjectMapper(); - String json = objectMapper.writeValueAsString(infraOSDaemon); + String json = gson.toJson(infraOSDaemon); System.out.println(json); } diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSPortServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSPortServiceTest.java index 15f13d2..0b2c02e 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSPortServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSPortServiceTest.java @@ -1,5 +1,6 @@ package com.loafle.overflow.central.module.infra.service; +import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.core.exception.OverflowException; import com.loafle.overflow.model.infra.InfraOS; @@ -23,6 +24,8 @@ public class InfraOSPortServiceTest { @Autowired private InfraOSPortService infraOSPortService; + @Autowired + private Gson gson; // @Ignore @Test diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSServiceTest.java index 13a4b89..1360f15 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraOSServiceTest.java @@ -1,5 +1,6 @@ package com.loafle.overflow.central.module.infra.service; +import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.model.infra.InfraMachine; import com.loafle.overflow.model.infra.InfraOS; @@ -7,7 +8,6 @@ import com.loafle.overflow.model.meta.MetaInfraType; import com.loafle.overflow.model.meta.MetaInfraVendor; import com.loafle.overflow.service.central.infra.InfraOSService; -import org.codehaus.jackson.map.ObjectMapper; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +23,8 @@ public class InfraOSServiceTest { @Autowired private InfraOSService infraOSService; + @Autowired + private Gson gson; @Test // @Ignore @@ -53,8 +55,7 @@ public class InfraOSServiceTest { public void read() throws Exception { InfraOS infraOS = this.infraOSService.read(1); - ObjectMapper objectMapper = new ObjectMapper(); - String json = objectMapper.writeValueAsString(infraOS); + String json = gson.toJson(infraOS); System.out.println(json); } diff --git a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java index 3fef12e..d0570f3 100644 --- a/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java +++ b/src/test/java/com/loafle/overflow/central/module/infra/service/InfraServiceServiceTest.java @@ -1,5 +1,6 @@ package com.loafle.overflow.central.module.infra.service; +import com.google.gson.Gson; import com.loafle.overflow.central.spring.AppConfigTest; import com.loafle.overflow.model.infra.InfraHost; import com.loafle.overflow.model.infra.InfraService; @@ -23,5 +24,7 @@ public class InfraServiceServiceTest { @Autowired private InfraServiceService infraServiceService; + @Autowired + private Gson gson; } \ No newline at end of file diff --git a/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java b/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java index 913ee13..8159c07 100644 --- a/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java +++ b/src/test/java/com/loafle/overflow/central/spring/AppConfigTest.java @@ -1,7 +1,5 @@ package com.loafle.overflow.central.spring; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; import org.springframework.context.annotation.*; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @@ -12,6 +10,8 @@ import org.springframework.test.context.TestPropertySource; import static org.junit.Assert.*; +import com.google.gson.Gson; + /** * Created by geek on 17. 8. 8. */ @@ -51,12 +51,9 @@ public class AppConfigTest { } @Bean - public ObjectMapper getObjectMapper() { - - ObjectMapper objectMapper = new ObjectMapper(); - - objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - return objectMapper; + public Gson gson() { + Gson gson = new Gson(); + + return gson; } } \ No newline at end of file