@Test public void specialCharsShouldGetEscapedAndUseOnlyCommaAndEqualsSignForConcat() { final Map<String, String> context = new HashMap<>(); context.put("!\"§$%&@/()=? ", "^°+*'# .,;:_<>´´``"); context.put("öü äß", "ÖÜ Äß€"); final String headerString = UNIT.render(context); assertThat(countChars(headerString, '='), is(2)); assertThat(countChars(headerString, ','), is(1)); }
public String render(Map<String, String> context) { final StringBuilder sb = new StringBuilder(128); for (Iterator<Map.Entry<String, String>> iterator = context.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, String> entry = iterator.next(); try { final String key = URLEncoder.encode(entry.getKey().trim(), ENCODING_CHARSET); final String value = URLEncoder.encode(entry.getValue().trim(), ENCODING_CHARSET); sb.append(key).append('=').append(value); if (iterator.hasNext()) { sb.append(','); } } catch (UnsupportedEncodingException e) { LOGGER.error("Charset not found", e); } } return sb.toString(); }
HttpHeaderTransport { public String render(Map<String, String> context) { final StringBuilder sb = new StringBuilder(128); for (Iterator<Map.Entry<String, String>> iterator = context.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, String> entry = iterator.next(); try { final String key = URLEncoder.encode(entry.getKey().trim(), ENCODING_CHARSET); final String value = URLEncoder.encode(entry.getValue().trim(), ENCODING_CHARSET); sb.append(key).append('=').append(value); if (iterator.hasNext()) { sb.append(','); } } catch (UnsupportedEncodingException e) { LOGGER.error("Charset not found", e); } } return sb.toString(); } }
HttpHeaderTransport { public String render(Map<String, String> context) { final StringBuilder sb = new StringBuilder(128); for (Iterator<Map.Entry<String, String>> iterator = context.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, String> entry = iterator.next(); try { final String key = URLEncoder.encode(entry.getKey().trim(), ENCODING_CHARSET); final String value = URLEncoder.encode(entry.getValue().trim(), ENCODING_CHARSET); sb.append(key).append('=').append(value); if (iterator.hasNext()) { sb.append(','); } } catch (UnsupportedEncodingException e) { LOGGER.error("Charset not found", e); } } return sb.toString(); }  }
HttpHeaderTransport { public String render(Map<String, String> context) { final StringBuilder sb = new StringBuilder(128); for (Iterator<Map.Entry<String, String>> iterator = context.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, String> entry = iterator.next(); try { final String key = URLEncoder.encode(entry.getKey().trim(), ENCODING_CHARSET); final String value = URLEncoder.encode(entry.getValue().trim(), ENCODING_CHARSET); sb.append(key).append('=').append(value); if (iterator.hasNext()) { sb.append(','); } } catch (UnsupportedEncodingException e) { LOGGER.error("Charset not found", e); } } return sb.toString(); }  Map<String, String> parse(List<String> serializedElements); String render(Map<String, String> context); }
HttpHeaderTransport { public String render(Map<String, String> context) { final StringBuilder sb = new StringBuilder(128); for (Iterator<Map.Entry<String, String>> iterator = context.entrySet().iterator(); iterator.hasNext(); ) { Map.Entry<String, String> entry = iterator.next(); try { final String key = URLEncoder.encode(entry.getKey().trim(), ENCODING_CHARSET); final String value = URLEncoder.encode(entry.getValue().trim(), ENCODING_CHARSET); sb.append(key).append('=').append(value); if (iterator.hasNext()) { sb.append(','); } } catch (UnsupportedEncodingException e) { LOGGER.error("Charset not found", e); } } return sb.toString(); }  Map<String, String> parse(List<String> serializedElements); String render(Map<String, String> context); static final String ENCODING_CHARSET; }