ing
This commit is contained in:
parent
b8971008be
commit
b48500832b
22
.vscode/test-launch.json
vendored
Normal file
22
.vscode/test-launch.json
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"run": [
|
||||
{
|
||||
"name": "central",
|
||||
"projectName": "central",
|
||||
"workingDirectory": "/project/loafle/overflow/central",
|
||||
"args": [],
|
||||
"vmargs": [],
|
||||
"preLaunchTask": ""
|
||||
}
|
||||
],
|
||||
"debug": [
|
||||
{
|
||||
"name": "central",
|
||||
"projectName": "central",
|
||||
"workingDirectory": "/project/loafle/overflow/central",
|
||||
"args": [],
|
||||
"vmargs": [],
|
||||
"preLaunchTask": ""
|
||||
}
|
||||
]
|
||||
}
|
18
pom.xml
18
pom.xml
|
@ -17,6 +17,8 @@
|
|||
<name>com.loafle.overflow.central</name>
|
||||
|
||||
<properties>
|
||||
<commons.rpc-java.version>1.0.0-SNAPSHOT</commons.rpc-java.version>
|
||||
|
||||
<grpc.version>1.2.0</grpc.version>
|
||||
<jedis.version>2.9.0</jedis.version>
|
||||
<caffeine.version>2.5.6</caffeine.version>
|
||||
|
@ -25,7 +27,8 @@
|
|||
<spring.data.jpa.version>1.11.4.RELEASE</spring.data.jpa.version>
|
||||
<spring.data.redis.version>1.8.7.RELEASE</spring.data.redis.version>
|
||||
<spring.crypto.version>4.2.3.RELEASE</spring.crypto.version>
|
||||
<gson.version>2.8.2</gson.version>
|
||||
<!-- <gson.version>2.8.2</gson.version> -->
|
||||
<jackson.mapper.version>1.9.13</jackson.mapper.version>
|
||||
<hibernate.version>5.2.10.Final</hibernate.version>
|
||||
<javax.mail.version>1.4.7</javax.mail.version>
|
||||
<javax.mail-api.version>1.6.0</javax.mail-api.version>
|
||||
|
@ -37,6 +40,12 @@
|
|||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.loafle.commons</groupId>
|
||||
<artifactId>rpc-java</artifactId>
|
||||
<version>${commons.rpc-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.grpc</groupId>
|
||||
<artifactId>grpc-netty</artifactId>
|
||||
|
@ -118,10 +127,15 @@
|
|||
<version>${spring.crypto.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.version}</version>
|
||||
</dependency> -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.jackson</groupId>
|
||||
<artifactId>jackson-mapper-asl</artifactId>
|
||||
<version>${jackson.mapper.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mail -->
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
package com.loafle.overflow.central.commons.stereotype;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ProbeAPI {
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.loafle.overflow.central.commons.stereotype;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface WebappAPI {
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
package com.loafle.overflow.central.module.auth.service;
|
||||
|
||||
|
||||
import com.loafle.overflow.central.module.auth.dao.AuthCrawlerDAO;
|
||||
|
||||
|
||||
import com.loafle.overflow.central.module.infra.service.CentralInfraService;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.model.auth.AuthCrawler;
|
||||
|
@ -28,7 +26,8 @@ public class CentralAuthCrawlerService implements AuthCrawlerService {
|
|||
|
||||
public AuthCrawler regist(AuthCrawler authCrawler) {
|
||||
|
||||
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByCrawlerAndTarget(authCrawler.getCrawler(), authCrawler.getTarget());
|
||||
AuthCrawler dbAuthCrawler = this.authCrawlerDAO.findByCrawlerAndTarget(authCrawler.getCrawler(),
|
||||
authCrawler.getTarget());
|
||||
|
||||
if (authCrawler == null) {
|
||||
return this.authCrawlerDAO.save(authCrawler);
|
||||
|
@ -41,7 +40,6 @@ public class CentralAuthCrawlerService implements AuthCrawlerService {
|
|||
return this.authCrawlerDAO.save(dbAuthCrawler);
|
||||
}
|
||||
|
||||
|
||||
public boolean checkAuthCrawler(long infraId, MetaCrawler crawler, String authJson) throws OverflowException {
|
||||
|
||||
Infra infra = this.infraService.read(infraId);
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
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;
|
||||
import com.loafle.overflow.model.auth.AuthCrawler;
|
||||
import com.loafle.overflow.model.infra.Infra;
|
||||
|
@ -19,6 +16,8 @@ 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;
|
||||
|
||||
|
@ -42,7 +41,7 @@ public class InfraHostGenerator {
|
|||
private AuthCrawlerService authCrawlerService;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
|
||||
|
||||
|
@ -73,7 +72,7 @@ public class InfraHostGenerator {
|
|||
this.infraHostWMIGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
|
||||
}
|
||||
|
||||
return gson.toJson(sensorConfig);
|
||||
return objectMapper.writeValueAsString(sensorConfig);
|
||||
}
|
||||
|
||||
private Target createTarget(InfraHost infraHost, Sensor dbSensor) throws Exception {
|
||||
|
@ -88,7 +87,7 @@ public class InfraHostGenerator {
|
|||
Connection connection = new Connection();
|
||||
connection.setIp(StringConvertor.intToIp(infraHost.getIp()));
|
||||
|
||||
HashMap<String, String> optionMap = this.gson.fromJson(authCrawler.getAuthJson(), TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
|
||||
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference<Map<String, String>>(){});
|
||||
|
||||
if (dbSensor.getCrawler().getId() == MetaCrawlerEnum.WMI_CRAWLER.getValue()) {
|
||||
connection.setPort(135);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
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;
|
||||
|
@ -11,10 +9,11 @@ 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -30,7 +29,7 @@ public class InfraHostWMIGenerator {
|
|||
private GenerateUtil generateUtil;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
|
||||
SensorConfig sensorConfig) throws Exception {
|
||||
|
@ -87,7 +86,7 @@ public class InfraHostWMIGenerator {
|
|||
|
||||
String json = tempItemKey.getOption();
|
||||
if (json != null && json.length() > 0) {
|
||||
HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
|
||||
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){});
|
||||
|
||||
Object obj = null;
|
||||
obj = optionMap.get("appends");
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
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;
|
||||
|
@ -18,10 +16,11 @@ 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -45,7 +44,7 @@ public class InfraServiceGenerator {
|
|||
private AuthCrawlerService authCrawlerService;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public String process(Sensor dbSensor, List<SensorItem> sensorItems, Infra infra) throws Exception {
|
||||
com.loafle.overflow.model.infra.InfraService infraService = (com.loafle.overflow.model.infra.InfraService)infra;
|
||||
|
@ -78,7 +77,7 @@ public class InfraServiceGenerator {
|
|||
this.infraServiceJMXGenerator.process(sensorItems, keyMap, dbSensor, sensorConfig);
|
||||
}
|
||||
|
||||
return gson.toJson(sensorConfig);
|
||||
return objectMapper.writeValueAsString(sensorConfig);
|
||||
}
|
||||
|
||||
private Target createTarget(InfraService infraService, Sensor sensor) throws Exception {
|
||||
|
@ -98,7 +97,7 @@ public class InfraServiceGenerator {
|
|||
|
||||
target.setConnection(connection);
|
||||
|
||||
HashMap<String, String> optionMap = this.gson.fromJson(authCrawler.getAuthJson(), TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
|
||||
HashMap<String, String> optionMap = this.objectMapper.readValue(authCrawler.getAuthJson(), new TypeReference<Map<String, String>>(){});
|
||||
|
||||
Map<String, Object> auth = new HashMap<>();
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
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;
|
||||
|
@ -11,6 +9,8 @@ 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,7 +29,7 @@ public class InfraServiceJMXGenerator {
|
|||
private GenerateUtil generateUtil;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
|
||||
SensorConfig sensorConfig) throws Exception {
|
||||
|
@ -73,7 +73,7 @@ public class InfraServiceJMXGenerator {
|
|||
List<String> arrayCol = null;
|
||||
|
||||
if (json != null && json.length() > 0) {
|
||||
HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
|
||||
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){});
|
||||
|
||||
Object obj = null;
|
||||
obj = optionMap.get("aliases");
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
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;
|
||||
import com.loafle.overflow.model.sensor.SensorItem;
|
||||
|
@ -12,10 +9,11 @@ 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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -30,7 +28,7 @@ public class InfraServiceMysqlGenerator {
|
|||
@Autowired
|
||||
private GenerateUtil generateUtil;
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public void process(List<SensorItem> sensorItems, Map<Integer, MetaSensorItemKey> keyMap, Sensor dbSensor,
|
||||
SensorConfig sensorConfig) throws Exception {
|
||||
|
@ -83,7 +81,7 @@ public class InfraServiceMysqlGenerator {
|
|||
|
||||
String json = tempItemKey.getOption();
|
||||
if (json != null && json.length() > 0) {
|
||||
HashMap<String, String> optionMap = this.gson.fromJson(json, TypeToken.getParameterized(HashMap.class, String.class, String.class).getType());
|
||||
HashMap<String, String> optionMap = this.objectMapper.readValue(json, new TypeReference<Map<String, String>>(){});
|
||||
|
||||
Object obj = null;
|
||||
obj = optionMap.get("valueColumn");
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.loafle.overflow.central.module.member.service;
|
||||
|
||||
import com.loafle.overflow.central.commons.stereotype.WebappAPI;
|
||||
import com.loafle.overflow.core.annotation.WebappAPI;
|
||||
import com.loafle.overflow.central.commons.utils.EmailSender;
|
||||
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
||||
import com.loafle.overflow.central.module.email.service.EmailAuthService;
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
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;
|
||||
import com.loafle.overflow.core.annotation.ProbeAPI;
|
||||
import com.loafle.overflow.core.annotation.WebappAPI;
|
||||
import com.loafle.overflow.central.commons.utils.GenerateKey;
|
||||
import com.loafle.overflow.central.commons.utils.SessionMetadata;
|
||||
import com.loafle.overflow.central.commons.utils.StringConvertor;
|
||||
import com.loafle.overflow.central.module.infra.service.CentralInfraMachineService;
|
||||
import com.loafle.overflow.central.module.infra.service.CentralInfraOSService;
|
||||
import com.loafle.overflow.central.module.noauthprobe.dao.NoAuthProbeDAO;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
import com.loafle.overflow.model.apikey.ApiKey;
|
||||
|
@ -35,10 +31,13 @@ import com.loafle.overflow.service.central.noauthprobe.NoAuthProbeService;
|
|||
import com.loafle.overflow.service.central.probe.ProbeHostService;
|
||||
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;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -68,7 +67,7 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
|||
private DomainMemberService domainMemberService;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Autowired
|
||||
private InfraMachineService infraMachineService;
|
||||
|
@ -106,8 +105,13 @@ public class CentralNoAuthProbeService implements NoAuthProbeService {
|
|||
@Transactional
|
||||
public List<NoAuthProbe> acceptNoAuthProbe(NoAuthProbe noAuthProbe) throws OverflowException {
|
||||
|
||||
HashMap<String, Object> objMap = this.gson.fromJson(noAuthProbe.getDescription(),
|
||||
TypeToken.getParameterized(HashMap.class, String.class, Object.class).getType());
|
||||
HashMap<String, Object> objMap;
|
||||
try {
|
||||
objMap = this.objectMapper.readValue(noAuthProbe.getDescription(), new TypeReference<Map<String, Object>>(){});
|
||||
} catch (IOException e) {
|
||||
throw new OverflowException("json error", e);
|
||||
}
|
||||
|
||||
Map<String, String> hostMap = (Map<String, String>) objMap.get("host");
|
||||
Map<String, String> netMap = (Map<String, String>) objMap.get("network");
|
||||
|
||||
|
|
|
@ -7,16 +7,14 @@ import io.grpc.*;
|
|||
public class ProxyServerInterceptor implements ServerInterceptor {
|
||||
|
||||
@Override
|
||||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
|
||||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
|
||||
ServerCallHandler<ReqT, RespT> next) {
|
||||
String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY);
|
||||
String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY);
|
||||
String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY);
|
||||
|
||||
Context ctx = Context.current().withValues(
|
||||
SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType,
|
||||
SessionMetadata.CTX_SESSION_ID_KEY, sessionID,
|
||||
SessionMetadata.CTX_TARGET_ID_KEY, targetID
|
||||
);
|
||||
Context ctx = Context.current().withValues(SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType,
|
||||
SessionMetadata.CTX_SESSION_ID_KEY, sessionID, SessionMetadata.CTX_TARGET_ID_KEY, targetID);
|
||||
|
||||
return Contexts.interceptCall(ctx, call, headers, next);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package com.loafle.overflow.central.proxy;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.internal.Primitives;
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.codehaus.jackson.type.JavaType;
|
||||
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;
|
||||
|
@ -20,16 +22,15 @@ import java.util.Map;
|
|||
*/
|
||||
@Component
|
||||
public class ServiceInvoker {
|
||||
// @Autowired
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
private Map<String, Cache> serviceCacheMap;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
public ServiceInvoker(ApplicationContext context) {
|
||||
this.context = context;
|
||||
public ServiceInvoker() {
|
||||
serviceCacheMap = new HashMap<>();
|
||||
}
|
||||
|
||||
|
@ -75,7 +76,8 @@ public class ServiceInvoker {
|
|||
}
|
||||
|
||||
private Method getMethod(String methodName) {
|
||||
Class<?> clazz = AopUtils.getTargetClass(serviceCache.bean);
|
||||
// Class<?> clazz = AopUtils.getTargetClass(serviceCache.bean);
|
||||
Class<?> clazz = serviceCache.bean.getClass();
|
||||
Method[] methods = clazz.getMethods();
|
||||
|
||||
Method targetMethod = null;
|
||||
|
@ -117,7 +119,16 @@ public class ServiceInvoker {
|
|||
}
|
||||
|
||||
private Object getValue(Type parameterType, String json) throws IllegalArgumentException {
|
||||
return this.gson.fromJson(json, parameterType);
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
private Object[] getParameters(Type[] parameterTypes, List<ByteString> params) throws IllegalArgumentException {
|
||||
|
@ -174,7 +185,11 @@ public class ServiceInvoker {
|
|||
throw new OverflowException("internal error", e);
|
||||
}
|
||||
|
||||
jsonInString = this.gson.toJson(result);
|
||||
try {
|
||||
jsonInString = objectMapper.writeValueAsString(result);
|
||||
} catch (IOException e) {
|
||||
throw new OverflowException("InternalError");
|
||||
}
|
||||
|
||||
return jsonInString;
|
||||
}
|
||||
|
|
|
@ -3,14 +3,17 @@ package com.loafle.overflow.central.proxy;
|
|||
import com.loafle.overflow.central.api.CentralAPIGrpc;
|
||||
import com.loafle.overflow.central.api.ServerInput;
|
||||
import com.loafle.overflow.central.api.ServerOutput;
|
||||
import com.loafle.overflow.central.spring.AppConfig;
|
||||
import com.loafle.overflow.core.exception.OverflowException;
|
||||
|
||||
import io.grpc.*;
|
||||
import io.grpc.Status.Code;
|
||||
import io.grpc.netty.NettyServerBuilder;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
@ -25,12 +28,13 @@ public class ServiceProxy {
|
|||
private ApplicationContext ctx;
|
||||
|
||||
public void start(int port) throws IOException {
|
||||
ctx = new AnnotationConfigApplicationContext("com.loafle.overflow");
|
||||
ctx = new AnnotationConfigApplicationContext(AppConfig.class);
|
||||
|
||||
ProxyServerInterceptor proxyServerInterceptor = new ProxyServerInterceptor();
|
||||
ServiceImpl serviceImpl = ctx.getBean(ServiceImpl.class);
|
||||
|
||||
server = NettyServerBuilder.forPort(port)
|
||||
.addService(ServerInterceptors.intercept(new ServiceImpl(new ServiceInvoker(ctx)), proxyServerInterceptor))
|
||||
.addService(ServerInterceptors.intercept(serviceImpl, proxyServerInterceptor))
|
||||
.build().start();
|
||||
logger.info("Server started, listening on " + port);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
|
@ -56,8 +60,10 @@ public class ServiceProxy {
|
|||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
static class ServiceImpl extends CentralAPIGrpc.CentralAPIImplBase {
|
||||
|
||||
@Autowired
|
||||
private ServiceInvoker serviceInvoker;
|
||||
|
||||
ServiceImpl(ServiceInvoker serviceInvoker) {
|
||||
|
@ -99,3 +105,4 @@ public class ServiceProxy {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ 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;
|
||||
|
@ -27,7 +28,7 @@ public class RedisMessagePublisher implements MessagePublisher {
|
|||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
@Autowired
|
||||
private MemberService memberService;
|
||||
|
||||
|
@ -113,8 +114,12 @@ public class RedisMessagePublisher implements MessagePublisher {
|
|||
ChannelTopic topic = this.topics.get(channel);
|
||||
message.setMessage(new PublishMessage.PublishMessageBody(method, this.getMessageBody(params)));
|
||||
|
||||
String json = this.gson.toJson(message);
|
||||
try {
|
||||
String json = this.objectMapper.writeValueAsString(message);
|
||||
redisTemplate.convertAndSend(topic.getTopic(), json);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected List<String> getMessageBody(final Object... params) {
|
||||
|
@ -123,7 +128,12 @@ public class RedisMessagePublisher implements MessagePublisher {
|
|||
if (param.getClass().equals(String.class)) {
|
||||
results.add((String) param);
|
||||
} else {
|
||||
results.add(this.gson.toJson(param));
|
||||
try {
|
||||
String json = this.objectMapper.writeValueAsString(param);
|
||||
results.add(json);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.loafle.overflow.central.spring;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.codehaus.jackson.map.DeserializationConfig;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
|
||||
|
@ -29,14 +29,22 @@ public class AppConfig {
|
|||
// return ppc;
|
||||
// }
|
||||
@Bean
|
||||
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||
public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||
return new PropertySourcesPlaceholderConfigurer();
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public Gson gson() {
|
||||
// GsonBuilder builder = new GsonBuilder();
|
||||
// builder.excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.PRIVATE);
|
||||
// // builder.excludeFieldsWithoutExposeAnnotation();
|
||||
// return builder.create();
|
||||
// }
|
||||
@Bean
|
||||
public Gson gson() {
|
||||
Gson gson = new Gson();
|
||||
public ObjectMapper getObjectMapper() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
return gson;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ 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;
|
||||
|
@ -27,7 +28,7 @@ public class InfraHostServiceTest {
|
|||
private InfraHostService infraHostService;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Test
|
||||
// @Ignore
|
||||
|
@ -58,7 +59,7 @@ public class InfraHostServiceTest {
|
|||
|
||||
InfraHost infraHost = this.infraHostService.read(1);
|
||||
|
||||
String json = gson.toJson(infraHost);
|
||||
String json = objectMapper.writeValueAsString(infraHost);
|
||||
|
||||
System.out.println(json);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ 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;
|
||||
|
@ -25,7 +26,7 @@ public class InfraMachineServiceTest {
|
|||
private InfraMachineService infraMachineService;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
// @Ignore
|
||||
@Test
|
||||
|
@ -52,7 +53,7 @@ public class InfraMachineServiceTest {
|
|||
|
||||
InfraMachine infraMachine = this.infraMachineService.read(1);
|
||||
|
||||
String json = gson.toJson(infraMachine);
|
||||
String json = objectMapper.writeValueAsString(infraMachine);
|
||||
System.out.println(json);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ 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;
|
||||
|
@ -25,7 +26,7 @@ public class InfraOSApplicationServiceTest {
|
|||
private InfraOSApplicationService infraOSApplicationService;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
// @Ignore
|
||||
@Test
|
||||
|
@ -56,7 +57,7 @@ public class InfraOSApplicationServiceTest {
|
|||
|
||||
Assert.assertNotNull(infraOSApplication);
|
||||
|
||||
String json = gson.toJson(infraOSApplication);
|
||||
String json = objectMapper.writeValueAsString(infraOSApplication);
|
||||
System.out.println(json);
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ 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;
|
||||
|
@ -25,7 +26,7 @@ public class InfraOSDaemonServiceTest {
|
|||
private InfraOSDaemonService infraOSDaemonService;
|
||||
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
// @Ignore
|
||||
@Test
|
||||
|
@ -55,7 +56,7 @@ public class InfraOSDaemonServiceTest {
|
|||
InfraOSDaemon infraOSDaemon = this.infraOSDaemonService.read(1);
|
||||
Assert.assertNotNull(infraOSDaemon);
|
||||
|
||||
String json = gson.toJson(infraOSDaemon);
|
||||
String json = objectMapper.writeValueAsString(infraOSDaemon);
|
||||
System.out.println(json);
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.loafle.overflow.model.infra.InfraOSPort;
|
|||
import com.loafle.overflow.model.meta.MetaInfraType;
|
||||
import com.loafle.overflow.service.central.infra.InfraOSPortService;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -25,7 +26,7 @@ public class InfraOSPortServiceTest {
|
|||
@Autowired
|
||||
private InfraOSPortService infraOSPortService;
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
// @Ignore
|
||||
@Test
|
||||
|
|
|
@ -8,6 +8,7 @@ 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;
|
||||
|
@ -24,7 +25,7 @@ public class InfraOSServiceTest {
|
|||
@Autowired
|
||||
private InfraOSService infraOSService;
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@Test
|
||||
// @Ignore
|
||||
|
@ -55,7 +56,7 @@ public class InfraOSServiceTest {
|
|||
public void read() throws Exception {
|
||||
|
||||
InfraOS infraOS = this.infraOSService.read(1);
|
||||
String json = gson.toJson(infraOS);
|
||||
String json = objectMapper.writeValueAsString(infraOS);
|
||||
System.out.println(json);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.loafle.overflow.model.meta.MetaInfraType;
|
|||
import com.loafle.overflow.model.meta.MetaInfraVendor;
|
||||
import com.loafle.overflow.service.central.infra.InfraServiceService;
|
||||
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -25,6 +26,6 @@ public class InfraServiceServiceTest {
|
|||
@Autowired
|
||||
private InfraServiceService infraServiceService;
|
||||
@Autowired
|
||||
private Gson gson;
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
}
|
|
@ -1,17 +1,13 @@
|
|||
package com.loafle.overflow.central.spring;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.codehaus.jackson.map.DeserializationConfig;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.springframework.context.annotation.*;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* Created by geek on 17. 8. 8.
|
||||
*/
|
||||
|
@ -51,9 +47,10 @@ public class AppConfigTest {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public Gson gson() {
|
||||
Gson gson = new Gson();
|
||||
public ObjectMapper getObjectMapper() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
||||
|
||||
return gson;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user