HttpUtil { public static MultivaluedMap<String, String> parseBodyParams( final Response response) { try { Charset charset = Charset.forName("UTF-8"); InputStream stream = (InputStream) response.getEntity(); StringWriter writer = new StringWriter(); IOUtils.copy(stream, writer, charset); return parseQueryParams(writer.toString()); } catch (IOException ioe) { logger.error("Could not decode params in stream.", ioe); } return new MultivaluedHashMap<>(); } private  HttpUtil(); static String authHeaderBasic(final String login,
                                         final String password); static String authHeaderBasic(final BigInteger login,
                                         final String password); static String authHeaderBearer(final BigInteger token); static String authHeaderBearer(final String token); static MultivaluedMap<String, String> parseQueryParams(
            final URI uri); static MultivaluedMap<String, String> parseQueryParams(
            final String query); static MultivaluedMap<String, String> parseBodyParams(
            final Response response);  }
@Test public void parseQueryParamsFromBody() { Response r = mock(Response.class); InputStream stream1 = IOUtils.toInputStream("foo=bar&lol=cat", UTF8); doReturn(stream1).when(r).getEntity(); MultivaluedMap<String, String> params = HttpUtil.parseBodyParams(r); assertEquals(2, params.size()); assertEquals("cat", params.getFirst("lol")); assertEquals("bar", params.getFirst("foo")); InputStream stream2 = IOUtils.toInputStream("", UTF8); doReturn(stream2).when(r).getEntity(); MultivaluedMap<String, String> params2 = HttpUtil.parseBodyParams(r); assertEquals(0, params2.size()); InputStream stream3 = IOUtils.toInputStream("", UTF8); doThrow(IOException.class).when(r).getEntity(); MultivaluedMap<String, String> params3 = HttpUtil.parseBodyParams(r); assertEquals(0, params3.size()); }