'Wildfly 26 changed behaviour of REST with content type "x-www-form-urlencoded"

while updating from Wildfly version 24 to version 26 I found an anoying change within REST.

If I post with curl some data, it is just not received on the server. I already found out, that this is because of default content type "x-www-form-urlencoded", used by curl.

Example server code:

import java.io.IOException;
import java.io.InputStream;

import javax.ejb.Stateless;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import org.apache.commons.io.IOUtils;

@Stateless
@Path("test")
public class RestSample {

    @POST
    @Path("t1")
    public Response postData(InputStream dataInputStream) {
        String content=null;
        try {
            content=IOUtils.toString(dataInputStream,"UTF-8");
            System.out.println("content length: "+content.length());
            System.out.println("content: "+content);
        } catch(IOException e) {
            System.out.println("An exception occurred."+e);
        }

        return Response.status(Response.Status.ACCEPTED).entity("Received: "+content).build();
    }

    @POST
    @Path("t2")
    public String postData(String input) {
        return "Received: "+input;
    }

}

Both methods postData() do the same and react the same. The first one is working more low level with InputStream and Response, but we can focus on the second one, which is really simple: The received content becomes part of the response.

If I do start my Wildfly 24 and do the call:

curl -d "Hello World" http://localhost/server/rest/test/t2

I see the response:

Received: Hello World

The same if I call:

curl -d "Hello World" -H 'Content-Type: application/xml' http://localhost/server/rest/test/t2

I see the response:

Received: Hello World

But if I use the same code within Wildfly 26, the behaviour changes:

curl -d "Hello World" -H 'Content-Type: application/xml' http://localhost/server/rest/test/t2

This still works and returns:

Received: Hello World

But:

curl -d "Hello World" http://localhost/server/rest/test/t2

Now gets an empty input stream or empty string and I just get:

Received: 

So, the question is: What has changed? Is ther a chance to get back the old behaviour?

Update:

This is really strange! I apologize for not testing my code on a ‘clear’ Wildfly! As James mentioned: There it is working, but I did simply not expect such side effects!

I compared my productive system with the clear test system a long time and compared e. g.

  • standalone.xml
  • modules folder
  • web.xml
  • application.xml
  • adding primefaces-11.0.1.jar

And I only found out one thing: If I remove the <login-config> section from my web.xml in my productive software, the problem is away. But if I put this section within my clean test system, it still works!

So it looks like the problem is based on multiple components but I do not find anything else. So, I found a workaround for the <login-config> section and hope there are no other problems from the same source.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source