Commit add097a3 by Nepxion

重构类结构

parent 9138da46
...@@ -40,4 +40,7 @@ public class DiscoveryConstant { ...@@ -40,4 +40,7 @@ public class DiscoveryConstant {
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
public static final String ENCODING_UTF_8 = "UTF-8"; public static final String ENCODING_UTF_8 = "UTF-8";
public static final String SEPARATE = ";"; public static final String SEPARATE = ";";
public static final String OK = "OK";
public static final String NO = "NO";
} }
\ No newline at end of file
...@@ -20,7 +20,7 @@ public class JsonUtil { ...@@ -20,7 +20,7 @@ public class JsonUtil {
static { static {
objectMapper = new ObjectMapper(); objectMapper = new ObjectMapper();
// objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")); // objectMapper.setDateFormat(new SimpleDateFormat(DiscoveryConstant.DATE_FORMAT));
} }
public static <T> String toJson(T object) { public static <T> String toJson(T object) {
......
...@@ -19,6 +19,7 @@ import org.springframework.http.MediaType; ...@@ -19,6 +19,7 @@ import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.entity.ResultEntity; import com.nepxion.discovery.common.entity.ResultEntity;
import com.nepxion.discovery.common.entity.RouterEntity; import com.nepxion.discovery.common.entity.RouterEntity;
import com.nepxion.discovery.common.handler.RestErrorHandler; import com.nepxion.discovery.common.handler.RestErrorHandler;
...@@ -81,7 +82,7 @@ public class ServiceController { ...@@ -81,7 +82,7 @@ public class ServiceController {
String result = restTemplate.postForEntity(url, entity, String.class).getBody(); String result = restTemplate.postForEntity(url, entity, String.class).getBody();
if (!StringUtils.equals(result, "OK") && !StringUtils.equals(result, "NO")) { if (!StringUtils.equals(result, DiscoveryConstant.OK) && !StringUtils.equals(result, DiscoveryConstant.NO)) {
result = RestUtil.getCause(restTemplate); result = RestUtil.getCause(restTemplate);
} }
...@@ -93,7 +94,7 @@ public class ServiceController { ...@@ -93,7 +94,7 @@ public class ServiceController {
String result = restTemplate.postForEntity(url, null, String.class).getBody(); String result = restTemplate.postForEntity(url, null, String.class).getBody();
if (!StringUtils.equals(result, "OK") && !StringUtils.equals(result, "NO")) { if (!StringUtils.equals(result, DiscoveryConstant.OK) && !StringUtils.equals(result, DiscoveryConstant.NO)) {
result = RestUtil.getCause(restTemplate); result = RestUtil.getCause(restTemplate);
} }
...@@ -132,7 +133,7 @@ public class ServiceController { ...@@ -132,7 +133,7 @@ public class ServiceController {
String result = restTemplate.postForEntity(url, entity, String.class).getBody(); String result = restTemplate.postForEntity(url, entity, String.class).getBody();
if (!StringUtils.equals(result, "OK")) { if (!StringUtils.equals(result, DiscoveryConstant.OK)) {
result = RestUtil.getCause(restTemplate); result = RestUtil.getCause(restTemplate);
} }
...@@ -153,7 +154,7 @@ public class ServiceController { ...@@ -153,7 +154,7 @@ public class ServiceController {
String result = restTemplate.postForEntity(url, null, String.class).getBody(); String result = restTemplate.postForEntity(url, null, String.class).getBody();
if (!StringUtils.equals(result, "OK")) { if (!StringUtils.equals(result, DiscoveryConstant.OK)) {
result = RestUtil.getCause(restTemplate); result = RestUtil.getCause(restTemplate);
} }
...@@ -174,7 +175,7 @@ public class ServiceController { ...@@ -174,7 +175,7 @@ public class ServiceController {
String result = restTemplate.postForEntity(url, version, String.class).getBody(); String result = restTemplate.postForEntity(url, version, String.class).getBody();
if (!StringUtils.equals(result, "OK")) { if (!StringUtils.equals(result, DiscoveryConstant.OK)) {
result = RestUtil.getCause(restTemplate); result = RestUtil.getCause(restTemplate);
} }
...@@ -195,7 +196,7 @@ public class ServiceController { ...@@ -195,7 +196,7 @@ public class ServiceController {
String result = restTemplate.postForEntity(url, null, String.class).getBody(); String result = restTemplate.postForEntity(url, null, String.class).getBody();
if (!StringUtils.equals(result, "OK")) { if (!StringUtils.equals(result, DiscoveryConstant.OK)) {
result = RestUtil.getCause(restTemplate); result = RestUtil.getCause(restTemplate);
} }
......
...@@ -233,7 +233,7 @@ public class ConsoleEndpoint { ...@@ -233,7 +233,7 @@ public class ConsoleEndpoint {
try { try {
boolean result = configAdapter.updateConfig(group, serviceId, config); boolean result = configAdapter.updateConfig(group, serviceId, config);
return ResponseEntity.ok().body(result ? "OK" : "NO"); return ResponseEntity.ok().body(result ? DiscoveryConstant.OK : DiscoveryConstant.NO);
} catch (Exception e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
} }
...@@ -249,7 +249,7 @@ public class ConsoleEndpoint { ...@@ -249,7 +249,7 @@ public class ConsoleEndpoint {
try { try {
boolean result = configAdapter.clearConfig(group, serviceId); boolean result = configAdapter.clearConfig(group, serviceId);
return ResponseEntity.ok().body(result ? "OK" : "NO"); return ResponseEntity.ok().body(result ? DiscoveryConstant.OK : DiscoveryConstant.NO);
} catch (Exception e) { } catch (Exception e) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
} }
......
...@@ -60,7 +60,7 @@ public abstract class AbstractRestInvoker { ...@@ -60,7 +60,7 @@ public abstract class AbstractRestInvoker {
checkPermission(serviceInstance); checkPermission(serviceInstance);
result = doRest(url); result = doRest(url);
if (!StringUtils.equals(result, "OK")) { if (!StringUtils.equals(result, DiscoveryConstant.OK)) {
result = RestUtil.getCause(restTemplate); result = RestUtil.getCause(restTemplate);
} }
} catch (Exception e) { } catch (Exception e) {
......
...@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -30,6 +30,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.nepxion.discovery.common.constant.DiscoveryConstant;
import com.nepxion.discovery.common.entity.RuleEntity; import com.nepxion.discovery.common.entity.RuleEntity;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter; import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.framework.context.PluginContextAware; import com.nepxion.discovery.plugin.framework.context.PluginContextAware;
...@@ -109,7 +110,7 @@ public class ConfigEndpoint { ...@@ -109,7 +110,7 @@ public class ConfigEndpoint {
// return ResponseEntity.ok().build(); // return ResponseEntity.ok().build();
return ResponseEntity.ok().body("OK"); return ResponseEntity.ok().body(DiscoveryConstant.OK);
} }
private ResponseEntity<?> clear(boolean async) { private ResponseEntity<?> clear(boolean async) {
...@@ -125,7 +126,7 @@ public class ConfigEndpoint { ...@@ -125,7 +126,7 @@ public class ConfigEndpoint {
pluginEventWapper.fireRuleCleared(new RuleClearedEvent(), async); pluginEventWapper.fireRuleCleared(new RuleClearedEvent(), async);
return ResponseEntity.ok().body("OK"); return ResponseEntity.ok().body(DiscoveryConstant.OK);
} }
private ResponseEntity<List<String>> view(boolean async) { private ResponseEntity<List<String>> view(boolean async) {
......
...@@ -115,7 +115,7 @@ public class VersionEndpoint { ...@@ -115,7 +115,7 @@ public class VersionEndpoint {
pluginEventWapper.fireVersionUpdated(new VersionUpdatedEvent(dynamicVersion, localVersion), async); pluginEventWapper.fireVersionUpdated(new VersionUpdatedEvent(dynamicVersion, localVersion), async);
return ResponseEntity.ok().body("OK"); return ResponseEntity.ok().body(DiscoveryConstant.OK);
} }
private ResponseEntity<?> clear(String version, boolean async) { private ResponseEntity<?> clear(String version, boolean async) {
...@@ -131,7 +131,7 @@ public class VersionEndpoint { ...@@ -131,7 +131,7 @@ public class VersionEndpoint {
pluginEventWapper.fireVersionCleared(new VersionClearedEvent(version), async); pluginEventWapper.fireVersionCleared(new VersionClearedEvent(version), async);
return ResponseEntity.ok().body("OK"); return ResponseEntity.ok().body(DiscoveryConstant.OK);
} }
private ResponseEntity<List<String>> view(boolean async) { private ResponseEntity<List<String>> view(boolean async) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment