zengkid / SmartTomcat

The Tomcat plugin for Intellij IDEA
Apache License 2.0
125 stars 56 forks source link

Support allowLinkng and cache setting on tomcat 8+ #99

Closed terwer closed 1 year ago

terwer commented 2 years ago

Is your feature request related to a problem? Please describe. Sometimes,we will deploy a app path with symbol links,how ever, tomcat default load the real filesyatem,this path with throw file not found Exception.

Describe the solution you'd like tomcatdir/conf/Catalina/localhost/appname.xml is configurable to fix this as a best practice,See https://stackoverflow.com/a/43673455/4037224

But SmartTomcat now create appname.xml without this.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<Context docBase="mydocpath">
  <Resources>
 </Resources >
</Context>

What expected is

<Context docBase="mydocpath">
  <Resources allowLinking="true" cacheMaxSize="100000" cachingAllowed="true">
 </Resources >
</Context>

Go through the source ,I found a solution

Change com.poratu.idea.plugins.tomcat.conf.TomcatCommandLineState.java createResourcesElementIfNecessary() mthod should add this

private Element createResourcesElementIfNecessary(Document doc, Element contextRoot) {
    Element resources = (Element) contextRoot.getElementsByTagName("Resources").item(0);
    if (resources == null) {
        resources = doc.createElement("Resources");
        // fix cache and linking
        resources.setAttribute("allowLinking", "true");
        resources.setAttribute("cachingAllowed", "true");
        resources.setAttribute("cacheMaxSize", "100000");
        contextRoot.appendChild(resources);
    }
    return resources;
}

Describe alternatives you've considered The above options can be configuable.This is just a example to show how to suit this suitation.

yuezk commented 1 year ago

Thanks for the report and look into this.

According to the documentation (https://tomcat.apache.org/tomcat-9.0-doc/config/resources.html ), cachingAllowed is true by default. And the default value for cacheMaxSize is 10240 (10 M). Is the default configuration good for you?

allowLinking is false by default, but it's not commonly used, for your case, I'm going to add a registry so that you can enable it on your needs.

Any questions?

terwer commented 1 year ago

Thanks , my company project is so large, in my case, 10240 is not enough, so also add a registry for cacheMaxSize will be better.

terwer commented 1 year ago

I tried thhe latest updated version 4.3.8. it works great! Thanks very much!

yuezk commented 1 year ago

How to configure cacheMaxSize and allowLinking for SmartTomcat?

Search the Registry action then:

image