提交 03c55336 编写于 作者: Y Yanick.xia 提交者: Liang Zhang

code style optimization (#3418)

* code style optimize

* Fix check bug

* Fix error logic code
上级 1df17e30
......@@ -30,6 +30,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
/**
* Implementation of Registry center configs repository.
......@@ -52,7 +53,7 @@ public final class YamlRegistryCenterConfigsRepositoryImpl implements RegistryCe
}
try (FileInputStream fileInputStream = new FileInputStream(file);
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8")) {
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8)) {
return new Yaml(new Constructor(RegistryCenterConfigs.class)).loadAs(inputStreamReader, RegistryCenterConfigs.class);
} catch (IOException e) {
throw new ShardingUIException(ShardingUIException.SERVER_ERROR, "load config error");
......
......@@ -43,6 +43,8 @@ public final class AuthenticationFilter implements Filter {
private static final String LOGIN_URI = "/api/login";
private final Gson gson = new Gson();
@Setter
private UserAuthenticationService userAuthenticationService;
......@@ -72,14 +74,14 @@ public final class AuthenticationFilter implements Filter {
private void handleLogin(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) {
try {
UserAccount user = new Gson().fromJson(httpRequest.getReader(), UserAccount.class);
UserAccount user = gson.fromJson(httpRequest.getReader(), UserAccount.class);
if (userAuthenticationService.checkUser(user)) {
httpResponse.setContentType("application/json");
httpResponse.setCharacterEncoding("UTF-8");
Map<String, Object> result = new HashMap<>();
result.put("username", userAuthenticationService.getUsername());
result.put("accessToken", userAuthenticationService.getToken());
httpResponse.getWriter().write(new Gson().toJson(ResponseResultUtil.build(result)));
httpResponse.getWriter().write(gson.toJson(ResponseResultUtil.build(result)));
} else {
respondWithUnauthorized(httpResponse);
}
......
......@@ -38,7 +38,6 @@ import org.apache.shardingsphere.core.yaml.swapper.impl.MasterSlaveRuleConfigura
import org.apache.shardingsphere.core.yaml.swapper.impl.ShardingRuleConfigurationYamlSwapper;
import org.apache.shardingsphere.orchestration.yaml.config.YamlDataSourceConfiguration;
import org.apache.shardingsphere.orchestration.yaml.swapper.DataSourceConfigurationYamlSwapper;
import java.util.Map;
import java.util.Properties;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册