@Test public void testDecode() throws UnsupportedEncodingException, WebHookHtmlRendererException { String line = URLEncoder.encode("name1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8") + "&" + URLEncoder.encode("name2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8") + "&" + URLEncoder.encode("name0", "UTF-8") + "=" + URLEncoder.encode("value0", "UTF-8"); WwwFormUrlEncodedToHtmlPrettyPrintingRenderer renderer = new WwwFormUrlEncodedToHtmlPrettyPrintingRenderer(); Map<String,String> decoded = renderer.extractKeyValues(line); assertEquals("Decoded map should only contain 3 items", 3, decoded.size()); assertEquals("Because a treeMap sorts keys, the second key should be name1", "name1", decoded.keySet().toArray()[1]); assertEquals("Because a treeMap sorts keys, third key should be name2", "name2", decoded.keySet().toArray()[2]); }
protected Map<String, String> extractKeyValues(String formEncodedString) throws WebHookHtmlRendererException { Map<String,String> keyValues= new TreeMap<>(); try { String[] pairs = formEncodedString.split("\\&"); for (int i = 0; i < pairs.length; i++) { String[] fields = pairs[i].split("="); String name = URLDecoder.decode(fields[0], "UTF-8"); String value; try { value = URLDecoder.decode(fields[1], "UTF-8"); } catch (ArrayIndexOutOfBoundsException arrayEx){ value = ""; } keyValues.put(name, value); } } catch (UnsupportedEncodingException uee){ throw new WebHookHtmlRendererException(uee); } return keyValues; }
WwwFormUrlEncodedToHtmlPrettyPrintingRenderer implements WebHookStringRenderer { protected Map<String, String> extractKeyValues(String formEncodedString) throws WebHookHtmlRendererException { Map<String,String> keyValues= new TreeMap<>(); try { String[] pairs = formEncodedString.split("\\&"); for (int i = 0; i < pairs.length; i++) { String[] fields = pairs[i].split("="); String name = URLDecoder.decode(fields[0], "UTF-8"); String value; try { value = URLDecoder.decode(fields[1], "UTF-8"); } catch (ArrayIndexOutOfBoundsException arrayEx){ value = ""; } keyValues.put(name, value); } } catch (UnsupportedEncodingException uee){ throw new WebHookHtmlRendererException(uee); } return keyValues; } }
WwwFormUrlEncodedToHtmlPrettyPrintingRenderer implements WebHookStringRenderer { protected Map<String, String> extractKeyValues(String formEncodedString) throws WebHookHtmlRendererException { Map<String,String> keyValues= new TreeMap<>(); try { String[] pairs = formEncodedString.split("\\&"); for (int i = 0; i < pairs.length; i++) { String[] fields = pairs[i].split("="); String name = URLDecoder.decode(fields[0], "UTF-8"); String value; try { value = URLDecoder.decode(fields[1], "UTF-8"); } catch (ArrayIndexOutOfBoundsException arrayEx){ value = ""; } keyValues.put(name, value); } } catch (UnsupportedEncodingException uee){ throw new WebHookHtmlRendererException(uee); } return keyValues; }  }
WwwFormUrlEncodedToHtmlPrettyPrintingRenderer implements WebHookStringRenderer { protected Map<String, String> extractKeyValues(String formEncodedString) throws WebHookHtmlRendererException { Map<String,String> keyValues= new TreeMap<>(); try { String[] pairs = formEncodedString.split("\\&"); for (int i = 0; i < pairs.length; i++) { String[] fields = pairs[i].split("="); String name = URLDecoder.decode(fields[0], "UTF-8"); String value; try { value = URLDecoder.decode(fields[1], "UTF-8"); } catch (ArrayIndexOutOfBoundsException arrayEx){ value = ""; } keyValues.put(name, value); } } catch (UnsupportedEncodingException uee){ throw new WebHookHtmlRendererException(uee); } return keyValues; }  @Override String render(String formEncodedString); @Override String render(Map<String, String[]> requestParameterMap); }
WwwFormUrlEncodedToHtmlPrettyPrintingRenderer implements WebHookStringRenderer { protected Map<String, String> extractKeyValues(String formEncodedString) throws WebHookHtmlRendererException { Map<String,String> keyValues= new TreeMap<>(); try { String[] pairs = formEncodedString.split("\\&"); for (int i = 0; i < pairs.length; i++) { String[] fields = pairs[i].split("="); String name = URLDecoder.decode(fields[0], "UTF-8"); String value; try { value = URLDecoder.decode(fields[1], "UTF-8"); } catch (ArrayIndexOutOfBoundsException arrayEx){ value = ""; } keyValues.put(name, value); } } catch (UnsupportedEncodingException uee){ throw new WebHookHtmlRendererException(uee); } return keyValues; }  @Override String render(String formEncodedString); @Override String render(Map<String, String[]> requestParameterMap);  }