I'm trying to read APPLICATION_FORM_URLENCODEDin MessageBodyReaderon jersey. The stream returns null data when I try to read it usingBufferedReader
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());
BufferedReader br = new BufferedReader(new InputStreamReader(entityStream));
String data = br.readLine();
System.out.println("Stream Read:"+data);
.....
}
}
I see that the data is being sent from my form to the POST request as application/x-www-form-urlencoded, however I cannot read it in MessageBodyReader.
During debugging, I see that ByteChunk contains the following 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 this is some kind of side effect SpringBootServletInitializer. Disabling this result causes the above code to work fine.
Does anyone help?
source
share