[Tomcat源码分析] Eclipse中搭建Apache Tomcat源码调试环境
网上很多文章都推荐使用ant下载编译,但本地实践中屡屡失败,无法下载。
后来参考 https://blog.csdn.net/xiongyouqiang/article/details/78941077 总算把调试环境搭建完成。
以下文章几乎完全copy上述网址,但稍作延展。
下载源码
官网直接下载源码
源码导入到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
上一篇: url编码本质
下一篇: Fiddler抓取内容自动保存本地