tomcat原始碼 -- servlet呼叫過程
servlet呼叫
public class Http11Processor extends AbstractProcessor {
@Override
public SocketState service(SocketWrapperBase<?> socketWrapper)
throws IOException {
。。。。。
// Process the request in the adapter
if (!getErrorState().isError()) {
try {
rp.setStage(org.apache.coyote.Constants.STAGE_SERVICE);
getAdapter().service(request, response);
。。。。。
順著 getAdapter().service 一直可以找到
inal class StandardWrapperValve
extends ValveBase {
@Override
public final void invoke(Request request, Response response)
throws IOException, ServletException {
。。。。。
try {
// 這裡是建立Servlet的程式碼
if (!unavailable) {
servlet = wrapper.allocate();
}
}
。。。。。
try {
if ((servlet != null) && (filterChain != null)) {
// Swallow output if needed
if (context.getSwallowOutput()) {
try {
SystemLogHandler.startCapture();
if (request.isAsyncDispatching()) {
request.getAsyncContextInternal().doInternalDispatch();
} else {
filterChain.doFilter(request.getRequest(),
response.getResponse());
}
} finally {
String log = SystemLogHandler.stopCapture();
if (log != null && log.length() > 0) {
context.getLogger().info(log);
}
}
} else {
// 這裡呼叫servlet的doDispatch()
if (request.isAsyncDispatching()) {
request.getAsyncContextInternal().doInternalDispatch();
} else {
filterChain.doFilter
(request.getRequest(), response.getResponse());
}
}
}
}
。。。。。
順著繼續debug
public final class ApplicationFilterChain implements FilterChain {
private void internalDoFilter(ServletRequest request,
ServletResponse response)
throws IOException, ServletException {
// Call the next filter if there is one
if (pos < n) {
ApplicationFilterConfig filterConfig = filters[pos++];
try {
Filter filter = filterConfig.getFilter();
if (request.isAsyncSupported() && "false".equalsIgnoreCase(
filterConfig.getFilterDef().getAsyncSupported())) {
request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR, Boolean.FALSE);
}
if( Globals.IS_SECURITY_ENABLED ) {
final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
Object[] args = new Object[]{req, res, this};
SecurityUtil.doAsPrivilege ("doFilter", filter, classType, args, principal);
} else {
filter.doFilter(request, response, this);
}
} catch (IOException | ServletException | RuntimeException e) {
throw e;
} catch (Throwable e) {
e = ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(e);
throw new ServletException(sm.getString("filterChain.filter"), e);
}
return;
}
// We fell off the end of the chain -- call the servlet instance
try {
if (ApplicationDispatcher.WRAP_SAME_OBJECT) {
lastServicedRequest.set(request);
lastServicedResponse.set(response);
}
if (request.isAsyncSupported() && !servletSupportsAsync) {
request.setAttribute(Globals.ASYNC_SUPPORTED_ATTR,
Boolean.FALSE);
}
// Use potentially wrapped request from this point
if ((request instanceof HttpServletRequest) &&
(response instanceof HttpServletResponse) &&
Globals.IS_SECURITY_ENABLED ) {
final ServletRequest req = request;
final ServletResponse res = response;
Principal principal =
((HttpServletRequest) req).getUserPrincipal();
Object[] args = new Object[]{req, res};
SecurityUtil.doAsPrivilege("service",
servlet,
classTypeUsedInService,
args,
principal);
} else {
servlet.service(request, response);
}
} catch (IOException | ServletException | RuntimeException e) {
throw e;
} catch (Throwable e) {
e = ExceptionUtils.unwrapInvocationTargetException(e);
ExceptionUtils.handleThrowable(e);
throw new ServletException(sm.getString("filterChain.servlet"), e);
} finally {
if (ApplicationDispatcher.WRAP_SAME_OBJECT) {
lastServicedRequest.set(null);
lastServicedResponse.set(null);
}
}
}
相關文章
- Runtime原始碼 方法呼叫的過程原始碼
- Dubbo服務呼叫過程原始碼解析④原始碼
- Dubbo原始碼解析之服務呼叫過程原始碼
- Spring原始碼分析之`BeanFactoryPostProcessor`呼叫過程Spring原始碼Bean
- Servlet過濾器原始碼分析Servlet過濾器原始碼
- java儲存過程呼叫servlet的授權問題Java儲存過程Servlet
- cesium原始碼編譯除錯及呼叫全過程原始碼編譯除錯
- Tomcat聯結器執行過程(原始碼閱讀)Tomcat原始碼
- tomcat原始碼分析(第二篇 tomcat啟動過程詳解)Tomcat原始碼
- Dubbo-go 原始碼筆記(二)客戶端呼叫過程Go原始碼筆記客戶端
- JDBC 呼叫儲存過程程式碼示例JDBC儲存過程
- mybatis-plus原始碼解析(三)----Mapper介面動態代理呼叫過程MyBatis原始碼APP
- 原始碼包安裝過程原始碼
- MySQL • 原始碼分析 • SHUTDOWN過程MySql原始碼
- 【Tomcat 原始碼系列】原始碼構建 TomcatTomcat原始碼
- 呼叫儲存過程儲存過程
- 【原始碼】Redis Server啟動過程原始碼RedisServer
- 【原始碼】Redis命令處理過程原始碼Redis
- Winform呼叫儲存過程ORM儲存過程
- perl呼叫儲存過程儲存過程
- jdbc呼叫儲存過程JDBC儲存過程
- 原始碼|HDFS之NameNode:啟動過程原始碼
- Netty NioEventLoop 建立過程原始碼分析NettyOOP原始碼
- 從Chrome原始碼看DNS解析過程Chrome原始碼DNS
- 深入剖析Vue原始碼 - 完整渲染過程Vue原始碼
- Spring啟動過程——原始碼分析Spring原始碼
- spark原始碼之任務提交過程Spark原始碼
- 走近原始碼:Redis的啟動過程原始碼Redis
- 原始碼分析OKHttp的執行過程原始碼HTTP
- 以太坊啟動過程原始碼解析原始碼
- 原始碼|HDFS之DataNode:啟動過程原始碼
- php5.6原始碼安裝過程PHP原始碼
- knockout原始碼分析之執行過程原始碼
- android view draw原始碼過程分析AndroidView原始碼
- Lucene原始碼解析--搜尋過程<二>原始碼
- Tomcat&Servlet學習TomcatServlet
- 【Tomcat 原始碼系列】認識 TomcatTomcat原始碼
- [Tomcat原始碼系列] Tomcat ConnectorTomcat原始碼