optimized private server source
This commit is contained in:
6
.idea/inspectionProfiles/Project_Default.xml
generated
6
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,6 +1,12 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="Duplicates" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Java>
|
||||
<minSize>60</minSize>
|
||||
<isEnabled>true</isEnabled>
|
||||
</Java>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="SpringJavaInjectionPointsAutowiringInspection" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
||||
@@ -14,7 +14,7 @@ import net.irext.server.service.model.ACParameters;
|
||||
*/
|
||||
public class ACParametersResponse extends ServiceResponse {
|
||||
|
||||
ACParameters entity;
|
||||
private ACParameters entity;
|
||||
|
||||
public ACParametersResponse(Status status, ACParameters entity) {
|
||||
super(status);
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
package net.irext.server.service.response;
|
||||
|
||||
public class CategoryResponse {
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package net.irext.server.service.restapi;
|
||||
import net.irext.server.service.businesslogic.DecodeLogic;
|
||||
import net.irext.server.service.cache.IDecodeSessionRepository;
|
||||
import net.irext.server.service.cache.IIRBinaryRepository;
|
||||
import net.irext.server.service.mapper.RemoteIndexMapper;
|
||||
import net.irext.server.service.model.ACParameters;
|
||||
import net.irext.server.service.model.DecodeSession;
|
||||
import net.irext.server.service.model.RemoteIndex;
|
||||
@@ -43,24 +42,39 @@ import java.text.SimpleDateFormat;
|
||||
@RestController
|
||||
@RequestMapping("/irext-server/decode")
|
||||
@Service("IRDecodeService")
|
||||
@SuppressWarnings("unused")
|
||||
public class IRDecodeService extends AbstractBaseService {
|
||||
|
||||
private static final String TAG = IRDecodeService.class.getSimpleName();
|
||||
|
||||
private RemoteIndexMapper remoteIndexMapper;
|
||||
|
||||
@Autowired
|
||||
private ServletContext context;
|
||||
|
||||
@Autowired
|
||||
private IndexingLogic indexingLogic;
|
||||
|
||||
@Autowired
|
||||
private IIRBinaryRepository irBinaryRepository;
|
||||
|
||||
@Autowired
|
||||
private IDecodeSessionRepository decodeSessionRepository;
|
||||
|
||||
@Autowired
|
||||
public void setContext(ServletContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setIndexingLogic(IndexingLogic indexingLogic) {
|
||||
this.indexingLogic = indexingLogic;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setIrBinaryRepository(IIRBinaryRepository irBinaryRepository) {
|
||||
this.irBinaryRepository = irBinaryRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setDecodeSessionRepository(IDecodeSessionRepository decodeSessionRepository) {
|
||||
this.decodeSessionRepository = decodeSessionRepository;
|
||||
}
|
||||
|
||||
@PostMapping("/open")
|
||||
public StringResponse irOpen(HttpServletRequest request, @RequestBody OpenRequest openRequest) {
|
||||
try {
|
||||
@@ -149,7 +163,7 @@ public class IRDecodeService extends AbstractBaseService {
|
||||
int changeWindDir = decodeRequest.getChangeWindDir();
|
||||
String sessionId = decodeRequest.getSessionId();
|
||||
|
||||
RemoteIndex cachedRemoteIndex = getCachedRemoteIndex(sessionId, remoteIndexId);;
|
||||
RemoteIndex cachedRemoteIndex = getCachedRemoteIndex(sessionId, remoteIndexId);
|
||||
DecodeResponse response = new DecodeResponse();
|
||||
|
||||
if (null == cachedRemoteIndex) {
|
||||
|
||||
@@ -2,7 +2,6 @@ package net.irext.server.service.restapi;
|
||||
|
||||
import net.irext.server.service.Constants;
|
||||
import net.irext.server.service.businesslogic.IndexingLogic;
|
||||
import net.irext.server.service.mapper.RemoteIndexMapper;
|
||||
import net.irext.server.service.model.*;
|
||||
import net.irext.server.service.request.*;
|
||||
import net.irext.server.service.response.*;
|
||||
@@ -32,17 +31,20 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/irext-server/indexing")
|
||||
@Service("IRIndexingService")
|
||||
@SuppressWarnings("unused")
|
||||
public class IRIndexingService extends AbstractBaseService {
|
||||
|
||||
private static final String TAG = IRIndexingService.class.getSimpleName();
|
||||
|
||||
@Autowired
|
||||
private ServletContext context;
|
||||
|
||||
@Autowired
|
||||
private IndexingLogic indexingLogic;
|
||||
|
||||
public IRIndexingService(RemoteIndexMapper remoteIndexMapper) {
|
||||
@Autowired
|
||||
public void setContext(ServletContext context) {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setIndexingLogic(IndexingLogic indexingLogic) {
|
||||
this.indexingLogic = indexingLogic;
|
||||
}
|
||||
|
||||
@PostMapping("/list_categories")
|
||||
@@ -54,9 +56,7 @@ public class IRIndexingService extends AbstractBaseService {
|
||||
String token = listCategoriesRequest.getToken();
|
||||
int from = listCategoriesRequest.getFrom();
|
||||
int count = listCategoriesRequest.getCount();
|
||||
int lang = Constants.LANG_ZH_CN;
|
||||
|
||||
lang = getLanguage(userLang);
|
||||
int lang = getLanguage(userLang);
|
||||
|
||||
CategoriesResponse response = validateToken(id, token, CategoriesResponse.class);
|
||||
if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) {
|
||||
@@ -89,9 +89,7 @@ public class IRIndexingService extends AbstractBaseService {
|
||||
int categoryId = listBrandsRequest.getCategoryId();
|
||||
int from = listBrandsRequest.getFrom();
|
||||
int count = listBrandsRequest.getCount();
|
||||
int lang = Constants.LANG_ZH_CN;
|
||||
|
||||
lang = getLanguage(userLang);
|
||||
int lang = getLanguage(userLang);
|
||||
|
||||
BrandsResponse response = validateToken(id, token, BrandsResponse.class);
|
||||
if (response.getStatus().getCode() == Constants.ERROR_CODE_AUTH_FAILURE) {
|
||||
@@ -237,8 +235,6 @@ public class IRIndexingService extends AbstractBaseService {
|
||||
lang = Constants.LANG_EN;
|
||||
} else if (userLang.equals("zh-TW")) {
|
||||
lang = Constants.LANG_TW_CN;
|
||||
} else {
|
||||
lang = Constants.LANG_ZH_CN;
|
||||
}
|
||||
}
|
||||
return lang;
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.irext.server.service.request.AppSignInRequest;
|
||||
import net.irext.server.service.response.LoginResponse;
|
||||
import net.irext.server.service.response.Status;
|
||||
import net.irext.server.service.restapi.base.AbstractBaseService;
|
||||
import net.irext.server.service.utils.LoggerUtil;
|
||||
import net.irext.server.service.utils.MD5Util;
|
||||
import net.irext.server.service.utils.VeDate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -35,16 +34,25 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@RestController
|
||||
@RequestMapping("/irext-server/app")
|
||||
@Service("SignInService")
|
||||
@SuppressWarnings("unused")
|
||||
public class SignInService extends AbstractBaseService {
|
||||
|
||||
private static final String TAG = SignInService.class.getSimpleName();
|
||||
|
||||
@Autowired
|
||||
private UserLoginLogic loginLogic;
|
||||
|
||||
@Autowired
|
||||
private IUserAppRepository userAppRepository;
|
||||
|
||||
@Autowired
|
||||
public void setLoginLogic(UserLoginLogic loginLogic) {
|
||||
this.loginLogic = loginLogic;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setUserAppRepository(IUserAppRepository userAppRepository) {
|
||||
this.userAppRepository = userAppRepository;
|
||||
}
|
||||
|
||||
@PostMapping("/app_login")
|
||||
public LoginResponse signIn(HttpServletRequest request, @RequestBody AppSignInRequest appSignInRequest) {
|
||||
try {
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.irext.server.service.response.Status;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* Filename: AbstractBaseService.java
|
||||
@@ -20,6 +19,7 @@ import org.springframework.context.ApplicationContext;
|
||||
* Revision log:
|
||||
* 2017-04-27: created by strawmanbobi
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public abstract class AbstractBaseService implements TokenValidation {
|
||||
|
||||
protected static Log log = LogFactory.getLog(AbstractBaseService.class);
|
||||
@@ -59,9 +59,7 @@ public abstract class AbstractBaseService implements TokenValidation {
|
||||
|
||||
try {
|
||||
r = c.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
log.error("Error when new instance of class: " + c.getName(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
log.error("Error when new instance of class: " + c.getName(), e);
|
||||
}
|
||||
|
||||
@@ -84,9 +82,7 @@ public abstract class AbstractBaseService implements TokenValidation {
|
||||
Status status = new Status();
|
||||
try {
|
||||
r = c.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
log.error("Error when new instance of class: " + c.getName(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
log.error("Error when new instance of class: " + c.getName(), e);
|
||||
}
|
||||
status.setCode(Constants.ERROR_CODE_AUTH_FAILURE);
|
||||
@@ -98,7 +94,6 @@ public abstract class AbstractBaseService implements TokenValidation {
|
||||
|
||||
private Status validateUserToken(Integer userId, String token) {
|
||||
Status status = new Status();
|
||||
ApplicationContext applicationContext;
|
||||
|
||||
if (userAppRepository.find(userId).equals(token)) {
|
||||
status.setCode(Constants.ERROR_CODE_SUCCESS);
|
||||
|
||||
@@ -12,6 +12,7 @@ import java.io.*;
|
||||
* Revision log:
|
||||
* 2017-04-14: created by strawmanbobi
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class FileUtil {
|
||||
|
||||
public static boolean write(File file, byte[] binaries) {
|
||||
@@ -43,9 +44,13 @@ public class FileUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean createDirs(String path) {
|
||||
public static void createDirs(String path) throws FileNotFoundException {
|
||||
File file = new File(path);
|
||||
return file.exists() || file.mkdir();
|
||||
if (!file.exists()) {
|
||||
if (!file.mkdir()) {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] getByteArrayFromFile(String fileName) {
|
||||
@@ -68,7 +73,7 @@ public class FileUtil {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
int count;
|
||||
byte buffer[] = new byte[512];
|
||||
byte[] buffer = new byte[512];
|
||||
while ((count = fis.read(buffer)) > 0) {
|
||||
baos.write(buffer, 0, count);
|
||||
}
|
||||
@@ -84,7 +89,7 @@ public class FileUtil {
|
||||
}
|
||||
|
||||
private static void deleteAllFiles(File root) {
|
||||
File files[] = root.listFiles();
|
||||
File[] files = root.listFiles();
|
||||
if (files != null) {
|
||||
for (File f : files) {
|
||||
if (f.isDirectory()) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class LoggerUtil {
|
||||
private Logger logger;
|
||||
private static final int MODE = 0;
|
||||
|
||||
LoggerUtil() {
|
||||
private LoggerUtil() {
|
||||
this.logger = LogManager.getLogger(LoggerUtil.class.getSimpleName());
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,9 @@ import java.security.MessageDigest;
|
||||
*/
|
||||
public class MD5Util {
|
||||
|
||||
public static String byteArrayToHexString(byte b[]) {
|
||||
StringBuffer resultSb = new StringBuffer();
|
||||
for (int i = 0; i < b.length; i++)
|
||||
resultSb.append(byteToHexString(b[i]));
|
||||
public static String byteArrayToHexString(byte[] b) {
|
||||
StringBuilder resultSb = new StringBuilder();
|
||||
for (byte value : b) resultSb.append(byteToHexString(value));
|
||||
|
||||
return resultSb.toString();
|
||||
}
|
||||
@@ -34,7 +33,7 @@ public class MD5Util {
|
||||
public static String MD5Encode(String origin, String charsetname) {
|
||||
String resultString = null;
|
||||
try {
|
||||
resultString = new String(origin);
|
||||
resultString = origin;
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
if (charsetname == null || "".equals(charsetname))
|
||||
resultString = byteArrayToHexString(md.digest(resultString
|
||||
@@ -42,12 +41,12 @@ public class MD5Util {
|
||||
else
|
||||
resultString = byteArrayToHexString(md.digest(resultString
|
||||
.getBytes(charsetname)));
|
||||
} catch (Exception exception) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return resultString;
|
||||
}
|
||||
|
||||
private static final String hexDigits[] = {"0", "1", "2", "3", "4", "5",
|
||||
private static final String[] hexDigits = {"0", "1", "2", "3", "4", "5",
|
||||
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f"};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user