Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
222 views
in Technique[技术] by (71.8m points)

java - Wildfly response 404 when url ends in .xhtml

I have the following endpoint in Spring Boot:

 @RestController
    @RequestMapping(value = "/")
    class HelloXhtml {

    @RequestMapping(value = {"/{app}/form.xhtml"}, method = {RequestMethod.GET},
            produces = {APPLICATION_XHTML_XML_VALUE})
    public ResponseEntity<String> getFormDefinitionXml(
            @PathVariable(name = "app") String app) {
            return new ResponseEntity<>("<fruit>apple</fruit>", HttpStatus.OK);

    }
}

if I run it with embedded Tomcat everything works fine but on Wildfly 20.0.0-Final this specific endpoint throws 404.

The endpoint fails with 404 when the @RequestMapping value ends in ".xhtml" like this:

@RequestMapping(value = {"/{app}/form.xhtml"}

I tried a workaround by changing @RequestMapping string to:

@RequestMapping(value = {"/{app}/{whatever}"}

It produced the same result: it worked as expected when the "whatever" parameter was any string and returned 404 error when I passed in a filename ending in xhtml (eg.: apple.xhtml) as parameter.

What makes Wildfly discard any url ending in xhtml and return 404, and how can I turn off this behaviour?

EDIT:

I went in for another round. I created a sample spring application to produce the behaviour:

Java code:

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import java.time.ZonedDateTime;

import static org.springframework.http.MediaType.APPLICATION_XHTML_XML_VALUE;
import static org.springframework.http.MediaType.APPLICATION_XML_VALUE;

@SpringBootApplication
public class DemoApplication  extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }   

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemoApplication.class);
    }

}

@RestController
@RequestMapping(value = "/persistence/crud")
class HelloXhtml {


    @RequestMapping(value = {"/{app}/{form}/form/{formXml}"}, method = {RequestMethod.GET}, produces = {APPLICATION_XHTML_XML_VALUE})
    public ResponseEntity<String> getFormDefinitionXml(
            @PathVariable(name = "app") String app) {
            return new ResponseEntity<>("<fruit>pear</fruit>", HttpStatus.OK);

    }
}

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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.4.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
                <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>2.0.0.Final</version>
            </plugin>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
                <archive>                   
                    <manifestEntries>
                        <Dependencies>jdk.unsupported</Dependencies>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
        </plugins>
    </build>

</project>
question from:https://stackoverflow.com/questions/65888801/wildfly-response-404-when-url-ends-in-xhtml

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...