nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.25k stars 322 forks source link

Issue with WAR in unit-jsc11 #1198

Closed dgrecoBill1st closed 3 months ago

dgrecoBill1st commented 3 months ago

Having an issue with a WAR spring boot application in unit-jsc11. The same war deploys and runs fine in tomcat. In unit, the result is an unarchive style output:

<a href="META-INF">META-INF</a><br>
<a href="WEB-INF">WEB-INF</a><br>

The application config is:

 "crypt": {
                "type": "java",
                "webapp": "/var/www/crypt/crypt-0.0.1.war",
                "working_directory": "/var/www/crypt/",
                "environment": {
                        "SERVER_ID": "24634138",
                }
        }

Unit log shows:

2024/03/22 14:05:35 [info] 374502#374502 "crypt" prototype started
2024/03/22 14:05:35 [info] 374503#374503 "crypt" application started
2024/03/22 14:05:37 [info] 0#374503 [unit] Context.addFilter<F> Tomcat WebSocket (JSR356) Filter
2024/03/22 14:05:37 [info] 0#374503 [unit] Context.FilterReg.setAsyncSupported: true
2024/03/22 14:05:37 [info] 0#374503 [unit] Context.1 Spring WebApplicationInitializers detected on classpath

Any tips for diagnosing this? I see a bug mentioned here - https://github.com/nginx/unit/issues/403 though the patch that fixed there is in my version of Unit (1.32.0)

tippexs commented 3 months ago

Hi @dgrecoBill1st what's the version of Spring and Tomcat you have tested this with?

Our Java implementation is limited to the Servlet API version 3.1 which is spring 2.

dgrecoBill1st commented 3 months ago

Spring Boot 2.7.18

Tomcat 9.0.83

dgrecoBill1st commented 3 months ago

Any ideas on this? Really would like to utilize unit for this small project requiring java, as our primary infrastructure is PHP on Unit already.

tippexs commented 3 months ago

Good evening @dgrecoBill1st sorry for the long response time.

Can you share a WAR file for diagnosis or share a simple example on how to reproduce this?

dgrecoBill1st commented 3 months ago

Sure, attaching the war here (renamed to add .zip as cannot upload war) crypt-0.0.1.war.zip crypt-0.0.1.war.zip . Here is the full setup and steps:

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.bill1st</groupId>
    <artifactId>crypt</artifactId>
    <version>0.0.1</version>

    <properties>
        <start-class>com.bill1st.CryptApplication</start-class>
    </properties>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

    </dependencies>

    <packaging>war</packaging>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
            </plugin>
        </plugins>
     </build>

</project>

Built with maven 3.5.4

Application is simple hello world controller mapped to / URI

Configured Unit:

http://localhost/config/listeners/127.0.0.1:8312

{
        "pass": "routes/crypt"
}

http://localhost/config/routes/crypt

[
        {
                "match": {
                        "uri": "*"
                },

                "action": {
                        "pass": "applications/crypt"
                }
        }
]

http://localhost/config/applications/crypt

{
        "type": "java",
        "webapp": "/var/www/crypt/crypt-0.0.1.war",
        "working_directory": "/var/www/crypt/",
        "environment": {
               <REDACTED>
        }
}

And the result: curl http://127.0.0.1:8312

<a href="META-INF">META-INF</a><br>
<a href="WEB-INF">WEB-INF</a><br>
dgrecoBill1st commented 3 months ago

Closing ticket, I did a new clean build of the project and it works in unit now.