|
@@ -1,5 +1,8 @@
|
|
|
package com.shkpr.service.proxycenter.components;
|
|
|
|
|
|
+import com.global.base.log.LogLevelFlag;
|
|
|
+import com.global.base.log.LogPrintMgr;
|
|
|
+import com.shkpr.service.proxycenter.commtools.CommTool;
|
|
|
import com.shkpr.service.proxycenter.commtools.HttpTool;
|
|
|
import com.shkpr.service.proxycenter.constants.ApiURI;
|
|
|
import com.shkpr.service.proxycenter.constants.ProxyPassDefine;
|
|
@@ -26,6 +29,8 @@ import java.security.cert.CertificateException;
|
|
|
import java.security.cert.X509Certificate;
|
|
|
|
|
|
public abstract class AbstractProxyServlet extends ProxyServlet {
|
|
|
+ private String mStrClassName = "AbstractProxyServlet";
|
|
|
+ private String mStrBizType = "";
|
|
|
private String proxyAddress = "https://127.0.0.1:9000/";
|
|
|
private String proxyId = "";
|
|
|
private String proxyTK = "";
|
|
@@ -74,17 +79,37 @@ public abstract class AbstractProxyServlet extends ProxyServlet {
|
|
|
|
|
|
@Override
|
|
|
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException {
|
|
|
+ final String strUserAgent = servletRequest.getHeader(ApiURI.HEADER_USER_AGENT);
|
|
|
+ final String strClientType = servletRequest.getHeader(ApiURI.HEADER_CLIENT_TYPE);
|
|
|
+ final String strPlatform = CommTool.getPlatformByAgent(strClientType, strUserAgent);
|
|
|
+ final String strIpAddress = HttpTool.getIpAddress(servletRequest);
|
|
|
+ final String destUri = servletRequest.getRequestURI();
|
|
|
ResponseCode headerCheck = checkHeader(servletRequest, servletResponse);
|
|
|
if (headerCheck != ResponseCode.RESULT_NORMAL) {
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_WARN, proxyId, mStrClassName, "Outer"
|
|
|
+ ,String.format("from:{%s-->%s} uri:{%s} failed:{code=%s,reason=%s}"
|
|
|
+ ,strIpAddress
|
|
|
+ ,strPlatform
|
|
|
+ ,destUri
|
|
|
+ ,headerCheck.toStrCode()
|
|
|
+ ,headerCheck.toStrMsg()));
|
|
|
HttpTool.handlerHttpErrorStatus(servletResponse, headerCheck);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- final String destUri = servletRequest.getRequestURI();
|
|
|
+
|
|
|
servletRequest.setAttribute(ATTR_TARGET_URI, null);
|
|
|
|
|
|
if (!destUri.startsWith(proxyUri)){
|
|
|
- HttpTool.handlerHttpErrorStatus(servletResponse, ResponseCode.STATUS_NOT_FOUND_URI);
|
|
|
+ headerCheck = ResponseCode.STATUS_NOT_FOUND_URI;
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_WARN, proxyId, mStrClassName, "Inner"
|
|
|
+ ,String.format("from:{%s-->%s} uri:{%s} failed:{code=%s,reason=%s}"
|
|
|
+ ,strIpAddress
|
|
|
+ ,strPlatform
|
|
|
+ ,destUri
|
|
|
+ ,headerCheck.toStrCode()
|
|
|
+ ,headerCheck.toStrMsg()));
|
|
|
+ HttpTool.handlerHttpErrorStatus(servletResponse, headerCheck);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -109,7 +134,7 @@ public abstract class AbstractProxyServlet extends ProxyServlet {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
servletRequest.setAttribute(ATTR_TARGET_HOST, null);
|
|
|
- super.targetHost = URIUtils.extractHost(uri);
|
|
|
+ super.targetHost = URIUtils.extractHost(uri);//只提取IP(域名)和端口,多余的路由无效
|
|
|
super.service(servletRequest, servletResponse);
|
|
|
}
|
|
|
|