Introduction:
In the preceding example, these xml files are finally copied to the Application Deployment directory of liferay tomcat webapps. At that time, I mentioned that this step is very complicated and I need to write another article to explain it, so here we will detail the updateWebXml () method:
Debugging process:
(1) First, it will read to the $ CATALINA_HOME/temp/timestamp directory, that is, the web after the war distribution package is expanded. xml file. The content of the original file is read in the string content.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542112258-0.png "title =" 1.png"/>
(2) It reads the <display-name> element in web. xml in line 1768-1775. If yes, it is removed from the content.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542115547-1.png "title =" 2.png"/>
(3) it will get the web in row 1778-1785. xml version, because the web. there are several versions of xml schema corresponding to XML, including 2.3, 2.4, and 2.5. The corresponding version information is different. The structure and method of adding content in the xml schema are also different, therefore, this information is also very important. This information will be obtained from the version attribute of the root element. We get our web. the xml version is 2.4
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/154211B47-2.png "title =" 3.png"/>
(4) because we use the updateWebXml method, it must change the xml content. Therefore, the xml content must be collected from multiple channels. First, it uses getExtraContent () in row 1789th () we get the additional content we want to change the original xml, which will be collected in many ways and we will use it as the original content we want to process.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542116128-3.png "title =" 4.png"/>
This is very complicated. I am going to put it in "answers to the best questions.
(5) After (4) the additional content is generated, we start to process the content. We have created a newContent string to store the new string after processing. Its initial value is in the latest version of the web from the war package. in xml, add additional content in the </web-app> section (4) returned extraContent. In other words, it is added to the end of web. xml.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542112244-4.png "title =" 5.png"/>
(6) then, on the basis of (5), replace the old package name with the new package name in line 1798-1802:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542112N1-5.png "title =" 6.png"/>
(7) Next in line 1806-1808 it will go to create and update liferay-web.xml, this is only for web. the xml version is more suitable than 2.3. Its main function is our web. xml split content stored in newContent), where all the filters (except Invoker Filter) are moved to the liferay-web.xml, then the remaining part is added with the Invoker Filter and then reversed and saved in newContentI will explain the details in "answers to the best questions.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542116129-6.png "title =" 7.png"/>
(8) At last, update the newContent returned by line 1812-1814 to the web. xml file.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542115443-7.png "title =" 8.png"/>
Q & A 1:
(1) when building new web. xml content, the original material comes from the getExtraContent () method call. What additional content does this Method Add after it is called?For this reason, debug the getExtraContent () method.
First, we can see that in row 122nd, it will call the getExtraContent () method of the super class to obtain additional content. The content to be changed is stored in the StringBundler sb variable.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542111H1-8.png "title =" 9.png"/>
Not specific. The content returned from the getExtraContent method of the parent class is as follows:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542112128-9.png "title =" 10.png"/>
In general, the following content is added:
(1) added a listener (SerializableSessionAttributeListener ),
(2) added a Servlet (SetPortletClassLoaderServlet), and the load-on-startup of this Servlet is 0.
(3) added several tag library definitions, if higher than the web. if the xml version is higher than 2.3, it is placed under the <jsp-config> element. if the version is lower than 2.3, it is directly placed under the root element.
These markup libraries include: aui. tld, liferay-portlet.tld, liferay-portlet-ext.tld, liferay-security.tld, liferay-theme.tld, liferay-ui.tld, liferay-util.tld
Looking back at what we studied last time, these corresponding tld files will be copied from portalImpl. jar to the corresponding/WEB-INF/tld file, so it's okay to use the tags in these tag libraries.
(4) adds a filter (PortalClassLoaderFilter), and uses the CompoundSessionIdFilter. Its url-pattern is any request /*
Then lines 127th-135 are added to the StringBundler for the webSphere server. Because our server uses tomcat, this code is not considered.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/154211FL-10.png "title =" 11.png"/>
Then the 142nd line calls the updatePortletXML method. The input parameters are also the portlet. xml file extracted from the portlet war package during deployment.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/154211G27-11.png "title =" 12.png"/>
From the above we can see that it is actually reading the content of the portlet. xml, and then converting the JSPPortlet into the MVCPortlet. Because our portlet. xml does not exist, it is returned as it is.
Then, in line 3, sb. append (getServletContent (portletXML, webXML) is called to append content related to Servlet configuration to StringBundler. Let's take a look at the implementation of getServletContent.Core):
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542114431-12.png "title =" 13.png"/>
It can be found that it first reads the portlet. xml file, and then iterates each of the <portlet> to create a servlet definition.Specifically, a servlet is defined as PortletServlet. this servlet has an initial parameter, portlet-class, which is the class name of our current Portlet and load-on-startup is 1, and its url-mapping is for any request.Then the web. xml file is iterated over the <servlet> file, because the file does not exist. <Servlet> definition, so skip it directly. Therefore, there is only one piece of information returned from getServletContent (portletXML, webXML) to getExtraContent ().PortletServlet.
Then from line 1 it will process the jsf file, because we don't have the faces-config.xml, so no processing is done.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542112264-13.png "title =" 14.png"/>
Then, the 148th line will judge that if it is sun's jsfPortlet, a special configuration will be added to StringBundler, because we are not using SunJSFPortlet, so SKIP:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542111250-14.png "title =" 15.png"/>
Add a PortletContextListener listener to StringBundler in line 162-166:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/15421154T-15.png "title =" 16.png"/>
Then, the 170th rows will add a set of ignore filters to StringBundler. They are used to filter out some files with the specified extension when the Portal class is loaded. The definitions of these filters are obtained through the getIgnoreFiltersContent (srcFile) method:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/154211B04-16.png "title =" 17.png"/>
In fact, through debugging, they all come from portal-impl.jar files:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/15421153a-17.png "title =" 18.png"/>
Then, the 174th rows will add a set of filters used to accelerate request processing to the StringBundler. They are used to accelerate processing when the Portal class is loaded, such as cache, such as compression. The definitions of these filters are obtained through getSpeedFiltersContent (srcFile:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542112K6-18.png "title =" 19.png"/>
In fact, through debugging, they are also from the portal-impl.jar file:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542111F6-19.png "title =" Your png"/>
Finally, add a set of ServletContextInclude filters to StringBundler in row 178th:
650) this. width = 650; "src =" http://img1.51cto.com/attachment/201309/134627370.png "title =" 21.png"/>
After this method is called, the following content is added:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542113920-21.png "title =" 22.png"/>
Therefore, the content returned by StringBundler is the sum of the preceding content.
Question 2:
What content has been updated to the liferay-web.xml in the updateLiferayWebXml method and what is the remaining content returned? For this reason, we also conduct debugging.
We found that, first, it uses WebXMLBuilder to format the total web. xml content file that is included by getExtraContent, including the element indent and the arrangement order of each element.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542115212-22.png "title =" 23.png"/>
Then, it obtains the entire filter definition string from the first <filter> to the last <filter-mapping> in this section, store the upper and lower bounds of coordinates in the variables x and y respectively, and then store the filter content in the filterContent string variable:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542111004-23.png "title =" 24.png"/>
Next, it will first create a <web-app> element, and then insert all the definitions of the filter to this <web-app> element, use WebXMLBuilder to reorganize the format, and finally write its content into the/WEB-INF/liferay-web.xml that deploy the cache directory.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/154211A29-24.png "title =" 25.png"/>
We compare the file timestamp of the file system, and the liferay-web.xml under the deployment cache directory is just updated.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542116044-25.png "title =" 26.png"/>
Next is to deal with the parts outside of the liferay-web.xml:
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542111148-26.png "title =" 27.png"/>
It can be seen that it first removes the filter section in web. xml, and then fills in the definition section of the InvokerFilter in the middle, which is obtained by calling the API getInvokerFilterContent () method. This forms the final web. xml,In fact, it is also very easy to understand, because to avoid repeated definitions, so the web. xml only retains the InvokerFilter, and other filters are placed in the liferay-web.xml.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1542116460-27.png "title =" 28.png"/>
The debugging information on the right shows that the current <filter> part only contains the Invoker Filter and no other part.
From the file system, we can also see that the web. xml is indeed generated just now.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/15421134T-28.png "title =" 29.png"/>
Summary:
The above process is too complicated. We have too many discoveries and too much knowledge to summarize.
(1) updateWebXml not only includes updating web. xml, but also includes creating an update liferay-web.xml
(2) update the web. xml, it always has an original xml string for us to process, this original web. the xml string is a web string obtained from our war package. add some additional content to the xml content.
(3) The additional content is pieced together by the content obtained from multiple channels and encapsulated in the getExtraContent () method. Specifically, it contains the following content:
A. added a listener (SerializableSessionAttributeListener ),
B. added a Servlet (SetPortletClassLoaderServlet), and the Servlet's load-on-startup is 0.
C. Added several tag library definitions. if the version is higher than the web. xml Version 2.3, It will be placed under the <jsp-config> element. if the version is lower than 2.3, It will be placed directly under the root element.
These markup libraries include: aui. tld, liferay-portlet.tld, liferay-portlet-ext.tld, liferay-security.tld, liferay-theme.tld, liferay-ui.tld, liferay-util.tld
D. added a filter (PortalClassLoaderFilter), and it will use the CompoundSessionIdFilter. Its url-pattern is any request /*
E. If the server type is websphere, add a special initial context related to websphere. <context-param>
F. Add a PortletServlet definition.
G. For JSFPortlet, a special listener is added.
H. Add a PortletContextListener listener Definition
I. add several Ignore Filter filters from the portal-impl.jar.
J. add several Speed Filter filters from the portal-impl.jar.
K. Add the ServletContextInclude filter.
(4) append the (3) additional content to the original web. after the xml, We will update the new web. xml content is post-processed. The main point of processing is this web. the xml content is split into two xml files, one being web. xml, A liferay-web.xml file. The root elements of these two files are all <web-app>, the difference is that the liferay-web.xml file contains all the filters, while the web. in xml, all the general filters are removed from the remaining elements, but the Invoker Filter can be used as a "divide and conquer" function.
(5) Finally, all these resource files will be copied to the deployment directory of the corresponding application under tomcat/webapps.
This article from "parallel line cohesion" blog, please be sure to keep this source http://supercharles888.blog.51cto.com/609344/1286976