Bilal-S / iis2tomcat

AJP Connector between Internet Information Services (IIS) and Apache Tomcat
http://www.boncode.net/boncode-connector
49 stars 32 forks source link

Static files in subfolders have too many redirects #79

Closed johnbyers closed 5 years ago

johnbyers commented 5 years ago

I am using the Boncode connector and it works great with servlets. It also works nicely with static files (like JavaScripts, CSS) as long as they are placed in a Tomcat app's first directory. However, when I try putting a static file inside a folder in a Tomcat app, I get 302 ERR_TOO_MANY_REDIRECTS. I am wondering if I am missing something in my IIS config, as Boncode and Tomcat both work. What would cause this?

Example trying to reach static .js file

My Config

This is the handler mapping for the Tomcat app in IIS: <add name="BonCode MyApp" path="MyApp/*" verb="*" type="BonCode..." resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode" />

I do have a JavaScript mapping as well, but it is further down in the list of precedence, and figured it wouldn't ever be reached. <add name="Javascript Files" path="*.js" verb="*" type="" modules="StaticFileModule" scriptProcessor="" resourceType="File" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="..." />

I noticed that if I add a second handler mapping for path="MyApp/*/*" then it does work as expected. However, that configuration doesn't make sense, as my servlets are in the WEB-INF folder and it can reach them without this additional handler mapping.

Finally, I noticed this person in the old forum had the same issue, but I haven't seen anything different between my code and the guide.

Bilal-S commented 5 years ago

John, I would make sure that the static handler mapping for your javascript files *.js is before BonCode in the precedents list. You can arrange precedent in the IIS UI.

Also you can verify which system is issuing redirects. If it is Tomcat you should check it and make changes there. You can do so by adding this directive temporarily to BonCodeAJP13.settings file <EnableHTTPStatusCodes>False</EnableHTTPStatusCodes>

johnbyers commented 5 years ago

Wouldn't having the *.js handler before Boncode mean IIS tries to serve JavaScript files before it ever gets to Tomcat?

Anyway, it is IIS issuing the redirects. I think I must have some problem with the handler mapping. Looks like others have had the same issue on Stack Overflow, and have fixed it with something like this:

<!-- Configuration for the "MyApp" subdirectory. -->
<location path="MyApp">
  <system.web>
    <httpHandlers>
      <add verb="*" path="MyApp" type="Boncode...."/>
    </httpHandlers>
  </system.web>
</location>

However I am unable to make this work correctly. I'm thinking it is not a Boncode issue, but more of an IIS configuration issue. Thanks for your time.

Bilal-S commented 5 years ago

Ok. No problem. I would normally suggest that if something is a static asset it is served by IIS directly. It is more efficient in doing so. This reduces processing and allows the server to handle higher loads. The easiest way to achieve this is to place static assets into a separate directory and have all requests for resources in that directory be handled by the static handler (disable all others):

myapp:
- my_code
  - [all jsps and servlets]
- my_assets
    - styles
    - images
    - js

image

For IIS to see the actual files the IIS-document-root has to be pointing at your tomcat application root etc.

Best, Bilal

Bilal-S commented 5 years ago

closing for now.