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