解决Windows中文乱码问题

master
fengfei 7 years ago
parent 70e3c242de
commit 34cab56437
  1. 6
      pom.xml
  2. 5
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/ProxyConfig.java
  3. 9
      proxy-server/src/main/java/org/fengfei/lanproxy/server/config/web/routes/RouteConfig.java
  4. 2
      proxy-server/src/test/resources/config.properties

@ -8,6 +8,11 @@
<version>0.1</version>
<name>lanproxy</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
</properties>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
@ -46,6 +51,7 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>

@ -6,6 +6,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -170,7 +171,7 @@ public class ProxyConfig implements Serializable {
}
in.close();
proxyMappingConfigJson = new String(out.toByteArray());
proxyMappingConfigJson = new String(out.toByteArray(), Charset.forName("UTF-8"));
}
} catch (Exception e) {
throw new RuntimeException(e);
@ -212,7 +213,7 @@ public class ProxyConfig implements Serializable {
try {
FileOutputStream out = new FileOutputStream(file);
out.write(proxyMappingConfigJson.getBytes());
out.write(proxyMappingConfigJson.getBytes(Charset.forName("UTF-8")));
out.flush();
out.close();
} catch (Exception e) {

@ -1,5 +1,6 @@
package org.fengfei.lanproxy.server.config.web.routes;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@ -59,7 +60,8 @@ public class RouteConfig {
String auth = request.headers().get(HttpHeaders.Names.AUTHORIZATION);
if (!authenticated && auth != null) {
String[] authArr = auth.split(" ");
if (authArr.length == 2 && authArr[0].equals(ProxyConfig.getInstance().getConfigAdminUsername()) && authArr[1].equals(ProxyConfig.getInstance().getConfigAdminPassword())) {
if (authArr.length == 2 && authArr[0].equals(ProxyConfig.getInstance().getConfigAdminUsername())
&& authArr[1].equals(ProxyConfig.getInstance().getConfigAdminPassword())) {
authenticated = true;
}
}
@ -89,7 +91,7 @@ public class RouteConfig {
public ResponseInfo request(FullHttpRequest request) {
byte[] buf = new byte[request.content().readableBytes()];
request.content().readBytes(buf);
String config = new String(buf);
String config = new String(buf, Charset.forName("UTF-8"));
List<Client> clients = JsonUtil.json2object(config, new TypeToken<List<Client>>() {
});
if (clients == null) {
@ -126,7 +128,8 @@ public class RouteConfig {
return ResponseInfo.build(ResponseInfo.CODE_INVILID_PARAMS, "Error username or password");
}
if (username.equals(ProxyConfig.getInstance().getConfigAdminUsername()) && password.equals(ProxyConfig.getInstance().getConfigAdminPassword())) {
if (username.equals(ProxyConfig.getInstance().getConfigAdminUsername())
&& password.equals(ProxyConfig.getInstance().getConfigAdminPassword())) {
token = UUID.randomUUID().toString().replace("-", "");
return ResponseInfo.build(token);
}

@ -10,6 +10,6 @@ server.ssl.keyManagerPassword=123456
server.ssl.needsClientAuth=false
config.server.bind=0.0.0.0
config.server.port=8082
config.server.port=8090
config.admin.username=admin
config.admin.password=admin
Loading…
Cancel
Save