I'm trying to read APPLICATION_FORM_URLENCODED
in a MessageBodyReader
in Jersey. The stream is returning null data when I try to read it using a BufferedReader
Here is my code:
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public class EmployeeReader implements MessageBodyReader<Employee> {
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType) {
return true;
}
@Override
public Employee readFrom(Class<Employee> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
System.out.println(entityStream.available()); //Prints 0
BufferedReader br = new BufferedReader(new InputStreamReader(entityStream));
String data = br.readLine();
System.out.println("Stream Read:"+data);
//data is null here
.....
}
}
I can see that the data is being sent from my form in the POST request as application/x-www-form-urlencoded
, however I am unable to read it in my MessageBodyReader
.
While debugging I can see that the ByteChunk is holding the below data:
POST /Employees/employee HTTP/1.1
host:localhost:80800
connection:keep-alivee
content-length:144
postman-token:cf873d98-3208-292c-8fc1-6da8138a31faa
cache-control:no-cachee
origin:chrome-extension://fhbjgbiflinjbdggehcddcbncdddomopp
user-agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.366
content-type:application/x-www-form-urlencodedd
accept:*/**
accept-encoding:gzip, deflate, brr
accept-language:en-US,en;q=0.88
id=3&name=Test
UPDATE
I just found out that it is some sort of side effect of SpringBootServletInitializer
. Disabling this results in the above code working fine.
Can anybody help?