Commit f35d1051 authored by yanzg's avatar yanzg

添加对Android的支持

parent 21f1112c
package com.yanzuoguang.cloud.aop;
import com.yanzuoguang.cloud.CloudContans;
import com.yanzuoguang.cloud.helper.CookiesHelper;
import com.yanzuoguang.cloud.service.TokenService;
import com.yanzuoguang.cloud.service.TokenServiceCall;
import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper;
......@@ -40,7 +39,7 @@ public class WebAspect extends BaseRequestAspect {
private static final Logger logger = LoggerFactory.getLogger(BaseRequestAspect.class);
@Autowired
private TokenService tokenService;
private TokenServiceCall tokenServiceCall;
/**
* exec aop point aspect
......@@ -64,7 +63,7 @@ public class WebAspect extends BaseRequestAspect {
String name = joinPoint.getSignature().getName();
try {
logger.info("[ {} ] request params is {}", name, joinPoint.getArgs());
tokenService.tokenInit();
tokenServiceCall.tokenInit();
Object result = executeMethod(joinPoint, name);
if (result instanceof ResponseResult) {
......@@ -87,7 +86,7 @@ public class WebAspect extends BaseRequestAspect {
throw e;
}
} finally {
tokenService.tokenFinish();
tokenServiceCall.tokenFinish();
Log.threadCommit();
saveInterLogs(joinPoint, responseResult);
}
......
package com.yanzuoguang.cloud.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import com.yanzuoguang.token.TokenLoad;
/**
* Token服务
* Token服务实现接口
*
* @author 颜佐光
*/
@Component
public class TokenService {
public interface TokenService extends TokenLoad {
@Autowired
private ApplicationContext context;
public void tokenInit() {
}
public void tokenFinish() {
}
/**
* 初始化token
*/
void tokenInit();
/**
* 结束token
*/
void tokenFinish();
}
package com.yanzuoguang.cloud.service;
import com.yanzuoguang.token.TokenData;
import com.yanzuoguang.token.TokenLoad;
import com.yanzuoguang.util.log.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
/**
* Token服务
*
* @author 颜佐光
*/
@Component
public class TokenServiceCall implements TokenLoad {
@Autowired
private ApplicationContext context;
private TokenService tokenService = null;
private boolean initFlag = false;
private void init() {
try {
tokenService = context.getBean(TokenService.class);
} catch (Exception ex) {
Log.error(TokenServiceCall.class, "获取登录服务失败:" + ex.getMessage(), ex);
} finally {
initFlag = true;
}
}
/**
* 请求时初始化token
*/
public void tokenInit() {
init();
if (tokenService == null) {
return;
}
tokenService.tokenInit();
}
/**
* 请求时结束token
*/
public void tokenFinish() {
init();
if (tokenService == null) {
return;
}
tokenService.tokenFinish();
}
/**
* 根据token标记加载
*
* @param token  加载标记
* @return
*/
@Override
public TokenData load(String token) {
init();
if (tokenService == null) {
return null;
}
return tokenService.load(token);
}
}
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