|
8 | 8 | import java.io.IOException;
|
9 | 9 | import java.io.InputStream;
|
10 | 10 | import java.io.InputStreamReader;
|
| 11 | +import java.io.UnsupportedEncodingException; |
11 | 12 | import java.net.HttpURLConnection;
|
12 | 13 | import java.net.URL;
|
| 14 | +import java.net.URLEncoder; |
13 | 15 | import java.util.HashMap;
|
14 | 16 | import java.util.Map;
|
15 | 17 |
|
@@ -57,18 +59,26 @@ private String getResponseBody(InputStream inputStream) throws IOException {
|
57 | 59 | return sb.toString();
|
58 | 60 | }
|
59 | 61 |
|
60 |
| - private String uri(String email) { |
61 |
| - StringBuilder result = new StringBuilder(); |
| 62 | + private String uri(String email) throws UnsupportedEncodingException { |
| 63 | + return getPath() + getEncodedParams(email); |
| 64 | + } |
| 65 | + |
| 66 | + private String getPath(){ |
| 67 | + StringBuilder path = new StringBuilder(); |
62 | 68 | String protocol = this.truemailConfiguration.isSecureConnection() ? "https" : "http";
|
63 |
| - result.append(protocol); |
64 |
| - result.append("://"); |
65 |
| - result.append(this.truemailConfiguration.getHost()); |
66 |
| - result.append(":"); |
67 |
| - result.append(this.truemailConfiguration.getPort()); |
68 |
| - result.append("?email="); |
69 |
| - result.append(email); |
| 69 | + path.append(protocol); |
| 70 | + path.append("://"); |
| 71 | + path.append(this.truemailConfiguration.getHost()); |
| 72 | + path.append(":"); |
| 73 | + path.append(this.truemailConfiguration.getPort()); |
| 74 | + return path.toString(); |
| 75 | + } |
70 | 76 |
|
71 |
| - return result.toString(); |
| 77 | + private String getEncodedParams(String email) throws UnsupportedEncodingException { |
| 78 | + // This way of encoding looks strange, but there is no other way in vanilla java |
| 79 | + // See https://stackoverflow.com/questions/444112/how-do-i-encode-uri-parameter-values |
| 80 | + return "?email=" + URLEncoder.encode(email, "UTF-8") |
| 81 | + .replaceAll("\\+", "%20"); |
72 | 82 | }
|
73 | 83 |
|
74 | 84 | private Map<String, String> headers() {
|
|
0 commit comments