Commit e4b1dc3d by Nepxion

优化代码

parent 5b266993
......@@ -57,23 +57,7 @@ public class ConfigEndpoint implements MvcEndpoint {
@ResponseBody
@ManagedOperation
public ResponseEntity<?> sendAsync(@RequestBody @ApiParam(value = "规则配置内容,XML格式", required = true) String config) {
Boolean discoveryControlEnabled = pluginContextAware.isDiscoveryControlEnabled();
if (!discoveryControlEnabled) {
// return new ResponseEntity<>(Collections.singletonMap("Message", "Discovery control is disabled"), HttpStatus.NOT_FOUND);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Discovery control is disabled");
}
try {
InputStream inputStream = IOUtils.toInputStream(config, PluginConstant.ENCODING_UTF_8);
pluginEventWapper.fireRuleChanged(new RuleChangedEvent(inputStream), true);
} catch (IOException e) {
return toExceptionResponseEntity(e, true);
}
// return ResponseEntity.ok().build();
return ResponseEntity.ok().body("OK");
return send(config, true);
}
@RequestMapping(path = "/config/send-sync", method = RequestMethod.POST)
......@@ -81,19 +65,7 @@ public class ConfigEndpoint implements MvcEndpoint {
@ResponseBody
@ManagedOperation
public ResponseEntity<?> sendSync(@RequestBody @ApiParam(value = "规则配置内容,XML格式", required = true) String config) {
Boolean discoveryControlEnabled = pluginContextAware.isDiscoveryControlEnabled();
if (!discoveryControlEnabled) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Discovery control is disabled");
}
try {
InputStream inputStream = IOUtils.toInputStream(config, PluginConstant.ENCODING_UTF_8);
pluginEventWapper.fireRuleChanged(new RuleChangedEvent(inputStream), false);
} catch (IOException e) {
return toExceptionResponseEntity(e, true);
}
return ResponseEntity.ok().body("OK");
return send(config, false);
}
@RequestMapping(path = "/config/view", method = RequestMethod.GET)
......@@ -111,6 +83,26 @@ public class ConfigEndpoint implements MvcEndpoint {
return ResponseEntity.ok().body(content);
}
private ResponseEntity<?> send(String config, boolean async) {
Boolean discoveryControlEnabled = pluginContextAware.isDiscoveryControlEnabled();
if (!discoveryControlEnabled) {
// return new ResponseEntity<>(Collections.singletonMap("Message", "Discovery control is disabled"), HttpStatus.NOT_FOUND);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Discovery control is disabled");
}
try {
InputStream inputStream = IOUtils.toInputStream(config, PluginConstant.ENCODING_UTF_8);
pluginEventWapper.fireRuleChanged(new RuleChangedEvent(inputStream), async);
} catch (IOException e) {
return toExceptionResponseEntity(e, true);
}
// return ResponseEntity.ok().build();
return ResponseEntity.ok().body("OK");
}
private ResponseEntity<String> toExceptionResponseEntity(Exception e, boolean showDetail) {
String message = null;
if (showDetail) {
......
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