網上很多文章都推薦使用Ant下載編譯,但本地實踐中屢屢失敗,無法下載。 後來參考 https://blog.csdn.net/xiongyouqiang/article/details/78941077 總算把調試環境搭建完成。 以下文章幾乎完全copy上述網址,但稍作延展。 下載源碼 官網直接下載 ...
網上很多文章都推薦使用Ant下載編譯,但本地實踐中屢屢失敗,無法下載。
後來參考 https://blog.csdn.net/xiongyouqiang/article/details/78941077 總算把調試環境搭建完成。
以下文章幾乎完全copy上述網址,但稍作延展。
下載源碼
官網直接下載源碼
http://tomcat.apache.org/download-70.cgi
源碼導入到Eclipse中
第1步:Eclipse中新建一個Java Project,例如名稱可以是Tomcat-Src
第2步:在工程上點擊右鍵=>Import=>General=>File System,點擊Next按鈕。
第3步:點擊Browser按鈕,找到tomcat源碼解壓路徑,勾選java、test、conf和webapps目錄(註意不需要勾選examples目錄),點擊Finish按鈕。
第4步:在java和test目錄上點擊右鍵=>Build Path=>Use As Source Folder將這兩個目錄設為源碼目錄。同時可以刪除工程中原有的src目錄了。
第5步:解決導入後工程中出現的編譯錯誤,一般都是由於缺少某些jar導致
主要導入以下幾個jar飽
ant.jar
ecj-4.4.2.jar
jaxrpc.jar
wsdl4j-1.5.2.jar
easymock-3.5.1.jar
在工程中新建一個lib目錄,將這些jar包放到該目錄下,同時添加到build path中。
apache tomcat採用junit作為單元測試工具,我們需要為工程添加Junit支持,在工程上點擊右鍵=>Properties=>Java build path。
點擊Add Library按鈕,選擇Junit4即可。
此時test包中的TestCookieFilter類會報CookieFilter編譯異常,這是因為缺少CookieFilter這個類導致,經過一番查找總算找到了CookieFilter源碼如下所示:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package util; import java.util.Locale; import java.util.StringTokenizer; /** * Processes a cookie header and attempts to obfuscate any cookie values that * represent session IDs from other web applications. Since session cookie names * are configurable, as are session ID lengths, this filter is not expected to * be 100% effective. * * It is required that the examples web application is removed in security * conscious environments as documented in the Security How-To. This filter is * intended to reduce the impact of failing to follow that advice. A failure by * this filter to obfuscate a session ID or similar value is not a security * vulnerability. In such instances the vulnerability is the failure to remove * the examples web application. */ public class CookieFilter { private static final String OBFUSCATED = "[obfuscated]"; private CookieFilter() { // Hide default constructor } public static String filter(String cookieHeader, String sessionId) { StringBuilder sb = new StringBuilder(cookieHeader.length()); // Cookie name value pairs are ';' separated. // Session IDs don't use ; in the value so don't worry about quoted // values that contain ; StringTokenizer st = new StringTokenizer(cookieHeader, ";"); boolean first = true; while (st.hasMoreTokens()) { if (first) { first = false; } else { sb.append(';'); } sb.append(filterNameValuePair(st.nextToken(), sessionId)); } return sb.toString(); } private static String filterNameValuePair(String input, String sessionId) { int i = input.indexOf('='); if (i == -1) { return input; } String name = input.substring(0, i); String value = input.substring(i + 1, input.length()); return name + "=" + filter(name, value, sessionId); } public static String filter(String cookieName, String cookieValue, String sessionId) { if (cookieName.toLowerCase(Locale.ENGLISH).contains("jsessionid") && (sessionId == null || !cookieValue.contains(sessionId))) { cookieValue = OBFUSCATED; } return cookieValue; } }
此時仍有部分error,但不影響調試
設置Debug Configuration,設定程式入口,開始調試!
————————————————
原文鏈接:https://blog.csdn.net/xiongyouqiang/article/details/78941077