I'd suggest using the google Gson parser
Map<String, String> extractLoginRequest(final ServletRequest request) throws IOException {
final StringBuffer sb = new StringBuffer();
String line = null;
final BufferedReader reader = request.getReader();
while ((line = reader.readLine()) != null) {
sb.append(line);
}
// as far as I know, gson might not be 100% threadsave
return new Gson().fromJson(sb.toString(), HashMap.class);
}
now you can access your parameter with
Map<String, String> loginRequest = extractLoginRequest(request);
loginRequest.get("username")
In case you are using Maven, this is the dependency you might use:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>