diff --git a/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java b/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java index d2092a2cc8866b64019b990ea4b5acf10a532322..70529a64ac66a4925479b58a013f67e558fb8d7e 100644 --- a/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java +++ b/src/main/java/neatlogic/framework/asynchronization/threadlocal/RequestContext.java @@ -15,6 +15,7 @@ along with this program. If not, see .*/ package neatlogic.framework.asynchronization.threadlocal; +import neatlogic.framework.common.util.IpUtil; import neatlogic.framework.dto.healthcheck.SqlAuditVo; import neatlogic.framework.restful.constvalue.RejectSource; import org.apache.commons.lang3.StringUtils; @@ -126,7 +127,7 @@ public class RequestContext implements Serializable { } HttpServletRequest request = _requestContext.getRequest(); if (request != null) { - String remoteAddr = request.getRemoteAddr(); + String remoteAddr = IpUtil.getIpAddr(request); if (StringUtils.isNotBlank(remoteAddr)) { tempUrl += "(" + remoteAddr + ")"; } diff --git a/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java b/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java index 76b69288b17a706c3fa65997aa0f7c7c4d5436ce..304880d9d47798aa290902dcb3d40ee22bebf4f9 100644 --- a/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java +++ b/src/main/java/neatlogic/framework/common/constvalue/InputFrom.java @@ -24,6 +24,8 @@ import java.util.List; public enum InputFrom implements IEnum { PAGE("page", "nfcc.inputfrom.page"), + PC("pc", "nfcc.inputfrom.pc"), + MOBILE("mobile", "nfcc.inputfrom.mobile"), IMPORT("import", "nfcc.inputfrom.excel"), RESTFUL("restful", "nfcc.inputfrom.api"), ITSM("itsm", "nfcc.inputfrom.itsm"), diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java index 7e80665429acbd3eb83fa544395dcdd49db9b5e2..7fc34b9011a5b14c22015474627d75e9b4c6eac0 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/AnonymousApiDispatcher.java @@ -19,10 +19,12 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONReader; import com.alibaba.fastjson.serializer.SerializerFeature; +import neatlogic.framework.asynchronization.threadlocal.InputFromContext; import neatlogic.framework.asynchronization.threadlocal.RequestContext; import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.common.config.Config; +import neatlogic.framework.common.constvalue.InputFrom; import neatlogic.framework.common.constvalue.ResponseCode; import neatlogic.framework.common.constvalue.systemuser.SystemUser; import neatlogic.framework.common.util.RC4Util; @@ -80,6 +82,15 @@ public class AnonymousApiDispatcher { private ApiAccessCountService apiAccessCountService; private void doIt(HttpServletRequest request, HttpServletResponse response, String token, boolean tokenHasEncrypted, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { + InputFrom inputFrom = null; + String source = request.getHeader("source"); + if (StringUtils.isNotBlank(source)) { + inputFrom = InputFrom.get(source); + } + if (inputFrom == null) { + inputFrom = InputFrom.UNKNOWN; + } + InputFromContext.init(inputFrom); ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); RequestContext.init(request, token, response); ApiVo dbApiVo = apiMapper.getApiByToken(token); diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java index 1019733c284427aefbedeb9971f6f60fc79ba292..16bf750c0459f815d8096036b12b2676b6ca116e 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/ApiDispatcher.java @@ -99,7 +99,15 @@ public class ApiDispatcher { private void doIt(HttpServletRequest request, HttpServletResponse response, String token, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { - InputFromContext.init(InputFrom.PAGE); + InputFrom inputFrom = null; + String source = request.getHeader("source"); + if (StringUtils.isNotBlank(source)) { + inputFrom = InputFrom.get(source); + } + if (inputFrom == null) { + inputFrom = InputFrom.UNKNOWN; + } + InputFromContext.init(inputFrom); RequestContext.init(request, token, response); ApiVo interfaceVo = PrivateApiComponentFactory.getApiByToken(token); if (paramObj == null) { diff --git a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java index 2a56b8be616ee82f4cd97cc5426e387d78502ff5..aaba524026d03febf562a1cfca2262067e9739bc 100644 --- a/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java +++ b/src/main/java/neatlogic/module/framework/restful/dispatch/handler/PublicApiDispatcher.java @@ -91,7 +91,15 @@ public class PublicApiDispatcher { private void doIt(HttpServletRequest request, HttpServletResponse response, String token, ApiType apiType, JSONObject paramObj, JSONObject returnObj, String action) throws Exception { - InputFromContext.init(InputFrom.RESTFUL); + InputFrom inputFrom = null; + String source = request.getHeader("source"); + if (StringUtils.isNotBlank(source)) { + inputFrom = InputFrom.get(source); + } + if (inputFrom == null) { + inputFrom = InputFrom.UNKNOWN; + } + InputFromContext.init(inputFrom); RequestContext.init(request, token, response); //初始化时区 Cookie[] cookies = request.getCookies();